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

Function _fix_fracs

examples/utils/math_normalizer.py:22–51  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

20
21
22def _fix_fracs(string):
23 substrs = string.split("\\frac")
24 new_str = substrs[0]
25 if len(substrs) > 1:
26 substrs = substrs[1:]
27 for substr in substrs:
28 new_str += "\\frac"
29 if substr[0] == "{":
30 new_str += substr
31 else:
32 try:
33 assert len(substr) >= 2
34 except:
35 return string
36 a = substr[0]
37 b = substr[1]
38 if b != "{":
39 if len(substr) > 2:
40 post_substr = substr[2:]
41 new_str += "{" + a + "}{" + b + "}" + post_substr
42 else:
43 new_str += "{" + a + "}{" + b + "}"
44 else:
45 if len(substr) > 2:
46 post_substr = substr[2:]
47 new_str += "{" + a + "}" + b + post_substr
48 else:
49 new_str += "{" + a + "}" + b
50 string = new_str
51 return string
52
53
54def _fix_a_slash_b(string):

Callers 1

_strip_stringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected