How to use the latex2mathml.exceptions.ExtraLeftOrMissingRight function in latex2mathml

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_aggregator.py View on Github external
def test_find_opening_parenthesis_raises_error() -> None:
    with pytest.raises(ExtraLeftOrMissingRight):
        find_opening_parenthesis([])
github roniemartinez / latex2mathml / tests / test_aggregator.py View on Github external
"_",
            r"\sum",
            [r"\substack", [["1", r"\le", "i", r"\le", "n"], ["i", r"\ne", "j"]]],
        ],
    ),
    ("issue #94", r"\mathrm{AA}", [r"\mathrm", ["A", "A"]]),
    (
        "issue #96",
        r"(1+(x-y)^{2})",
        ["(", "1", "+", "^", ["(", "x", "-", "y", ")"], ["2"], ")"],
    ),
    ("issue #98", r"p_{\max}", ["_", "p", [r"\max"]]),
]

PARAMS_WITH_EXCEPTION = [
    (r"missing \right", r"\left(x", ExtraLeftOrMissingRight),
    ("fraction without numerator", r"{ \over 2}", NumeratorNotFoundError),
    ("fraction without denominator", r"{1 \over }", DenominatorNotFoundError),
    ("missing subscript", r"1_", MissingSuperScriptOrSubscript),
    ("missing superscript", r"1^", MissingSuperScriptOrSubscript),
]


@pytest.mark.parametrize(
    "name, latex, expected", ids=[x[0] for x in PARAMS], argvalues=PARAMS,
)
def test_aggregator(name: str, latex: str, expected: list):
    assert aggregate(latex) == expected


@pytest.mark.parametrize(
    "name, latex, exception",
github roniemartinez / latex2mathml / latex2mathml / aggregator.py View on Github external
g.append(next(tokens))
                break
            else:
                g.append(token)
        except StopIteration:
            break
    if delimiter:
        try:
            right = g.index(RIGHT)
            content = g[2:right]
            g_ = g
            if len(content):
                g_ = g[0:2] + [_aggregate(iter(content))] + g[right:]
            return g_
        except ValueError:
            raise ExtraLeftOrMissingRight
    return _aggregate(iter(g))