MCPcopy Create free account
hub / github.com/Bairong-Xdynamics/MistakeNotebookLearning / _parse_latex

Function _parse_latex

examples/utils/grader.py:31–46  ·  view source on GitHub ↗

Attempts to parse latex to an expression sympy can read.

(expr: str)

Source from the content-addressed store, hash-verified

29
30
31def _parse_latex(expr: str) -> str:
32 """Attempts to parse latex to an expression sympy can read."""
33 expr = expr.replace("\\tfrac", "\\frac")
34 expr = expr.replace("\\dfrac", "\\frac")
35 expr = expr.replace("\\frac", " \\frac") # Play nice with mixed numbers.
36 expr = latex2text.LatexNodes2Text().latex_to_text(expr)
37
38 # Replace the specific characters that this parser uses.
39 expr = expr.replace("√", "sqrt")
40 expr = expr.replace("π", "pi")
41 expr = expr.replace("∞", "inf")
42 expr = expr.replace("∪", "U")
43 expr = expr.replace("·", "*")
44 expr = expr.replace("×", "*")
45
46 return expr.strip()
47
48
49def _is_float(num: str) -> bool:

Callers 1

_normalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected