Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28839b9

Browse files
committed
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.
1 parent 9ec4b95 commit 28839b9

File tree

2 files changed

+11
-68
lines changed

2 files changed

+11
-68
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
###############################################################################
3131

3232

33-
_luatex_version_re = re.compile(
34-
r'This is LuaTeX, Version (?:beta-)?([0-9]+)\.([0-9]+)\.([0-9]+)'
35-
)
36-
37-
3833
@cbook.deprecated("3.0")
3934
def get_texcommand():
4035
"""Get chosen TeX system from rc."""
@@ -43,18 +38,6 @@ def get_texcommand():
4338
return texsystem if texsystem in texsystem_options else "xelatex"
4439

4540

46-
def _get_lualatex_version():
47-
"""Get version of luatex"""
48-
output = subprocess.check_output(['lualatex', '--version'])
49-
return _parse_lualatex_version(output.decode())
50-
51-
52-
def _parse_lualatex_version(output):
53-
'''parse the lualatex version from the output of `lualatex --version`'''
54-
match = _luatex_version_re.match(output)
55-
return tuple(map(int, match.groups()))
56-
57-
5841
def get_fontspec():
5942
"""Build fontspec preamble from rc."""
6043
latex_fontspec = []
@@ -1171,26 +1154,23 @@ def savefig(self, figure=None, **kwargs):
11711154
if self._n_figures == 0:
11721155
self._write_header(width, height)
11731156
else:
1174-
self._file.write(self._build_newpage_command(width, height))
1157+
# \pdfpagewidth and \pdfpageheight exist on pdftex, xetex, and
1158+
# luatex<0.85; they were renamed to \pagewidth and \pageheight
1159+
# on luatex>=0.85.
1160+
self._file.write(
1161+
br'\newpage'
1162+
br'\ifdefined\pdfpagewidth\pdfpagewidth'
1163+
br'\else\pagewidth\fi=%ain'
1164+
br'\ifdefined\pdfpageheight\pdfpageheight'
1165+
br'\else\pageheight\fi=%ain'
1166+
b'%%\n' % (width, height)
1167+
)
11751168

11761169
figure.savefig(self._file, format="pgf", **kwargs)
11771170
self._n_figures += 1
11781171
finally:
11791172
figure.canvas = orig_canvas
11801173

1181-
def _build_newpage_command(self, width, height):
1182-
r'''LuaLaTeX from version 0.85 removed the `\pdf*` primitives,
1183-
so we need to check the lualatex version and use `\pagewidth` if
1184-
the version is 0.85 or newer
1185-
'''
1186-
texcommand = rcParams["pgf.texsystem"]
1187-
if texcommand == 'lualatex' and _get_lualatex_version() >= (0, 85, 0):
1188-
cmd = r'\page'
1189-
else:
1190-
cmd = r'\pdfpage'
1191-
newpage = r'\newpage{cmd}width={w}in,{cmd}height={h}in%' + '\n'
1192-
return newpage.format(cmd=cmd, w=width, h=height).encode('utf-8')
1193-
11941174
def get_pagecount(self):
11951175
"""
11961176
Returns the current number of pages in the multipage pdf file.

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -270,40 +270,3 @@ def test_pdf_pages_lualatex():
270270
pdf.savefig(fig)
271271

272272
assert pdf.get_pagecount() == 2
273-
274-
275-
@needs_lualatex
276-
def test_luatex_version():
277-
from matplotlib.backends.backend_pgf import _parse_lualatex_version
278-
from matplotlib.backends.backend_pgf import _get_lualatex_version
279-
280-
v1 = '''This is LuaTeX, Version 1.0.4 (TeX Live 2017)
281-
282-
Execute 'luatex --credits' for credits and version details.
283-
284-
There is NO warranty. Redistribution of this software is covered by
285-
the terms of the GNU General Public License, version 2 or (at your option)
286-
any later version. For more information about these matters, see the file
287-
named COPYING and the LuaTeX source.
288-
289-
LuaTeX is Copyright 2017 Taco Hoekwater and the LuaTeX Team.
290-
'''
291-
292-
v2 = '''This is LuaTeX, Version beta-0.76.0-2015112019 (TeX Live 2013) (rev 4627)
293-
294-
Execute 'luatex --credits' for credits and version details.
295-
296-
There is NO warranty. Redistribution of this software is covered by
297-
the terms of the GNU General Public License, version 2 or (at your option)
298-
any later version. For more information about these matters, see the file
299-
named COPYING and the LuaTeX source.
300-
301-
Copyright 2013 Taco Hoekwater, the LuaTeX Team.
302-
'''
303-
304-
assert _parse_lualatex_version(v1) == (1, 0, 4)
305-
assert _parse_lualatex_version(v2) == (0, 76, 0)
306-
307-
# just test if it is successful
308-
version = _get_lualatex_version()
309-
assert len(version) == 3

0 commit comments

Comments
 (0)