@@ -291,43 +291,41 @@ def __init__(self):
291
291
self ._finalize_tmpdir = weakref .finalize (self , self ._tmpdir .cleanup )
292
292
293
293
# test the LaTeX setup to ensure a clean startup of the subprocess
294
- self .texcommand = mpl .rcParams ["pgf.texsystem" ]
295
- self .latex_header = LatexManager ._build_latex_header ()
296
- latex_end = "\n \\ makeatletter\n \\ @@end\n "
297
294
try :
298
- latex = subprocess .Popen (
299
- [self .texcommand , "-halt-on-error" ],
300
- stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
301
- encoding = "utf-8" , cwd = self .tmpdir )
295
+ self ._setup_latex_process (expect_reply = False )
302
296
except FileNotFoundError as err :
303
297
raise RuntimeError (
304
- f"{ self .texcommand } not found. Install it or change "
298
+ f"{ self .latex . args [ 0 ]!r } not found. Install it or change "
305
299
f&
10000
quot;rcParams['pgf.texsystem'] to an available TeX "
306
300
f"implementation." ) from err
307
301
except OSError as err :
308
- raise RuntimeError ("Error starting process %r" %
309
- self .texcommand ) from err
310
- test_input = self .latex_header + latex_end
311
- stdout , stderr = latex .communicate (test_input )
312
- if latex .returncode != 0 :
302
+ raise RuntimeError (
303
+ f"Error starting process { self .latex .args [0 ]!r} " ) from err
304
+ stdout , stderr = self .latex .communicate ("\n \\ makeatletter\\ @@end\n " )
305
+ if self .latex .returncode != 0 :
313
306
raise LatexError (
314
307
f"LaTeX errored (probably missing font or error in preamble) "
315
- f"while processing the following input:\n { test_input } " ,
308
+ f"while processing the following input:\n "
309
+ f"{ self ._build_latex_header ()} " ,
316
310
stdout )
317
311
318
312
self .latex = None # Will be set up on first use.
319
313
# Per-instance cache.
320
314
self ._get_box_metrics = functools .lru_cache ()(self ._get_box_metrics )
321
315
322
316
str_cache = _api .deprecated ("3.5" )(property (lambda self : {}))
317
+ texcommand = _api .deprecated ("3.6" )(
318
+ property (lambda self : mpl .rcParams ["pgf.texsystem" ]))
319
+ latex_header = _api .deprecated ("3.6" )(
320
+ property (lambda self : self ._build_latex_header ()))
323
321
324
- def _setup_latex_process (self ):
322
+ def _setup_latex_process (self , * , expect_reply = True ):
325
323
# Open LaTeX process for real work; register it for deletion. On
326
324
# Windows, we must ensure that the subprocess has quit before being
327
325
# able to delete the tmpdir in which it runs; in order to do so, we
328
326
# must first `kill()` it, and then `communicate()` with it.
329
327
self .latex = subprocess .Popen (
330
- [self . texcommand , "-halt-on-error" ],
328
+ [mpl . rcParams [ "pgf.texsystem" ] , "-halt-on-error" ],
331
329
stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
332
330
encoding = "utf-8" , cwd = self .tmpdir )
333
331
@@ -339,9 +337,9 @@ def finalize_latex(latex):
339
337
self , finalize_latex , self .latex )
340
338
# write header with 'pgf_backend_query_start' token
341
339
self ._stdin_writeln (self ._build_latex_header ())
342
- # read all lines until our 'pgf_backend_query_start' token appears
343
- self ._expect ("*pgf_backend_query_start" )
344
- self ._expect_prompt ()
340
+ if expect_reply : # read until 'pgf_backend_query_start' token appears
341
+ self ._expect ("*pgf_backend_query_start" )
342
+ self ._expect_prompt ()
345
343
346
344
def get_width_height_descent (self , text , prop ):
347
345
"""
0 commit comments