@@ -95,9 +95,9 @@ class TexManager:
9595 'computer modern typewriter' : ('cmtt' , r'\usepackage{type1ec}' )}
9696
9797 _rc_cache = None
98- _rc_cache_keys = (
99- ( 'text.latex.preamble' , 'text.latex.unicode ' , 'text.latex.preview ' ,
100- 'font.family' ) + tuple ( 'font.' + n for n in font_families ))
98+ _rc_cache_keys = [
99+ 'text.latex.preamble' , 'text.latex.preview ' , 'font.family ' ,
100+ * [ 'font.' + n for n in font_families ]]
101101
102102 @functools .lru_cache () # Always return the same instance.
103103 def __new__ (cls ):
@@ -193,18 +193,15 @@ def get_custom_preamble(self):
193193 return rcParams ['text.latex.preamble' ]
194194
195195 def _get_preamble (self ):
196- unicode_preamble = "\n " .join ([
197- r"\usepackage[utf8]{inputenc}" ,
198- r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}" ,
199- ]) if rcParams ["text.latex.unicode" ] else ""
200196 return "\n " .join ([
201197 r"\documentclass{article}" ,
202198 # Pass-through \mathdefault, which is used in non-usetex mode to
203199 # use the default text font but was historically suppressed in
204200 # usetex mode.
205201 r"\newcommand{\mathdefault}[1]{#1}" ,
206202 self ._font_preamble ,
207- unicode_preamble ,
203+ r"\usepackage[utf8]{inputenc}" ,
204+ r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}" ,
208205 self .get_custom_preamble (),
209206 ])
210207
@@ -219,26 +216,17 @@ def make_tex(self, tex, fontsize):
219216 fontcmd = {'sans-serif' : r'{\sffamily %s}' ,
220217 'monospace' : r'{\ttfamily %s}' }.get (self .font_family ,
221218 r'{\rmfamily %s}' )
222- tex = fontcmd % tex
223219
224- s = r"""
220+ Path (texfile ).write_text (
221+ r"""
225222%s
226223\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
227224\pagestyle{empty}
228225\begin{document}
229226\fontsize{%f}{%f}%s
230227\end{document}
231- """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , tex )
232- with open (texfile , 'wb' ) as fh :
233- if rcParams ['text.latex.unicode' ]:
234- fh .write (s .encode ('utf8' ))
235- else :
236- try :
237- fh .write (s .encode ('ascii' ))
238- except UnicodeEncodeError :
239- _log .info ("You are using unicode and latex, but have not "
240- "enabled the 'text.latex.unicode' rcParam." )
241- raise
228+ """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , fontcmd % tex ),
229+ encoding = 'utf-8' )
242230
243231 return texfile
244232
@@ -259,12 +247,12 @@ def make_tex_preview(self, tex, fontsize):
259247 fontcmd = {'sans-serif' : r'{\sffamily %s}' ,
260248 'monospace' : r'{\ttfamily %s}' }.get (self .font_family ,
261249 r'{\rmfamily %s}' )
262- tex = fontcmd % tex
263250
264251 # newbox, setbox, immediate, etc. are used to find the box
265252 # extent of the rendered text.
266253
267- s = r"""
254+ Path (texfile ).write_text (
255+ r"""
268256%s
269257\usepackage[active,showbox,tightpage]{preview}
270258\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
@@ -279,17 +267,8 @@ def make_tex_preview(self, tex, fontsize):
279267{\fontsize{%f}{%f}%s}
280268\end{preview}
281269\end{document}
282- """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , tex )
283- with open (texfile , 'wb' ) as fh :
284- if rcParams ['text.latex.unicode' ]:
285- fh .write (s .encode ('utf8' ))
286- else :
287- try :
288- fh .write (s .encode ('ascii' ))
289- except UnicodeEncodeError :
290- _log .info ("You are using unicode and latex, but have not "
291- "enabled the 'text.latex.unicode' rcParam." )
292- raise
270+ """ % (self ._get_preamble (), fontsize , fontsize * 1.25 , fontcmd % tex ),
271+ encoding = 'utf-8' )
293272
294273 return texfile
295274
0 commit comments