@@ -241,24 +241,14 @@ def __init__(self):
241241 self ._finalize_tmpdir = weakref .finalize (self , self ._tmpdir .cleanup )
242242
243243 # test the LaTeX setup to ensure a clean startup of the subprocess
244- try :
245- self ._setup_latex_process (expect_reply = False )
246- except FileNotFoundError as err :
247- raise RuntimeError (
248- f"{ self .latex .args [0 ]!r} not found. Install it or change "
249- f"rcParams['pgf.texsystem'] to an available TeX "
250- f"implementation." ) from err
251- except OSError as err :
252- raise RuntimeError (
253- f"Error starting process { self .latex .args [0 ]!r} " ) from err
244+ self ._setup_latex_process (expect_reply = False )
254245 stdout , stderr = self .latex .communicate ("\n \\ makeatletter\\ @@end\n " )
255246 if self .latex .returncode != 0 :
256247 raise LatexError (
257248 f"LaTeX errored (probably missing font or error in preamble) "
258249 f"while processing the following input:\n "
259250 f"{ self ._build_latex_header ()} " ,
260251 stdout )
261-
262252 self .latex = None # Will be set up on first use.
263253 # Per-instance cache.
264254 self ._get_box_metrics = functools .lru_cache (self ._get_box_metrics )
@@ -268,10 +258,19 @@ def _setup_latex_process(self, *, expect_reply=True):
268258 # Windows, we must ensure that the subprocess has quit before being
269259 # able to delete the tmpdir in which it runs; in order to do so, we
270260 # must first `kill()` it, and then `communicate()` with it.
271- self .latex = subprocess .Popen (
272- [mpl .rcParams ["pgf.texsystem" ], "-halt-on-error" ],
273- stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
274- encoding = "utf-8" , cwd = self .tmpdir )
261+ try :
262+ self .latex = subprocess .Popen (
263+ [mpl .rcParams ["pgf.texsystem" ], "-halt-on-error" ],
264+ stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
265+ encoding = "utf-8" , cwd = self .tmpdir )
266+ except FileNotFoundError as err :
267+ raise RuntimeError (
268+ f"{ mpl .rcParams ['pgf.texsystem' ]!r} not found; install it or change "
269+ f"rcParams['pgf.texsystem'] to an available TeX implementation"
270+ ) from err
271+ except OSError as err :
272+ raise RuntimeError (
273+ f"Error starting { mpl .rcParams ['pgf.texsystem' ]!r} " ) from err
275274
276275 def finalize_latex (latex ):
277276 latex .kill ()
0 commit comments