def test_superscript(self): sup = eTree.SubElement(self.row, 'msup') mi = eTree.SubElement(sup, 'mi') mi.text = 'a' mi = eTree.SubElement(sup, 'mi') mi.text = 'b' self.assertEqual(eTree.tostring(self.math), converter.convert('a^b'))
def test_array_with_horizontal_lines(self): table = eTree.SubElement(self.row, 'mtable', rowlines="none solid") tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '1' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '2' tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '3' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '4' tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '5' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '6' self.assertEqual(eTree.tostring(self.math), converter.convert(r'\begin{array}{cr} 1 & 2 \\ 3 & 4 \\ \hline 5 & 6 \end{array}'''))
def test_square_root(math_and_row): math, row = math_and_row sqrt = eTree.SubElement(row, 'msqrt') row = eTree.SubElement(sqrt, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '2' assert _convert(math) == convert(r'\sqrt{2}')
def test_numbers_and_identifiers(math_and_row): math, row = math_and_row mn = eTree.SubElement(row, 'mn') mn.text = '12' mi = eTree.SubElement(row, 'mi') mi.text = 'x' assert _convert(math) == convert('12x')
def test_array_with_vertical_bars(math_and_row): math, row = math_and_row table = eTree.SubElement(row, 'mtable', columnlines='solid none') tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '1' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '2' td = eTree.SubElement(tr, 'mtd', columnalign='left') mn = eTree.SubElement(td, 'mn') mn.text = '3' tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '4' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '5' td = eTree.SubElement(tr, 'mtd', columnalign='left') mn = eTree.SubElement(td, 'mn') mn.text = '6' assert _convert(math) == convert( r'\begin{array}{c|rl} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array}')
def test_pmatrix(math_and_row): math, row = math_and_row mo = eTree.SubElement(row, 'mo') mo.text = '(' table = eTree.SubElement(row, 'mtable') tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd') mi = eTree.SubElement(td, 'mi') mi.text = 'a' td = eTree.SubElement(tr, 'mtd') mi = eTree.SubElement(td, 'mi') mi.text = 'b' tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd') mi = eTree.SubElement(td, 'mi') mi.text = 'c' td = eTree.SubElement(tr, 'mtd') mi = eTree.SubElement(td, 'mi') mi.text = 'd' mo = eTree.SubElement(row, 'mo') mo.text = ')' assert _convert(math) == convert( r'\begin{pmatrix}a & b \\ c & d \end{pmatrix}')
def test_array_with_horizontal_lines(math_and_row): math, row = math_and_row table = eTree.SubElement(row, 'mtable', rowlines='none solid') tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '1' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '2' tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '3' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '4' tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '5' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '6' s = r'\begin{array}{cr} 1 & 2 \\ 3 & 4 \\ \hline 5 & 6 \end{array}' assert _convert(math) == convert(s)
def test_issue_42(math_and_row): math, row = math_and_row msqrt = eTree.SubElement(row, 'msqrt') mrow = eTree.SubElement(msqrt, 'mrow') mo = eTree.SubElement(mrow, 'mo') mo.text = '(' mo = eTree.SubElement(mrow, 'mo') mo.text = '−' mn = eTree.SubElement(mrow, 'mn') mn.text = '25' msup = eTree.SubElement(mrow, 'msup') mo = eTree.SubElement(msup, 'mo') mo.text = ')' mrow2 = eTree.SubElement(msup, 'mrow') mn = eTree.SubElement(mrow2, 'mn') mn.text = '2' mo = eTree.SubElement(row, 'mo') mo.text = '=' mi = eTree.SubElement(row, 'mi') mi.text = '±' mn = eTree.SubElement(row, 'mn') mn.text = '25' assert _convert(math) == convert(r'\sqrt { ( - 25 ) ^ { 2 } } = \pm 25')
def test_array_with_vertical_bars(self): table = eTree.SubElement(self.row, 'mtable', columnlines='solid none') tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '1' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '2' td = eTree.SubElement(tr, 'mtd', columnalign='left') mn = eTree.SubElement(td, 'mn') mn.text = '3' tr = eTree.SubElement(table, 'mtr') td = eTree.SubElement(tr, 'mtd', columnalign='center') mn = eTree.SubElement(td, 'mn') mn.text = '4' td = eTree.SubElement(tr, 'mtd', columnalign='right') mn = eTree.SubElement(td, 'mn') mn.text = '5' td = eTree.SubElement(tr, 'mtd', columnalign='left') mn = eTree.SubElement(td, 'mn') mn.text = '6' self.assertEqual(eTree.tostring(self.math), converter.convert(r'\begin{array}{c|rl} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array}'''))
def test_binomial(self): self.row.append_child('mo', '(') frac = self.row.append_child('mfrac', None, linethickness=0) frac.append_child('mrow').append_child('mn', 2) frac.append_child('mrow').append_child('mn', 3) self.row.append_child('mo', ')') self.assertEqual(str(self.math), converter.convert(r'\binom{2}{3}'))
def test_multiple_identifiers(self): mi = eTree.SubElement(self.row, 'mi') mi.text = 'x' mi = eTree.SubElement(self.row, 'mi') mi.text = 'y' mi = eTree.SubElement(self.row, 'mi') mi.text = 'z' self.assertEqual(eTree.tostring(self.math), converter.convert('xyz'))
def test_numbers_and_operators(self): mn = eTree.SubElement(self.row, 'mn') mn.text = '3' mo = eTree.SubElement(self.row, 'mo') mo.text = '−' mn = eTree.SubElement(self.row, 'mn') mn.text = '2' self.assertEqual(eTree.tostring(self.math), converter.convert('3-2'))
def test_superscript(math_and_row): math, row = math_and_row sup = eTree.SubElement(row, 'msup') mi = eTree.SubElement(sup, 'mi') mi.text = 'a' mi = eTree.SubElement(sup, 'mi') mi.text = 'b' assert _convert(math) == convert('a^b')
def test_superscript_within_curly_braces(self): row = eTree.SubElement(self.row, 'mrow') sup = eTree.SubElement(row, 'msup') mi = eTree.SubElement(sup, 'mi') mi.text = 'a' mi = eTree.SubElement(sup, 'mi') mi.text = 'b' self.assertEqual(eTree.tostring(self.math), converter.convert('{a^b}'))
def test_left_and_right(self): mo = eTree.SubElement(self.row, 'mo', stretchy='true', form='prefix', fence='true') mo.text = '(' mi = eTree.SubElement(self.row, 'mi') mi.text = 'x' mo = eTree.SubElement(self.row, 'mo', stretchy='true', form='postfix', fence='true') mo.text = ')' self.assertEqual(eTree.tostring(self.math), converter.convert(r'\left(x\right)'))
def test_underline(self): under = eTree.SubElement(self.row, 'munder') mrow = eTree.SubElement(under, 'mrow') mi = eTree.SubElement(mrow, 'mi') mi.text = 'a' mo = eTree.SubElement(under, 'mo', stretchy='true') mo.text = '̲' self.assertEqual(eTree.tostring(self.math), converter.convert(r'\underline{a}'))
def test_overline(self): over = eTree.SubElement(self.row, 'mover') row = eTree.SubElement(over, 'mrow') mi = eTree.SubElement(row, 'mi') mi.text = 'a' mo = eTree.SubElement(over, 'mo', stretchy='true') mo.text = '¯' self.assertEqual(eTree.tostring(self.math), converter.convert(r'\overline{a}'))
def test_issue_45_gt(math_and_row): math, row = math_and_row mn = eTree.SubElement(row, 'mn') mn.text = '2' mo = eTree.SubElement(row, 'mo') mo.text = '>' mn = eTree.SubElement(row, 'mn') mn.text = '5' assert _convert(math) == convert('2 > 5')
def test_simple_array(self): table = self.row.append_child('mtable') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='center').append_child('mn', '1') tr.append_child('mtd', None, columnalign='right').append_child('mn', '2') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='center').append_child('mn', '3') tr.append_child('mtd', None, columnalign='right').append_child('mn', '4') self.assertEqual(str(self.math), converter.convert(r'\begin{array}{cr} 1 & 2 \\ 3 & 4 \end{array}'''))
def test_superscript_with_curly_braces(self): subsup = self.row.append_child('msubsup') subsup.append_child('mi', 'a') subsup.append_child('mn', 3) row = subsup.append_child('mrow') row.append_child('mi', 'i') row.append_child('mo', '+') row.append_child('mn', 1) self.assertEqual(str(self.math), converter.convert('a^{i+1}_3'))
def test_matrix(self): table = self.row.append_child('mtable') tr = table.append_child('mtr') tr.append_child('mtd').append_child('mi', 'a') tr.append_child('mtd').append_child('mi', 'b') tr = table.append_child('mtr') tr.append_child('mtd').append_child('mi', 'c') tr.append_child('mtd').append_child('mi', 'd') self.assertEqual(str(self.math), converter.convert(r'\begin{matrix}a & b \\ c & d \end{matrix}'))
def test_matrix_with_alignment(self): table = self.row.append_child('mtable') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='right').append_child('mi', 'a') tr.append_child('mtd', None, columnalign='right').append_child('mi', 'b') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='right').append_child('mi', 'c') tr.append_child('mtd', None, columnalign='right').append_child('mi', 'd') self.assertEqual(str(self.math), converter.convert(r'\begin{matrix*}[r]a & b \\ c & d \end{matrix*}'))
def test_matrix_without_begin_and_end(self): # taken from MathJax table = self.row.append_child('mtable') tr = table.append_child('mtr') tr.append_child('mtd').append_child('mi', 'a') tr.append_child('mtd').append_child('mi', 'b') tr = table.append_child('mtr') tr.append_child('mtd').append_child('mi', 'c') tr.append_child('mtd').append_child('mi', 'd') self.assertEqual(str(self.math), converter.convert(r'\matrix{a & b \\ c & d}'))
def test_left_and_right(math_and_row): math, row = math_and_row mo = eTree.SubElement(row, 'mo', fence='true', form='prefix', stretchy='true') mo.text = '(' mi = eTree.SubElement(row, 'mi') mi.text = 'x' mo = eTree.SubElement(row, 'mo', fence='true', form='postfix', stretchy='true') mo.text = ')' assert _convert(math) == convert(r'\left(x\right)')
def test_superscript_within_curly_braces(math_and_row): math, row = math_and_row row = eTree.SubElement(row, 'mrow') sup = eTree.SubElement(row, 'msup') mi = eTree.SubElement(sup, 'mi') mi.text = 'a' mi = eTree.SubElement(sup, 'mi') mi.text = 'b' assert _convert(math) == convert('{a^b}')
def test_multiple_groups(self): mrow = eTree.SubElement(self.row, 'mrow') mi = eTree.SubElement(mrow, 'mi') mi.text = 'a' mrow = eTree.SubElement(self.row, 'mrow') mi = eTree.SubElement(mrow, 'mi') mi.text = 'b' self.assertEqual(eTree.tostring(self.math), converter.convert('{a}{b}'))
def test_simple_fraction(self): frac = eTree.SubElement(self.row, 'mfrac') row = eTree.SubElement(frac, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '1' row = eTree.SubElement(frac, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '2' self.assertEqual(eTree.tostring(self.math), converter.convert(r'\frac{1}{2}'))
def test_overline(math_and_row): math, row = math_and_row over = eTree.SubElement(row, 'mover') row = eTree.SubElement(over, 'mrow') mi = eTree.SubElement(row, 'mi') mi.text = 'a' mo = eTree.SubElement(over, 'mo', stretchy='true') mo.text = '¯' assert _convert(math) == convert(r'\overline{a}')
def test_numbers_and_operators(math_and_row): math, row = math_and_row mn = eTree.SubElement(row, 'mn') mn.text = '3' mo = eTree.SubElement(row, 'mo') mo.text = '−' mn = eTree.SubElement(row, 'mn') mn.text = '2' assert _convert(math) == convert('3-2')
def test_underline(math_and_row): math, row = math_and_row under = eTree.SubElement(row, 'munder') mrow = eTree.SubElement(under, 'mrow') mi = eTree.SubElement(mrow, 'mi') mi.text = 'a' mo = eTree.SubElement(under, 'mo', stretchy='true') mo.text = '̲' assert _convert(math) == convert(r'\underline{a}')
def test_multiple_identifiers(math_and_row): math, row = math_and_row mi = eTree.SubElement(row, 'mi') mi.text = 'x' mi = eTree.SubElement(row, 'mi') mi.text = 'y' mi = eTree.SubElement(row, 'mi') mi.text = 'z' assert _convert(math) == convert('xyz')
def test_multiple_groups(math_and_row): math, row = math_and_row mrow = eTree.SubElement(row, 'mrow') mi = eTree.SubElement(mrow, 'mi') mi.text = 'a' mrow = eTree.SubElement(row, 'mrow') mi = eTree.SubElement(mrow, 'mi') mi.text = 'b' assert _convert(math) == convert('{a}{b}')
def test_root(self): root = eTree.SubElement(self.row, 'mroot') row = eTree.SubElement(root, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '2' row = eTree.SubElement(root, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '3' self.assertEqual(eTree.tostring(self.math), converter.convert(r'\sqrt[3]{2}'))
def test_over(math_and_row): math, row = math_and_row frac = eTree.SubElement(row, 'mfrac') row = eTree.SubElement(frac, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '1' row = eTree.SubElement(frac, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '2' assert _convert(math) == convert(r'1 \over 2')
def test_root(math_and_row): math, row = math_and_row root = eTree.SubElement(row, 'mroot') row = eTree.SubElement(root, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '2' row = eTree.SubElement(root, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '3' assert _convert(math) == convert(r'\sqrt[3]{2}')
def test_simple_fraction(math_and_row): math, row = math_and_row frac = eTree.SubElement(row, 'mfrac') row = eTree.SubElement(frac, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '1' row = eTree.SubElement(frac, 'mrow') mn = eTree.SubElement(row, 'mn') mn.text = '2' assert _convert(math) == convert(r'\frac{1}{2}')
def test_matrix_with_negative_sign(self): table = self.row.append_child('mtable') tr = table.append_child('mtr') mtd = tr.append_child('mtd') mtd.append_child('mo', '−') mtd.append_child('mi', 'a') tr.append_child('mtd').append_child('mi', 'b') tr = table.append_child('mtr') tr.append_child('mtd').append_child('mi', 'c') tr.append_child('mtd').append_child('mi', 'd') self.assertEqual(str(self.math), converter.convert(r'\begin{matrix}-a & b \\ c & d \end{matrix}'))
def test_array_with_vertical_bars(self): table = self.row.append_child('mtable', None, columnlines='solid none') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='center').append_child('mn', '1') tr.append_child('mtd', None, columnalign='right').append_child('mn', '2') tr.append_child('mtd', None, columnalign='left').append_child('mn', '3') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='center').append_child('mn', '4') tr.append_child('mtd', None, columnalign='right').append_child('mn', '5') tr.append_child('mtd', None, columnalign='left').append_child('mn', '6') self.assertEqual(str(self.math), converter.convert(r'\begin{array}{c|rl} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array}'''))
def test_array_with_horizontal_lines(self): table = self.row.append_child('mtable', None, rowlines="none solid") tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='center').append_child('mn', '1') tr.append_child('mtd', None, columnalign='right').append_child('mn', '2') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='center').append_child('mn', '3') tr.append_child('mtd', None, columnalign='right').append_child('mn', '4') tr = table.append_child('mtr') tr.append_child('mtd', None, columnalign='center').append_child('mn', '5') tr.append_child('mtd', None, columnalign='right').append_child('mn', '6') self.assertEqual(str(self.math), converter.convert(r'\begin{array}{cr} 1 & 2 \\ 3 & 4 \\ \hline 5 & 6 \end{array}'''))
def test_superscript_within_curly_braces(self): row = self.row.append_child('mrow') sup = row.append_child('msup') sup.append_child('mi', 'a') sup.append_child('mi', 'b') self.assertEqual(str(self.math), converter.convert('{a^b}'))
def test_multiple_numbers(self): self.row.append_child('mn', 333) self.assertEqual(str(self.math), converter.convert('333'))
def test_space(self): self.row.append_child('mspace', None, width='0.167em') self.assertEqual(str(self.math), converter.convert('\,'))
def test_underline(self): under = self.row.append_child('munder') under.append_child('mrow').append_child('mi', 'a') under.append_child('mo', '̲', stretchy='true') self.assertEqual(str(self.math), converter.convert(r'\underline{a}'))
def test_subscript(self): sub = self.row.append_child('msub') sub.append_child('mi', 'a') sub.append_child('mi', 'b') self.assertEqual(str(self.math), converter.convert('a_b'))
def test_superscript_and_subscript(self): subsup = self.row.append_child('msubsup') subsup.append_child('mi', 'a') subsup.append_child('mi', 'c') subsup.append_child('mi', 'b') self.assertEqual(str(self.math), converter.convert('a^b_c'))
def test_numbers_and_identifiers_and_operators(self): self.row.append_child('mn', 3) self.row.append_child('mi', 'x') self.row.append_child('mo', '*') self.row.append_child('mn', 2) self.assertEqual(str(self.math), converter.convert('3x*2'))
def test_inner_group(self): row = self.row.append_child('mrow') row.append_child('mi', 'a') row.append_child('mo', '+') row.append_child('mrow').append_child('mi', 'b') self.assertEqual(str(self.math), converter.convert('{a+{b}}'))
def test_multiple_identifiers(self): self.row.append_child('mi', 'x') self.row.append_child('mi', 'y') self.row.append_child('mi', 'z') self.assertEqual(str(self.math), converter.convert('xyz'))
def test_numbers_and_operators(self): self.row.append_child('mn', 3) self.row.append_child('mo', '−') self.row.append_child('mn', 2) self.assertEqual(str(self.math), converter.convert('3-2'))
def test_numbers_and_identifiers(self): self.row.append_child('mn', 12) self.row.append_child('mi', 'x') self.assertEqual(str(self.math), converter.convert('12x'))
def test_multiple_groups(self): self.row.append_child('mrow').append_child('mi', 'a') self.row.append_child('mrow').append_child('mi', 'b') self.assertEqual(str(self.math), converter.convert('{a}{b}'))
def test_left_and_right(self): self.row.append_child('mo', '(', stretchy='true', form='prefix', fence='true') self.row.append_child('mi', 'x') self.row.append_child('mo', ')', stretchy='true', form='postfix', fence='true') self.assertEqual(str(self.math), converter.convert(r'\left(x\right)'))
def test_single_operator(self): self.row.append_child('mo', '+') self.assertEqual(str(self.math), converter.convert('+'))
def test_single_number(self): self.row.append_child('mn', 3) self.assertEqual(str(self.math), converter.convert('3'))
def test_decimal_numbers(self): self.row.append_child('mn', 12.34) self.assertEqual(str(self.math), converter.convert('12.34'))
def test_square_root(self): sqrt = self.row.append_child('msqrt') sqrt.append_child('mrow').append_child('mn', 2) self.assertEqual(str(self.math), converter.convert(r'\sqrt{2}'))
def test_single_group(self): self.row.append_child('mrow').append_child('mi', 'a') self.assertEqual(str(self.math), converter.convert('{a}'))
def test_root(self): root = self.row.append_child('mroot') root.append_child('mrow').append_child('mn', 2) root.append_child('mrow').append_child('mn', 3) self.assertEqual(str(self.math), converter.convert(r'\sqrt[3]{2}'))
def test_overline(self): over = self.row.append_child('mover') over.append_child('mrow').append_child('mi', 'a') over.append_child('mo', '¯', stretchy='true') self.assertEqual(str(self.math), converter.convert(r'\overline{a}'))
def test_simple_fraction(self): frac = self.row.append_child('mfrac') frac.append_child('mrow').append_child('mn', 1) frac.append_child('mrow').append_child('mn', 2) self.assertEqual(str(self.math), converter.convert(r'\frac{1}{2}'))