How to use the latex2mathml.symbols_parser.convert_symbol 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 / latex2mathml / converter.py View on Github external
alignment = elements[index]
        next(iterable)
    if element in (r"\lim", r"\inf", r"\sup", r"\max", r"\min"):
        limit = SubElement(new_parent, "mo")
        limit.text = element[1:]
    for j in range(params):
        index += 1
        param = elements[index]
        if element == "_" and index == 1 and param == r"\sum":
            new_parent.tag = "munder"
            _classify(param, new_parent)
        elif element == r"\left" or element == r"\right":
            if param == ".":
                pass
            else:
                symbol = convert_symbol(param)
                new_parent.text = param if symbol is None else "&#x{};".format(symbol)
        elif element == r"\array":
            _convert_array_content(param, new_parent, alignment)
        elif element in MATRICES:
            _convert_matrix_content(
                param, new_parent, alignment, element == r"\substack"
            )
        else:
            if isinstance(param, list):
                _parent = SubElement(new_parent, "mrow")
                _classify_subgroup(param, _parent)
            else:
                _classify(param, new_parent)
    _get_postfix_element(element, parent)
    if element in (r"\overline", r"\bar"):
        mo = SubElement(new_parent, "mo", stretchy="true")
github roniemartinez / latex2mathml / latex2mathml / tokenizer.py View on Github external
buffer = ""
            elif char in "{}*":
                # FIXME: Anything that starts with '\math' passes. There is a huge list of math symbols in
                #  unimathsymbols.txt and hard-coding all of them is inefficient.
                if (
                    buffer.startswith(r"\begin")
                    or buffer.startswith(r"\end")
                    or buffer.startswith(r"\math")
                ):
                    if buffer.endswith("}"):
                        yield buffer
                        yield char
                        buffer = ""
                        continue
                    elif buffer.startswith(r"\math") and char == "}":
                        symbol = convert_symbol(buffer + char)
                        if symbol:
                            yield "&#x{};".format(symbol)
                            buffer = ""
                            continue
                        else:
                            index = buffer.index("{")
                            yield buffer[:index]
                            yield list(tokenize(buffer[index + 1 :]))
                            buffer = ""
                            continue
                    buffer += char
                else:
                    if len(buffer):
                        yield buffer
                        buffer = ""
                    yield char
github roniemartinez / latex2mathml / latex2mathml / converter.py View on Github external
def _classify(_element: str, parent: Element, is_math_mode: bool = False) -> None:
    symbol = convert_symbol(_element)
    if re.match(r"\d+(.\d+)?", _element):
        mn = SubElement(parent, "mn")
        mn.text = _element
    elif len(_element) and _element in "<>&":
        mo = SubElement(parent, "mo")
        mo.text = {"<": "<", ">": ">", "&": "&"}[_element]
    elif len(_element) and _element in "+-*/()=":
        mo = SubElement(parent, "mo")
        mo.text = _element if symbol is None else "&#x{};".format(symbol)
        if _element in "()":
            mo.attrib["stretchy"] = "false"
    elif (
        symbol
        and (
            int(symbol, 16) in range(int("2200", 16), int("22FF", 16) + 1)
            or int(symbol, 16) in range(int("2190", 16), int("21FF", 16) + 1)