File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,24 @@ def _last_boxed_only_string(text: str) -> str | None:
136
136
return retval
137
137
138
138
def _fix_fracs (text : str ) -> str :
139
+ """
140
+ Fix the formatting of fractions in the given text.
141
+ Copied from: https://github.com/hendrycks/math/blob/357963a7f5501a6c1708cf3f3fb0cdf525642761/modeling/math_equivalence.py#L1
142
+
143
+ Args:
144
+ text (str): The input text.
145
+
146
+ Returns:
147
+ str: The text with properly formatted fractions.
148
+
149
+ Examples:
150
+ >>> _fix_fracs("\\ frac12")
151
+ "\\ frac{1}{2}"
152
+ >>> _fix_fracs("\\ frac{3}{4}")
153
+ "\\ frac{3}{4}"
154
+ >>> _fix_fracs("\\ frac1{2}")
155
+ "\\ frac{1}{2}"
156
+ """
139
157
substrs = text .split ("\\ frac" )
140
158
new_str = substrs [0 ]
141
159
if len (substrs ) > 1 :
@@ -149,7 +167,8 @@ def _fix_fracs(text: str) -> str:
149
167
assert len (substr ) >= 2
150
168
except AssertionError :
151
169
return text
152
- a , b = substr
170
+ a = substr [0 ]
171
+ b = substr [1 ]
153
172
if b != "{" :
154
173
if len (substr ) > 2 :
155
174
post_substr = substr [2 :]
You can’t perform that action at this time.
0 commit comments