How to use the latex2mathml.exceptions.NumeratorNotFoundError 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
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",
    ids=[x[0] for x in PARAMS_WITH_EXCEPTION],
github roniemartinez / latex2mathml / latex2mathml / aggregator.py View on Github external
next(tokens)
                b = next_item_or_group(tokens)
                aggregated += [token, previous, a, b]
            elif token in SUB_SUP:
                aggregated = process_sub_sup(aggregated, token, tokens)
            elif token.startswith(BEGIN) or token in MATRICES:
                aggregated += environment(token, tokens)
            elif token == OVER:
                try:
                    numerator = aggregated.pop()
                    aggregated.append(FRAC)
                    aggregated.append([numerator])
                    denominator = next_item_or_group(tokens)
                    aggregated.append([denominator])
                except IndexError:
                    raise NumeratorNotFoundError
                except (StopIteration, EmptyGroupError):
                    raise DenominatorNotFoundError
            else:
                aggregated.append(token)
        except EmptyGroupError:
            aggregated += [OPENING_BRACES, CLOSING_BRACES]
            continue
        except StopIteration:
            if token is not None:
                aggregated.append(token)
            break
    return aggregated
github tsengwoody / Access8Math / addon / globalPlugins / MathMlReader / latex2mathml / aggregator.py View on Github external
aggregated.append(g)
                except EmptyGroupError:
                    aggregated += ['[', ']']
            elif token in '_^':
                process_sub_sup(aggregated, token, tokens)
            elif token.startswith(r'\begin') or token in MATRICES:
                aggregated += environment(token, tokens)
            elif token == r'\over':
                try:
                    numerator = aggregated.pop()
                    aggregated.append(r'\frac')
                    aggregated.append([numerator])
                    denominator = next_item_or_group(tokens)
                    aggregated.append([denominator])
                except IndexError:
                    raise NumeratorNotFoundError
                except (StopIteration, EmptyGroupError):
                    raise DenominatorNotFoundError
            else:
                aggregated.append(token)
        except EmptyGroupError:
            aggregated += ['{', '}']
            continue
        except StopIteration:
            break
    return aggregated