Skip to content

Commit 5fc0441

Browse files
authored
Merge pull request #23482 from tfpf/consistent-spacing
Mathtext spaces must be independent of font style.
2 parents 1e4bc52 + 686dffa commit 5fc0441

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/_mathtext.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1935,13 +1935,17 @@ def non_math(self, s, loc, toks):
19351935
float_literal = staticmethod(pyparsing_common.convertToFloat)
19361936

19371937
def _make_space(self, percentage):
1938-
# All spaces are relative to em width
1938+
# In TeX, an em (the unit usually used to measure horizontal lengths)
1939+
# is not the width of the character 'm'; it is the same in different
1940+
# font styles (e.g. roman or italic). Mathtext, however, uses 'm' in
1941+
# the italic style so that horizontal spaces don't depend on the
1942+
# current font style.
19391943
state = self.get_state()
19401944
key = (state.font, state.fontsize, state.dpi)
19411945
width = self._em_width_cache.get(key)
19421946
if width is None:
19431947
metrics = state.font_output.get_metrics(
1944-
state.font, mpl.rcParams['mathtext.default'], 'm',
1948+
'it', mpl.rcParams['mathtext.default'], 'm',
19451949
state.fontsize, state.dpi)
19461950
width = metrics.advance
19471951
self._em_width_cache[key] = width

0 commit comments

Comments
 (0)