Converts LaTeX subscripts in italic fonts into mathrm fonts. :param textext: LaTeX snippet :type textxt: str :return: Modified LaTeX snippet :rtype: str :example: >>> textext = "\\frac{V_{out}}{V_{in}}" >>> print(sub2rm(textext)) \\fr
(textext)
| 113 | # Work-around to change subscripts to mathrm: |
| 114 | |
| 115 | def sub2rm(textext): |
| 116 | """ |
| 117 | Converts LaTeX subscripts in italic fonts into mathrm fonts. |
| 118 | |
| 119 | :param textext: LaTeX snippet |
| 120 | :type textxt: str |
| 121 | |
| 122 | :return: Modified LaTeX snippet |
| 123 | :rtype: str |
| 124 | |
| 125 | :example: |
| 126 | |
| 127 | >>> textext = "\\frac{V_{out}}{V_{in}}" |
| 128 | >>> print(sub2rm(textext)) |
| 129 | |
| 130 | \\frac{V_{\\mathrm{out}}}{V_{\\mathrm{in}}} |
| 131 | """ |
| 132 | pos = 0 |
| 133 | out = '' |
| 134 | pattern = re.compile(r'_{([a-zA-Z0-9]+)}') |
| 135 | for m in re.finditer(pattern, textext): |
| 136 | out += textext[pos:m.start()+1]+'{\\mathrm'+textext[m.start()+1: m.end()]+'}' |
| 137 | pos = m.end() |
| 138 | out += textext[pos:] |
| 139 | return out |
| 140 | |
| 141 | # Convert all the snippets |
| 142 |