@@ -87,9 +87,9 @@ class TexManager:
87
87
'computer modern typewriter' : ('cmtt' , r'\usepackage{type1ec}' )}
88
88
89
89
_rc_cache = None
90
- _rc_cache_keys = (
91
- ( 'text.latex.preamble' , 'text.latex.unicode ' , 'text.latex.preview ' ,
92
- 'font.family' ) + tuple ( 'font.' + n for n in font_families ))
90
+ _rc_cache_keys = [
91
+ 'text.latex.preamble' , 'text.latex.preview ' , 'font.family ' ,
92
+ * [ 'font.' + n for n in font_families ]]
93
93
94
94
@cbook .deprecated ("3.3" , alternative = "matplotlib.get_cachedir()" )
95
95
@property
@@ -184,18 +184,15 @@ def get_custom_preamble(self):
184
184
return rcParams ['text.latex.preamble' ]
185
185
186
186
def _get_preamble (self ):
187
- unicode_preamble = "\n " .join ([
188
- r"\usepackage[utf8]{inputenc}" ,
189
- r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}" ,
190
- ]) if rcParams ["text.latex.unicode" ] else ""
191
187
return "\n " .join ([
192
188
r"\documentclass{article}" ,
193
189
# Pass-through \mathdefault, which is used in non-usetex mode to
194
190
# use the default text font but was historically suppressed in
195
191
# usetex mode.
196
192
r"\newcommand{\mathdefault}[1]{#1}" ,
197
193
self ._font_preamble ,
198
- unicode_preamble ,
194
+ r"\usepackage[utf8]{inputenc}" ,
195
+ r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}" ,
199
196
self .get_custom_preamble (),
200
197
])
201
198
@@ -210,26 +207,17 @@ def make_tex(self, tex, fontsize):
210
207
fontcmd = {'sans-serif' : r'{\sffamily %s}' ,
211
208
'monospace' : r'{\ttfamily %s}' }.get (self .font_family ,
212
209
r'{\rmfamily %s}' )
213
- tex = fontcmd % tex
214
210
215
- s = r"""
211
+ Path (texfile ).write_text (
212
+ r"""
216
213
%s
217
214
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
218
215
\pagestyle{empty}
219
216
\begin{document}
220
217
\fontsize{%f}{%f}%s
221
218
\end{document}
222
- """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , tex )
223
- with open (texfile , 'wb' ) as fh :
224
- if rcParams ['text.latex.unicode' ]:
225
- fh .write (s .encode ('utf8' ))
226
- else :
227
- try :
228
- fh .write (s .encode ('ascii' ))
229
- except UnicodeEncodeError :
230
- _log .info ("You are using unicode and latex, but have not "
231
- "enabled the 'text.latex.unicode' rcParam." )
232
- raise
219
+ """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , fontcmd % tex ),
220
+ encoding = 'utf-8' )
233
221
234
222
return texfile
235
223
@@ -250,12 +238,12 @@ def make_tex_preview(self, tex, fontsize):
250
238
fontcmd = {'sans-serif' : r'{\sffamily %s}' ,
251
239
'monospace' : r'{\ttfamily %s}' }.get (self .font_family ,
252
240
r'{\rmfamily %s}' )
253
- tex = fontcmd % tex
254
241
255
242
# newbox, setbox, immediate, etc. are used to find the box
256
243
# extent of the rendered text.
257
244
258
- s = r"""
245
+ Path (texfile ).write_text (
246
+ r"""
259
247
%s
260
248
\usepackage[active,showbox,tightpage]{preview}
261
249
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
@@ -270,17 +258,8 @@ def make_tex_preview(self, tex, fontsize):
270
258
{\fontsize{%f}{%f}%s}
271
259
\end{preview}
272
260
\end{document}
273
- """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , tex )
274
- with open (texfile , 'wb' ) as fh :
275
- if rcParams ['text.latex.unicode' ]:
276
- fh .write (s .encode ('utf8' ))
277
- else :
278
- try :
279
- fh .write (s .encode ('ascii' ))
280
- except UnicodeEncodeError :
281
- _log .info ("You are using unicode and latex, but have not "
282
- "enabled the 'text.latex.unicode' rcParam." )
283
- raise
261
+ """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , fontcmd % tex ),
262
+ encoding = 'utf-8' )
284
263
285
264
return texfile
286
265
0 commit comments