Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83a19bd

Browse files
committed
Delay \usepackage{textcomp} until after the custom tex preamble.
... and only load textcomp if it hasn't already been loaded. This avoids option clashes in case the custom preamble loads textcomp with other options.
1 parent e53a00c commit 83a19bd

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

lib/matplotlib/tests/test_usetex.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,10 @@ def test_minus_no_descent():
7777
heights[vals] = ((np.array(fig.canvas.buffer_rgba())[..., 0] != 255)
7878
.any(axis=1).sum())
7979
assert len({*heights.values()}) == 1
80+
81+
82+
def test_textcomp_full():
83+
plt.rcParams["text.latex.preamble"] = r"\usepackage[full]{textcomp}"
84+
fig = plt.figure()
85+
fig.text(.5, .5, "hello, world", usetex=True)
86+
fig.canvas.draw()

lib/matplotlib/texmanager.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ def get_font_config(self):
154154
self._fonts['monospace'][1]]
155155
if self.font_family == 'cursive':
156156
cmd.append(self._fonts['cursive'][1])
157-
self._font_preamble = '\n'.join(
158-
[r'\usepackage{type1cm}', *cmd, r'\usepackage{textcomp}'])
157+
self._font_preamble = '\n'.join([r'\usepackage{type1cm}', *cmd])
159158

160159
return ''.join(fontconfig)
161160

@@ -188,10 +187,16 @@ def _get_preamble(self):
188187
self._font_preamble,
189188
r"\usepackage[utf8]{inputenc}",
190189
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
191-
# Needs to come early so that the custom preamble can change the
192-
# geometry, e.g. in convert_psfrags.
190+
# geometry is loaded before the custom preamble as convert_psfrags
191+
# relies on a custom preamble to change the geometry.
193192
r"\usepackage[papersize=72in,body=70in,margin=1in]{geometry}",
194193
self.get_custom_preamble(),
194+
# textcomp is loaded last (if not already loaded by the custom
195+
# preamble) in order not to clash with custom packages (e.g.
196+
# newtxtext) which load it with different options.
197+
r"\makeatletter"
198+
r"\@ifpackageloaded{textcomp}{}{\usepackage{textcomp}}"
199+
r"\makeatother",
195200
])
196201

197202
def make_tex(self, tex, fontsize):

0 commit comments

Comments
 (0)