How to use latex2mathml - 10 common examples

To help you get started, weโ€™ve selected a few latex2mathml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github roniemartinez / latex2mathml / tests / test_command.py View on Github external
sub_right = eTree.SubElement(row, "msub")

    row = eTree.SubElement(over, "mrow")
    sub_left = eTree.SubElement(row, "msub")
    mi = eTree.SubElement(sub_left, "mi")
    mi.text = "z"
    mn = eTree.SubElement(sub_left, "mn")
    mn.text = "1"
    mo = eTree.SubElement(over, "mo", stretchy="true")
    mo.text = "¯"

    mi = eTree.SubElement(sub_right, "mi")
    mi.text = "z"
    mn = eTree.SubElement(sub_right, "mn")
    mn.text = "2"
    assert _convert(math) == convert(r"\bar{z_1} = z_2")
github roniemartinez / latex2mathml / tests / test_command.py View on Github external
def test_binomial(math_and_row):
    math, row = math_and_row
    mo = eTree.SubElement(row, "mo")
    mo.text = "("
    frac = eTree.SubElement(row, "mfrac", linethickness="0")
    _row = eTree.SubElement(frac, "mrow")
    mn = eTree.SubElement(_row, "mn")
    mn.text = "2"
    _row = eTree.SubElement(frac, "mrow")
    mn = eTree.SubElement(_row, "mn")
    mn.text = "3"
    mo = eTree.SubElement(row, "mo")
    mo.text = ")"
    assert _convert(math) == convert(r"\binom{2}{3}")
github roniemartinez / latex2mathml / tests / test_command.py View on Github external
mo.text = "−"
    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"

    assert _convert(math) == convert(r"\begin{matrix}-a & b \\ c & d \end{matrix}")
github roniemartinez / latex2mathml / tests / test_converter.py View on Github external
def test_converter(name: str, latex: str, json: MultiDict):
    parent = {
        "math": {
            "@xmlns": "http://www.w3.org/1998/Math/MathML",
            "@display": "inline",
            "mrow": json,
        }
    }
    bf = BadgerFish(dict_type=MultiDict)
    math = bf.etree(parent)
    assert convert(latex) == _convert(math[0])
github roniemartinez / latex2mathml / tests / test_converter.py View on Github external
def test_attributes():
    assert (
        convert("1")
        == '<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mn>1</mn></mrow></math>'
    )
    assert (
        convert("1", display="block")
        == '<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mn>1</mn></mrow></math>'
    )
github roniemartinez / latex2mathml / tests / test_command.py View on Github external
def test_superscript_and_subscript(math_and_row):
    math, row = math_and_row
    subsup = eTree.SubElement(row, "msubsup")
    mi = eTree.SubElement(subsup, "mi")
    mi.text = "a"
    mi = eTree.SubElement(subsup, "mi")
    mi.text = "c"
    mi = eTree.SubElement(subsup, "mi")
    mi.text = "b"
    assert _convert(math) == convert("a^b_c")
github roniemartinez / latex2mathml / tests / test_issues.py View on Github external
def test_issue_45_amp(math_and_row):
    math, row = math_and_row
    mo = eTree.SubElement(row, 'mo')
    mo.text = '&amp;'
    assert _convert(math) == convert('&')
github roniemartinez / latex2mathml / tests / test_command.py View on Github external
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 = "&#x00029;"

    assert _convert(math) == convert(r"\begin{pmatrix}a & b \\ c & d \end{pmatrix}")
github roniemartinez / latex2mathml / tests / test_command.py View on Github external
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}")
github roniemartinez / latex2mathml / tests / test_command.py View on Github external
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}"
    )