コード例 #1
0
def test_null_delimiter():
    assert [r'\left', r'\{', r'\right',
            '.'] == list(aggregate(r'\left\{\right.'))
    latex = r'\left\{ \begin{array} { l } { 3x - 5y + 4z = 0} \\ { x - y + 8z = 0} \\ { 2x - 6y + z = 0} \end{array}' \
            r' \right.'
    assert [
        r'\left', r'\{', r'\array', 'l',
        [[['3', 'x', '-', '5', 'y', '+', '4', 'z', '=', '0']],
         [['x', '-', 'y', '+', '8', 'z', '=', '0']],
         [['2', 'x', '-', '6', 'y', '+', 'z', '=', '0']]], r'\right', '.'
    ] == list(aggregate(latex))
コード例 #2
0
def test_issue_55():
    latex = r"\begin{array}{rcl}ABC&=&a\\A&=&abc\end{array}"
    expected = [
        r'\array', 'rcl',
        [[['A', 'B', 'C'], '=', 'a'], ['A', '=', ['a', 'b', 'c']]]
    ]
    assert expected == list(aggregate(latex))
コード例 #3
0
def convert(
    latex: str,
    xmlns: str = "http://www.w3.org/1998/Math/MathML",
    display: str = "inline",
) -> str:
    math = Element("math", xmlns=xmlns, display=display)
    row = SubElement(math, "mrow")
    _classify_subgroup(aggregate(latex), row)
    return _convert(math)
コード例 #4
0
def test_issue_33():
    latex = r'''\begin{bmatrix}
     a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
     a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
     \vdots  & \vdots  & \ddots & \vdots  \\
     a_{m,1} & a_{m,2} & \cdots & a_{m,n}
    \end{bmatrix}'''
    expected = [
        r'\bmatrix',
        [[['_', 'a', ['1', ',', '1']], ['_', 'a', ['1', ',', '2']], r'\cdots',
          ['_', 'a', ['1', ',', 'n']]],
         [['_', 'a', ['2', ',', '1']], ['_', 'a', ['2', ',', '2']], r'\cdots',
          ['_', 'a', ['2', ',', 'n']]],
         [r'\vdots', r'\vdots', r'\ddots', r'\vdots'],
         [['_', 'a', ['m', ',', '1']], ['_', 'a', ['m', ',', '2']], r'\cdots',
          ['_', 'a', ['m', ',', 'n']]]]
    ]
    assert expected == list(aggregate(latex))
コード例 #5
0
def test_matrix():
    assert [r'\matrix', [['a', 'b'],
                         ['c',
                          'd']]] == list(aggregate(r'\matrix{a & b \\ c & d}'))
    assert [r'\matrix', [['a', 'b'], ['c', 'd']]
            ] == list(aggregate(r'\begin{matrix}a & b \\ c & d \end{matrix}'))
コード例 #6
0
def test_subscript():
    assert ['_', 'a', 'b'] == aggregate('a_b')
    assert [['_', 'a', 'b']] == aggregate('{a_b}')
    assert ['_', '1', '2'] == aggregate('1_2')
    assert ['_', '1.2', '2'] == aggregate('1.2_2')
コード例 #7
0
def test_subscript_and_superscript():
    assert ['_^', 'a', 'b', 'c'] == aggregate('a_b^c')
    assert ['_^', 'a', 'c', 'b'] == aggregate('a^b_c')
コード例 #8
0
def test_string_with_spaces():
    s = '3 x'
    assert ['3', 'x'] == aggregate(s)
コード例 #9
0
 def test_superscript(self):
     self.assertListEqual(['^', 'a', 'b'], aggregator.aggregate('a^b'))
コード例 #10
0
def test_numbers():
    numbers = string.digits
    assert [numbers] == aggregate(numbers)
コード例 #11
0
def test_numbers_and_alphabets():
    s = '5x'
    assert list(s) == aggregate(s)
コード例 #12
0
 def test_complex_matrix(self):
     self.assertListEqual(['\\matrix', [['_', 'a', ['1'], '_', 'b', ['2']], ['_', 'c', ['3'], '_', 'd', ['4']]]],
                          list(aggregator.aggregate(r'\begin{matrix}a_{1} & b_{2} \\ c_{3} & d_{4} \end{matrix}')))
コード例 #13
0
 def test_simple_array(self):
     self.assertListEqual([r'\array', 'cc', [['1', '2'], ['3', '4']]],
                          list(aggregator.aggregate(r'\begin{array}{cc} 1 & 2 \\ 3 & 4 \end{array}''')))
コード例 #14
0
 def test_matrix_with_alignment(self):
     self.assertListEqual([r'\matrix*', 'r', [['a', 'b'], ['c', 'd']]],
                          list(aggregator.aggregate(r'\begin{matrix*}[r]a & b \\ c & d \end{matrix*}')))
コード例 #15
0
 def test_matrix_with_negative_sign(self):
     self.assertListEqual([r'\matrix', [[['-', 'a'], 'b'], ['c', 'd']]],
                          list(aggregator.aggregate(r'\begin{matrix}-a & b \\ c & d \end{matrix}')))
コード例 #16
0
 def test_matrix(self):
     self.assertListEqual([r'\matrix', [['a', 'b'], ['c', 'd']]],
                          list(aggregator.aggregate(r'\begin{matrix}a & b \\ c & d \end{matrix}')))
コード例 #17
0
 def test_root(self):
     self.assertListEqual([r'\root', ['2'], ['3']], aggregator.aggregate(r'\sqrt[3]{2}'))
コード例 #18
0
 def test_subscript_and_superscript(self):
     self.assertListEqual(['_^', 'a', 'b', 'c'], aggregator.aggregate('a_b^c'))
コード例 #19
0
 def test_inner_group(self):
     self.assertListEqual([['a', '+', ['b']]], aggregator.aggregate('{a+{b}}'))
コード例 #20
0
 def test_single_group(self):
     self.assertListEqual([['a']], aggregator.aggregate('{a}'))
コード例 #21
0
 def test_multiple_groups(self):
     self.assertListEqual([['a'], ['b']], aggregator.aggregate('{a}{b}'))
コード例 #22
0
def test_numbers_alphabets_and_operators():
    s = '3 + 5x - 5y = 7'
    assert ['3', '+', '5', 'x', '-', '5', 'y', '=', '7'] == aggregate(s)
コード例 #23
0
def test_numbers_with_decimals():
    decimal = '12.56'
    assert [decimal] == aggregate(decimal)
コード例 #24
0
def test_symbols_appended_number():
    s = r'\frac2x'
    assert [r'\frac', '2', 'x'] == aggregate(s)
コード例 #25
0
def test_decimals_and_alphabets():
    s = '5.8x'
    assert ['5.8', 'x'] == aggregate(s)
コード例 #26
0
def test_multiple_groups():
    assert [['a'], ['b']] == aggregate('{a}{b}')
コード例 #27
0
def test_operators():
    s = '+-*/=()[]_^{}'
    assert list(s) == aggregate(s)
コード例 #28
0
 def test_subscript(self):
     self.assertListEqual(['_', 'a', 'b'], aggregator.aggregate('a_b'))
コード例 #29
0
def test_symbols():
    s = r'\alpha\beta'
    assert [r'\alpha', r'\beta'] == aggregate(s)
コード例 #30
0
def test_complex_matrix():
    # assert ['\\matrix', [['_', 'a', ['1']], ['_', 'b', ['2']], ['_', 'c', ['3']], ['_', 'd', ['4']]]]
    assert [r'\matrix', [['_', 'a', ['1'], '_', 'b', ['2']], ['_', 'c', ['3'], '_', 'd', ['4']]]] == \
           list(aggregate(r'\begin{matrix}a_{1} & b_{2} \\ c_{3} & d_{4} \end{matrix}'))
コード例 #31
0
def test_single_group():
    assert [['a']] == aggregate('{a}')
コード例 #32
0
def test_alphabets():
    alphabets = string.ascii_letters
    assert list(alphabets) == aggregate(alphabets)
コード例 #33
0
def test_inner_group():
    assert [['a', '+', ['b']]] == aggregate('{a+{b}}')
コード例 #34
0
def test_simple_array():
    assert [r'\array', 'cc', [['1', '2'], ['3', '4']]] == \
           list(aggregate(r'\begin{array}{cc} 1 & 2 \\ 3 & 4 \end{array}'))
コード例 #35
0
def test_superscript():
    assert ['^', 'a', 'b'] == aggregate('a^b')
    assert [['^', 'a', 'b']] == aggregate('{a^b}')
コード例 #36
0
def test_frac():
    assert [r'\frac', ['1'], ['2']] == list(aggregate(r'\frac{1}{2}'))
コード例 #37
0
def test_root():
    assert [r'\root', ['2'], ['3']] == aggregate(r'\sqrt[3]{2}')
コード例 #38
0
def test_over():
    assert [r'\frac', ['1'], ['2']] == list(aggregate(r'1 \over 2'))
    assert [[r'\frac', ['1'], ['2']]] == list(aggregate(r'{1 \over 2}'))
コード例 #39
0
def convert(latex, xmlns='http://www.w3.org/1998/Math/MathML'):
    math = eTree.Element('math')
    math.attrib['xmlns'] = xmlns
    row = eTree.SubElement(math, 'mrow')
    _classify_subgroup(aggregate(latex), row)
    return _convert(math)
コード例 #40
0
def test_superscript_with_curly_braces():
    assert ['_^', 'a', '3', ['i', '+', '1']] == list(aggregate('a^{i+1}_3'))
コード例 #41
0
ファイル: converter.py プロジェクト: Johnabell/latex2mathml
def convert(latex):
    math = eTree.Element('math')
    row = eTree.SubElement(math, 'mrow')
    _classify_subgroup(aggregate(latex), row)
    return _convert(math)
コード例 #42
0
def test_empty_group():
    assert [['{', '}']] == aggregate('{{}}')