Commit 37f4f3d0 authored by Akim Demaille's avatar Akim Demaille
Browse files

rat: tuple: improve latex pretty-printing

Instead of `E \mid F`, whose size does not depend on the size of its
argument, use `\left. E \middle| \right.`.
Suggested by Alexandre Duret-Lutz.

* vcsn/core/rat/printer.hh, vcsn/core/rat/printer.hxx: here.

* tests/bin/test.py: Always print the expected/effective paragraphs.
Even if they are redundant for single line changes, they enable the
use of update-tests.

* tests/python/transducer.py: Update expectations.
parent 5cdfb21e
......@@ -141,12 +141,9 @@ def CHECK_EQ(expected, effective, loc = None):
exp = format(expected)
eff = format(effective)
msg = exp + " != " + eff
if msg.count("\n") == 0:
FAIL(msg, loc=loc)
else:
FAIL(loc=loc)
rst_file("Expected output", exp)
rst_file("Effective output", eff)
FAIL(loc=loc)
rst_file("Expected output", exp)
rst_file("Effective output", eff)
rst_diff(exp, eff)
def normalize(a):
......
......@@ -57,7 +57,7 @@ e = c.expression('(<2>a)*|(<3>b)*|(<5>c)*')
CHECK_EQ(f, e)
CHECK_EQ('''(<2>a)*|(<3>b)*|(<5>c)*''', e)
CHECK_EQ(r'''<1> + \e|\e|c.[<5>\e|\e|(<5>c)*] + \e|b|\e.[<3>\e|(<3>b)*|\e] + \e|b|c.[<15>\e|(<3>b)*|(<5>c)*] + a|\e|\e.[<2>(<2>a)*|\e|\e] + a|\e|c.[<10>(<2>a)*|\e|(<5>c)*] + a|b|\e.[<6>(<2>a)*|(<3>b)*|\e] + a|b|c.[<30>(<2>a)*|(<3>b)*|(<5>c)*]''', e.expansion())
CHECK_EQ(r'''\left\langle 1\right\rangle \oplus \varepsilon|\varepsilon|c \odot \left[\left\langle 5\right\rangle \varepsilon \mid \varepsilon \mid \left( \left\langle 5 \right\rangle \,c\right)^{*}\right] \oplus \varepsilon|b|\varepsilon \odot \left[\left\langle 3\right\rangle \varepsilon \mid \left( \left\langle 3 \right\rangle \,b\right)^{*} \mid \varepsilon\right] \oplus \varepsilon|b|c \odot \left[\left\langle 15\right\rangle \varepsilon \mid \left( \left\langle 3 \right\rangle \,b\right)^{*} \mid \left( \left\langle 5 \right\rangle \,c\right)^{*}\right] \oplus a|\varepsilon|\varepsilon \odot \left[\left\langle 2\right\rangle \left( \left\langle 2 \right\rangle \,a\right)^{*} \mid \varepsilon \mid \varepsilon\right] \oplus a|\varepsilon|c \odot \left[\left\langle 10\right\rangle \left( \left\langle 2 \right\rangle \,a\right)^{*} \mid \varepsilon \mid \left( \left\langle 5 \right\rangle \,c\right)^{*}\right] \oplus a|b|\varepsilon \odot \left[\left\langle 6\right\rangle \left( \left\langle 2 \right\rangle \,a\right)^{*} \mid \left( \left\langle 3 \right\rangle \,b\right)^{*} \mid \varepsilon\right] \oplus a|b|c \odot \left[\left\langle 30\right\rangle \left( \left\langle 2 \right\rangle \,a\right)^{*} \mid \left( \left\langle 3 \right\rangle \,b\right)^{*} \mid \left( \left\langle 5 \right\rangle \,c\right)^{*}\right]''', e.expansion().format('latex'))
CHECK_EQ(r'''\left\langle 1\right\rangle \oplus \varepsilon|\varepsilon|c \odot \left[\left\langle 5\right\rangle \left. \varepsilon \middle| \varepsilon \middle| \left( \left\langle 5 \right\rangle \,c\right)^{*} \right. \right] \oplus \varepsilon|b|\varepsilon \odot \left[\left\langle 3\right\rangle \left. \varepsilon \middle| \left( \left\langle 3 \right\rangle \,b\right)^{*} \middle| \varepsilon \right. \right] \oplus \varepsilon|b|c \odot \left[\left\langle 15\right\rangle \left. \varepsilon \middle| \left( \left\langle 3 \right\rangle \,b\right)^{*} \middle| \left( \left\langle 5 \right\rangle \,c\right)^{*} \right. \right] \oplus a|\varepsilon|\varepsilon \odot \left[\left\langle 2\right\rangle \left. \left( \left\langle 2 \right\rangle \,a\right)^{*} \middle| \varepsilon \middle| \varepsilon \right. \right] \oplus a|\varepsilon|c \odot \left[\left\langle 10\right\rangle \left. \left( \left\langle 2 \right\rangle \,a\right)^{*} \middle| \varepsilon \middle| \left( \left\langle 5 \right\rangle \,c\right)^{*} \right. \right] \oplus a|b|\varepsilon \odot \left[\left\langle 6\right\rangle \left. \left( \left\langle 2 \right\rangle \,a\right)^{*} \middle| \left( \left\langle 3 \right\rangle \,b\right)^{*} \middle| \varepsilon \right. \right] \oplus a|b|c \odot \left[\left\langle 30\right\rangle \left. \left( \left\langle 2 \right\rangle \,a\right)^{*} \middle| \left( \left\langle 3 \right\rangle \,b\right)^{*} \middle| \left( \left\langle 5 \right\rangle \,c\right)^{*} \right. \right]''', e.expansion().format('latex'))
CHECK_EQ(r'''digraph
{
vcsn_context = "lat<nullableset<letterset<char_letters(a)>>, nullableset<letterset<char_letters(b)>>, nullableset<letterset<char_letters(c)>>>, z"
......
......@@ -123,7 +123,7 @@ namespace vcsn
void print_(const tuple_t& v)
{
if (I)
visitor_.out_ << visitor_.tuple_;
visitor_.out_ << visitor_.tuple_middle;
auto rs = detail::make_focus<I>(visitor_.rs_);
auto print = make_printer(rs, visitor_.out_);
print.format(visitor_.fmt_);
......@@ -145,7 +145,9 @@ namespace vcsn
/// Entry point.
void operator()(const tuple_t& v)
{
return print_(v, labelset_t_of<context_t>::indices);
visitor_.out_ << visitor_.tuple_left;
print_(v, labelset_t_of<context_t>::indices);
visitor_.out_ << visitor_.tuple_right;
}
const printer& visitor_;
};
......@@ -332,7 +334,14 @@ namespace vcsn
const char* shuffle_ = nullptr;
const char* product_ = nullptr;
const char* sum_ = nullptr;
const char* tuple_ = nullptr;
/// Left tuple delimiter.
const char* tuple_left = nullptr;
/// Tuple tape separator.
const char* tuple_middle = nullptr;
/// Right tuple delimiter.
const char* tuple_right = nullptr;
/// The constants.
const char* zero_ = nullptr;
const char* one_ = nullptr;
......
......@@ -91,9 +91,9 @@ namespace vcsn
lmul_ = "\\,";
rmul_ = "\\,";
ldiv_ = " \\backslash ";
// Use `\mid` between expressions (e.g., `a|(x+y)`), but
// still `|` beween labels, i.e., in tupleset.
tuple_ = " \\mid ";
tuple_left = " \\left. ";
tuple_middle = " \\middle| ";
tuple_right = " \\right. ";
}
else if (fmt_ == format::text)
{
......@@ -115,7 +115,9 @@ namespace vcsn
lmul_ = "";
rmul_ = "";
ldiv_ = "{\\}";
tuple_ = "|";
tuple_left = "";
tuple_middle = "|";
tuple_right = "";
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment