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