sciq.web.app.services.parser.parser

class web.app.services.parser.parser.ASCIIMath2Tex(grammar, *args, cache=True, inplace=False, parser='lalr', lexer='contextual', transformer=<web.app.services.parser.parser.LatexTransformer object>, **kwargs)

Bases: object

Class that handle the translation from ASCIIMath to LaTeX

Parameters:
  • grammar (str) – grammar to be recognized by the parser.
  • cache (bool, optional) – If True, use cached parser. See Lark. Defaults to True.
  • inplace (bool, optional) – If True, parse the input inplace. See Lark. Defaults to False.
  • lexer (str, optional) – Lexer used during parsing. See Lark. Defaults to “contextual”.
  • parser (str, optional) – Parser algorithm. See Lark. Defaults to “lalr”.
  • lexer – Lexer algorithm. See Lark. Defaults to “contextual”.
  • transformer (str, optional) – a class that specifies how the parsed input will be transformed. In this case it represents how a recognized (parsed) ASCIIMath expression will be transformed into its LaTeX equivalent. Defaults to “LatexTransformer()”.
  • *args – Additional positional arguments to the Lark class.
  • **kwargs – Additional keyword arguments to the Lark class.
asciimath2tex(exp: str, pprint=False)

Translates an ASCIIMath string to LaTeX

Parameters:
  • exp (str) – String to translate. If from_file is True, then s must represent the file’s path
  • pprint (bool, optional) – Abstract Syntax Tree pretty print. Defaults to False.
Returns:

LaTeX translated expression

Return type:

str