(string)
| 94 | |
| 95 | |
| 96 | def _strip_string(string): |
| 97 | # linebreaks |
| 98 | string = string.replace("\n", "") |
| 99 | # print(string) |
| 100 | |
| 101 | # remove inverse spaces |
| 102 | string = string.replace("\\!", "") |
| 103 | # print(string) |
| 104 | |
| 105 | # replace \\ with \ |
| 106 | string = string.replace("\\\\", "\\") |
| 107 | # print(string) |
| 108 | |
| 109 | # replace tfrac and dfrac with frac |
| 110 | string = string.replace("tfrac", "frac") |
| 111 | string = string.replace("dfrac", "frac") |
| 112 | # print(string) |
| 113 | |
| 114 | # remove \left and \right |
| 115 | string = string.replace("\\left", "") |
| 116 | string = string.replace("\\right", "") |
| 117 | # print(string) |
| 118 | |
| 119 | # Remove circ (degrees) |
| 120 | string = string.replace("^{\\circ}", "") |
| 121 | string = string.replace("^\\circ", "") |
| 122 | |
| 123 | # remove dollar signs |
| 124 | string = string.replace("\\$", "") |
| 125 | |
| 126 | # remove units (on the right) |
| 127 | string = _remove_right_units(string) |
| 128 | |
| 129 | # remove percentage |
| 130 | string = string.replace("\\%", "") |
| 131 | string = string.replace("\%", "") |
| 132 | |
| 133 | # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string |
| 134 | string = string.replace(" .", " 0.") |
| 135 | string = string.replace("{.", "{0.") |
| 136 | # if empty, return empty string |
| 137 | if len(string) == 0: |
| 138 | return string |
| 139 | if string[0] == ".": |
| 140 | string = "0" + string |
| 141 | |
| 142 | # to consider: get rid of e.g. "k = " or "q = " at beginning |
| 143 | if len(string.split("=")) == 2: |
| 144 | if len(string.split("=")[0]) <= 2: |
| 145 | string = string.split("=")[1] |
| 146 | |
| 147 | # fix sqrt3 --> sqrt{3} |
| 148 | string = _fix_sqrt(string) |
| 149 | |
| 150 | # remove spaces |
| 151 | string = string.replace(" ", "") |
| 152 | |
| 153 | # \frac1b or \frac12 --> \frac{1}{b} and \frac{1}{2}, etc. Even works with \frac1{72} (but not \frac{72}1). Also does a/b --> \\frac{a}{b} |
no test coverage detected