|
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,25 +2873,37 @@ 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 = Hlist([Char(c, state) for c in toks[0]]) |
2880 |
| - self.pop_state() |
| 2876 | + hlist = self.operatorname(s, loc, toks) |
2881 | 2877 | hlist.function_name = toks[0]
|
2882 | 2878 | return hlist
|
2883 | 2879 |
|
2884 | 2880 | def operatorname(self, s, loc, toks):
|
2885 | 2881 | self.push_state()
|
2886 | 2882 | state = self.get_state()
|
2887 | 2883 | state.font = 'rm'
|
| 2884 | + hlist_list = [] |
2888 | 2885 | # Change the font of Chars, but leave Kerns alone
|
2889 | 2886 | for c in toks[0]:
|
2890 | 2887 | if isinstance(c, Char):
|
2891 | 2888 | c.font = 'rm'
|
2892 | 2889 | c._update_metrics()
|
| 2890 | + hlist_list.append(c) |
| 2891 | + elif isinstance(c, str): |
| 2892 | + hlist_list.append(Char(c, state)) |
| 2893 | + else: |
| 2894 | + hlist_list.append(c) |
| 2895 | + next_char_loc = loc + len(toks[0]) + 1 |
| 2896 | + if isinstance(toks[0], ParseResults): |
| 2897 | + next_char_loc += len('operatorname{}') |
| 2898 | + next_char = next((c for c in s[next_char_loc:] if c != ' '), '') |
| 2899 | + delimiters = self._left_delim | self._ambi_delim | self._right_delim |
| 2900 | + delimiters |= {'^', '_'} |
| 2901 | + if (next_char not in delimiters and |
| 2902 | + toks[0] not in self._overunder_functions): |
| 2903 | + # Add thin space except when followed by parenthesis, bracket, etc. |
| 2904 | + hlist_list += [self._make_space(self._space_widths[r'\,'])] |
2893 | 2905 | self.pop_state()
|
2894 |
| - return Hlist(toks[0]) |
| 2906 | + return Hlist(hlist_list) |
2895 | 2907 |
|
2896 | 2908 | def start_group(self, s, loc, toks):
|
2897 | 2909 | self.push_state()
|
|
0 commit comments