From 686dffadb42dcbf0dbee29ad1f5555356c77a9f5 Mon Sep 17 00:00:00 2001 From: tfpf <19171016+tfpf@users.noreply.github.com> Date: Mon, 25 Jul 2022 14:46:24 +0530 Subject: [PATCH] Mathtext spaces must be independent of font style. --- lib/matplotlib/_mathtext.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 3c4be2144533..3d6e943704e9 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -1935,13 +1935,17 @@ def non_math(self, s, loc, toks): float_literal = staticmethod(pyparsing_common.convertToFloat) def _make_space(self, percentage): - # All spaces are relative to em width + # In TeX, an em (the unit usually used to measure horizontal lengths) + # is not the width of the character 'm'; it is the same in different + # font styles (e.g. roman or italic). Mathtext, however, uses 'm' in + # the italic style so that horizontal spaces don't depend on the + # current font style. state = self.get_state() key = (state.font, state.fontsize, state.dpi) width = self._em_width_cache.get(key) if width is None: metrics = state.font_output.get_metrics( - state.font, mpl.rcParams['mathtext.default'], 'm', + 'it', mpl.rcParams['mathtext.default'], 'm', state.fontsize, state.dpi) width = metrics.advance self._em_width_cache[key] = width