From 28839b971a4bf6606b7b2d162b19c6b9c037fea8 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 10 May 2018 20:08:29 -0700 Subject: [PATCH] Don't bother checking luatex's version. Depending on the version of luatex, the pgf backend would either emit \pdfpagewidth or \pagewidth. Instead of explicitly checking the version of luatex (which requires additional code to parse the output of --version, and is brittle to (admittedly unlikely) possible future other changes in luatex or xetex), just emit some TeX code that emits whichever primitive is defined. --- lib/matplotlib/backends/backend_pgf.py | 42 +++++++----------------- lib/matplotlib/tests/test_backend_pgf.py | 37 --------------------- 2 files changed, 11 insertions(+), 68 deletions(-) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 6b0b64446124..03b816f0a3ba 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -30,11 +30,6 @@ ############################################################################### -_luatex_version_re = re.compile( - r'This is LuaTeX, Version (?:beta-)?([0-9]+)\.([0-9]+)\.([0-9]+)' -) - - @cbook.deprecated("3.0") def get_texcommand(): """Get chosen TeX system from rc.""" @@ -43,18 +38,6 @@ def get_texcommand(): return texsystem if texsystem in texsystem_options else "xelatex" -def _get_lualatex_version(): - """Get version of luatex""" - output = subprocess.check_output(['lualatex', '--version']) - return _parse_lualatex_version(output.decode()) - - -def _parse_lualatex_version(output): - '''parse the lualatex version from the output of `lualatex --version`''' - match = _luatex_version_re.match(output) - return tuple(map(int, match.groups())) - - def get_fontspec(): """Build fontspec preamble from rc.""" latex_fontspec = [] @@ -1171,26 +1154,23 @@ def savefig(self, figure=None, **kwargs): if self._n_figures == 0: self._write_header(width, height) else: - self._file.write(self._build_newpage_command(width, height)) + # \pdfpagewidth and \pdfpageheight exist on pdftex, xetex, and + # luatex<0.85; they were renamed to \pagewidth and \pageheight + # on luatex>=0.85. + self._file.write( + br'\newpage' + br'\ifdefined\pdfpagewidth\pdfpagewidth' + br'\else\pagewidth\fi=%ain' + br'\ifdefined\pdfpageheight\pdfpageheight' + br'\else\pageheight\fi=%ain' + b'%%\n' % (width, height) + ) figure.savefig(self._file, format="pgf", **kwargs) self._n_figures += 1 finally: figure.canvas = orig_canvas - def _build_newpage_command(self, width, height): - r'''LuaLaTeX from version 0.85 removed the `\pdf*` primitives, - so we need to check the lualatex version and use `\pagewidth` if - the version is 0.85 or newer - ''' - texcommand = rcParams["pgf.texsystem"] - if texcommand == 'lualatex' and _get_lualatex_version() >= (0, 85, 0): - cmd = r'\page' - else: - cmd = r'\pdfpage' - newpage = r'\newpage{cmd}width={w}in,{cmd}height={h}in%' + '\n' - return newpage.format(cmd=cmd, w=width, h=height).encode('utf-8') - def get_pagecount(self): """ Returns the current number of pages in the multipage pdf file. diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index 76949ad369e9..ed5e8c2bedfb 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -270,40 +270,3 @@ def test_pdf_pages_lualatex(): pdf.savefig(fig) assert pdf.get_pagecount() == 2 - - -@needs_lualatex -def test_luatex_version(): - from matplotlib.backends.backend_pgf import _parse_lualatex_version - from matplotlib.backends.backend_pgf import _get_lualatex_version - - v1 = '''This is LuaTeX, Version 1.0.4 (TeX Live 2017) - -Execute 'luatex --credits' for credits and version details. - -There is NO warranty. Redistribution of this software is covered by -the terms of the GNU General Public License, version 2 or (at your option) -any later version. For more information about these matters, see the file -named COPYING and the LuaTeX source. - -LuaTeX is Copyright 2017 Taco Hoekwater and the LuaTeX Team. -''' - - v2 = '''This is LuaTeX, Version beta-0.76.0-2015112019 (TeX Live 2013) (rev 4627) - -Execute 'luatex --credits' for credits and version details. - -There is NO warranty. Redistribution of this software is covered by -the terms of the GNU General Public License, version 2 or (at your option) -any later version. For more information about these matters, see the file -named COPYING and the LuaTeX source. - -Copyright 2013 Taco Hoekwater, the LuaTeX Team. -''' - - assert _parse_lualatex_version(v1) == (1, 0, 4) - assert _parse_lualatex_version(v2) == (0, 76, 0) - - # just test if it is successful - version = _get_lualatex_version() - assert len(version) == 3