MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / _parse_latex

Function _parse_latex

data_preprocessing/math_util/__init__.py:36–51  ·  view source on GitHub ↗

Attempts to parse latex to an expression sympy can read.

(expr: str)

Source from the content-addressed store, hash-verified

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

Callers 1

_normalizeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected