8000 Merge pull request #4895 from zblz/texmanager-preamble · matplotlib/matplotlib@3f758ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f758ab

Browse files
committed
Merge pull request #4895 from zblz/texmanager-preamble
Add latex preamble to texmanager _fontconfig
2 parents d85a9a4 + adbd34e commit 3f758ab

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import matplotlib.pyplot as plt
5+
from matplotlib.texmanager import TexManager
6+
7+
8+
def test_fontconfig_preamble():
9+
"""
10+
Test that the preamble is included in _fontconfig
11+
"""
12+
plt.rcParams['text.usetex'] = True
13+
14+
tm1 = TexManager()
15+
font_config1 = tm1.get_font_config()
16+
17+
plt.rcParams['text.latex.preamble'] = [r'\usepackage{txfonts}']
18+
tm2 = TexManager()
19+
font_config2 = tm2.get_font_config()
20+
21+
assert font_config1 != font_config2

lib/matplotlib/texmanager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ def __init__(self):
203203
'default.' % ff, 'helpful')
204204
setattr(self, font_family_attr, self.font_info[font_family])
205205
fontconfig.append(getattr(self, font_family_attr)[0])
206+
# Add a hash of the latex preamble to self._fontconfig so that the
207+
# correct png is selected for strings rendered with same font and dpi
208+
# even if the latex preamble changes within the session
209+
preamble_bytes = six.text_type(self.get_custom_preamble()).encode('utf-8')
210+
fontconfig.append(md5(preamble_bytes).hexdigest())
206211
self._fontconfig = ''.join(fontconfig)
207212

208213
# The following packages and commands need to be included in the latex

0 commit comments

Comments
 (0)
0