|
28 | 28 | from pyparsing import (
|
29 | 29 | Combine, Empty, FollowedBy, Forward, Group, Literal, oneOf, OneOrMore,
|
30 | 30 | Optional, ParseBaseException, ParseFatalException, ParserElement,
|
31 |
| - QuotedString, Regex, StringEnd, Suppress, ZeroOrMore) |
| 31 | + ParseResults, QuotedString, Regex, StringEnd, Suppress, ZeroOrMore) |
32 | 32 |
|
33 | 33 | from matplotlib import cbook, colors as mcolors, rcParams
|
34 | 34 | from matplotlib.afm import AFM
|
@@ -2873,33 +2873,35 @@ def accent(self, s, loc, toks):
|
2873 | 2873 | ])
|
2874 | 2874 |
|
2875 | 2875 | def function(self, s, loc, toks):
|
2876 |
| - self.push_state() |
2877 |
| - state = self.get_state() |
2878 |
| - state.font = 'rm' |
2879 |
| - hlist_list = [Char(c, state) for c in toks[0]] |
2880 |
| - next_char = next((c for c in s[loc+len(toks[0])+1:] if c != ' '), '') |
2881 |
| - delimiters = self._left_delim | self._ambi_delim | self._right_delim |
2882 |
| - delimiters |= set(r"^_".split()) |
2883 |
| - if (next_char not in delimiters and |
2884 |
| - toks[0] not in self._overunder_functions): |
2885 |
| - # Add thin space except when followed by parenthesis, bracket, etc. |
2886 |
| - hlist_list += [self._make_space(self._space_widths[r'\,'])] |
2887 |
| - hlist = Hlist(hlist_list) |
2888 |
| - self.pop_state() |
| 2876 | + hlist = self.operatorname(s, loc, toks) |
2889 | 2877 | hlist.function_name = toks[0]
|
2890 | 2878 | return hlist
|
2891 | 2879 |
|
2892 | 2880 | def operatorname(self, s, loc, toks):
|
2893 | 2881 | self.push_state()
|
2894 | 2882 | state = self.get_state()
|
2895 | 2883 | state.font = 'rm'
|
| 2884 | + hlist_list = [] |
2896 | 2885 | # Change the font of Chars, but leave Kerns alone
|
2897 | 2886 | for c in toks[0]:
|
2898 | 2887 | if isinstance(c, Char):
|
2899 | 2888 | c.font = 'rm'
|
2900 | 2889 | c._update_metrics()
|
| 2890 | + hlist_list.append(c) |
| 2891 | + else: |
| 2892 | + hlist_list.append(Char(c, state)) |
| 2893 | + next_char_loc = loc + len(toks[0]) + 1 |
| 2894 | + if isinstance(toks[0], ParseResults): |
| 2895 | + next_char_loc += 14 # Skip `operatorname{}` |
| 2896 | + next_char = next((c for c in s[next_char_loc:] if c != ' '), '') |
| 2897 | + delimiters = self._left_delim | self._ambi_delim | self._right_delim |
| 2898 | + delimiters |= set(r"^_".split()) |
| 2899 | + if (next_char not in delimiters and |
| 2900 | + toks[0] not in self._overunder_functions): |
| 2901 | + # Add thin space except when followed by parenthesis, bracket, etc. |
| 2902 | + hlist_list += [self._make_space(self._space_widths[r'\,'])] |
2901 | 2903 | self.pop_state()
|
2902 |
| - return Hlist(toks[0]) |
| 2904 | + return Hlist(hlist_list) |
2903 | 2905 |
|
2904 | 2906 | def start_group(self, s, loc, toks):
|
2905 | 2907 | self.push_state()
|
|
0 commit comments