@@ -273,13 +273,14 @@ def __init__(self):
273273 [self .texcommand , "-halt-on-error" ],
274274 stdin = subprocess .PIPE , stdout = subprocess .PIPE ,
275275 encoding = "utf-8" , cwd = self .tmpdir )
276- except FileNotFoundError :
276+ except FileNotFoundError as err :
277277 raise RuntimeError (
278278 f"{ self .texcommand } not found. Install it or change "
279279 f"rcParams['pgf.texsystem'] to an available TeX "
280- f"implementation." )
281- except OSError :
282- raise RuntimeError ("Error starting process %r" % self .texcommand )
280+ f"implementation." ) from err
281+ except OSError as err :
282+ raise RuntimeError ("Error starting process %r" %
283+ self .texcommand ) from err
283284 test_input = self .latex_header + latex_end
284285 stdout , stderr = latex .communicate (test_input )
285286 if latex .returncode != 0 :
@@ -342,7 +343,7 @@ def get_width_height_descent(self, text, prop):
342343 self ._expect_prompt ()
343344 except LatexError as e :
344345 raise ValueError ("Error processing '{}'\n LaTeX Output:\n {}"
345- .format (text , e .latex_output ))
346+ .format (text , e .latex_output )) from e
346347
347348 # typeout width, height and text offset of the last textbox
348349 self ._stdin_writeln (r"\typeout{\the\wd0,\the\ht0,\the\dp0}" )
@@ -351,14 +352,14 @@ def get_width_height_descent(self, text, prop):
351352 answer = self ._expect_prompt ()
352353 except LatexError as e :
353354 raise ValueError ("Error processing '{}'\n LaTeX Output:\n {}"
354- .format (text , e .latex_output ))
355+ .format (text , e .latex_output )) from e
355356
356357 # parse metrics from the answer string
357358 try :
358359 width , height , offset = answer .splitlines ()[0 ].split ("," )
359- except Exception :
360+ except Exception as err :
360361 raise ValueError ("Error processing '{}'\n LaTeX Output:\n {}"
361- .format (text , answer ))
362+ .format (text , answer )) from err
362363 w , h , o = float (width [:- 2 ]), float (height [:- 2 ]), float (offset [:- 2 ])
363364
364365 # the height returned from LaTeX goes from base to top.
0 commit comments