From c81bb9d4f0c6208111f2d146dad299935ec39c29 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 30 Jan 2018 00:01:15 -0800 Subject: [PATCH] When latex fails, make sure it does not write a dvi. PR 10180 added some tests checking that when the latex subprocess used by usetex fails, a RuntimeError does propagate up to the Python process. It originally passed the CI, but since its merge, various CIs have been failing on the test that a text with `$22_2_2$` (an invalid tex construct) fails when usetex is set. This is because while `latex --interaction=nonstopmode` does exit with error code 1 when processing a file with that construct, the error is "benign" enough that it still writes a dvi before exiting (the contents are simply as if the input was `$22_{22}$`). The dvi goes into the tex cache and later CI runs pick up the cached dvi instead of running the subprocess, thus failing the test. The solution is to use --halt-on-error on top of nonstopmode, see e.g. https://tex.stackexchange.com/questions/258814/what-is-the-difference-between-interaction-nonstopmode-and-halt-on-error (and to clear your tex cache). Note that before the PR, there would similarly be the weird behavior (for the user) that the first attempt to use a "benignly" invalid tex construct would trigger an exception, but latter attempts would not (for the same reason as above). --- lib/matplotlib/texmanager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index da251a0667a3..c9001151cde9 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -361,7 +361,8 @@ def make_dvi(self, tex, fontsize): texfile = self.make_tex(tex, fontsize) with Locked(self.texcache): self._run_checked_subprocess( - ["latex", "-interaction=nonstopmode", texfile], tex) + ["latex", "-interaction=nonstopmode", "--halt-on-error", + texfile], tex) for fname in glob.glob(basefile + '*'): if not fname.endswith(('dvi', 'tex')): try: @@ -387,7 +388,8 @@ def make_dvi_preview(self, tex, fontsize): if not os.path.exists(dvifile) or not os.path.exists(baselinefile): texfile = self.make_tex_preview(tex, fontsize) report = self._run_checked_subprocess( - ["latex", "-interaction=nonstopmode", texfile], tex) + ["latex", "-interaction=nonstopmode", "--halt-on-error", + texfile], tex) # find the box extent information in the latex output # file and store them in ".baseline" file