@@ -286,24 +286,14 @@ def __init__(self):
286
286
self ._finalize_tmpdir = weakref .finalize (self , self ._tmpdir .cleanup )
287
287
288
288
# test the LaTeX setup to ensure a clean startup of the subprocess
289
- try :
290
- self ._setup_latex_process (expect_reply = False )
291
- except FileNotFoundError as err :
292
- raise RuntimeError (
293
- f"{ self .latex .args [0 ]!r} not found. Install it or change "
294
- f"rcParams['pgf.texsystem'] to an available TeX "
295
- f"implementation." ) from err
296
- except OSError as err :
297
- raise RuntimeError (
298
- f"Error starting process { self .latex .args [0 ]!r} " ) from err
289
+ self ._setup_latex_process (expect_reply = False )
299
290
stdout , stderr = self .latex .communicate ("\n \\ makeatletter\\ @@end\n " )
300
291
if self .latex .returncode != 0 :
301
292
raise LatexError (
302
293
f"LaTeX errored (probably missing font or error in preamble) "
303
294
f"while processing the following input:\n "
304
295
f"{ self ._build_latex_header ()} " ,
305
296
stdout )
306
-
307
297
self .latex = None # Will be set up on first use.
308
298
# Per-instance cache.
309
299
self ._get_box_metrics = functools .lru_cache ()(self ._get_box_metrics )
@@ -318,10 +308,19 @@ def _setup_latex_process(self, *, expect_reply=True):
318
308
# Windows, we must ensure that the subprocess has quit before being
319
309
# able to delete the tmpdir in which it runs; in order to do so, we
320
310
# must first `kill()` it, and then `communicate()` with it.
321
- self .latex = subprocess .Popen (
322
- [mpl .rcParams ["pgf.texsystem" ], "-halt-on-error" ],
323
- stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
324
- encoding = "utf-8" , cwd = self .tmpdir )
311
+ try :
312
+ self .latex = subprocess .Popen (
313
+ [mpl .rcParams ["pgf.texsystem" ], "-halt-on-error" ],
314
+ stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
315
+ encoding = "utf-8" , cwd = self .tmpdir )
316
+ except FileNotFoundError as err :
317
+ raise RuntimeError (
318
+ f"{ mpl .rcParams ['pgf.texsystem' ]!r} not found; install it or change "
319
+ f"rcParams['pgf.texsystem'] to an available TeX implementation"
320
+ ) from err
321
+ except OSError as err :
322
+ raise RuntimeError (
323
+ f"Error starting { mpl .rcParams ['pgf.texsystem' ]!r} " ) from err
325
324
326
325
def finalize_latex (latex ):
327
326
latex .kill ()
0 commit comments