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

Skip to content

Commit 3496bd4

Browse files
committed
Support lualatex < 0.85
1 parent 66db38e commit 3496bd4

2 files changed

Lines changed: 64 additions & 10 deletions

File tree

lib/matplotlib/backends/backend_pgf.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,31 @@
5151
except:
5252
warnings.warn('error getting fonts from fc-list', UserWarning)
5353

54+
55+
luatex_version_re = re.compile(
56+
'This is LuaTeX, Version (?:beta-)?([0-9]+)\.([0-9]+)\.([0-9]+)'
57+
)
58+
59+
5460
def get_texcommand():
5561
"""Get chosen TeX system from rc."""
5662
texsystem_options = ["xelatex", "lualatex", "pdflatex"]
5763
texsystem = rcParams["pgf.texsystem"]
5864
return texsystem if texsystem in texsystem_options else "xelatex"
5965

6066

67+
def get_lualatex_version():
68+
"""Get version of luatex"""
69+
output = check_output(['lualatex', '--version'])
70+
return parse_lualatex_version(output.decode())
71+
72+
73+
def parse_lualatex_version(output):
74+
'''parse the lualatex version from the output of `lualatex --version`'''
75+
match = luatex_version_re.match(output)
76+
return tuple(map(int, match.groups()))
77+
78+
6179
def get_fontspec():
6280
"""Build fontspec preamble from rc."""
6381
latex_fontspec = []
@@ -1181,17 +1199,16 @@ def savefig(self, figure=None, **kwargs):
11811199
self._write_header(*figure.get_size_inches())
11821200
else:
11831201
if get_texcommand() == 'lualatex':
1184-
self._file.write(
1185-
r'\newpage\pagewidth={}in\pageheight={}in%'.format(
1186-
*figure.get_size_inches()
1187-
).encode('utf-8') + b'\n'
1188-
)
1202+
if get_lualatex_version() > (0, 85, 0):
1203+
np = r'\newpage\pagewidth={}in\pageheight={}in%'
1204+
else:
1205+
np = r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'
11891206
else:
1190-
self._file.write(
1191-
r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'.format(
1192-
*figure.get_size_inches()
1193-
).encode('utf-8') + b'\n'
1194-
)
1207+
np = r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'
1208+
self._file.write(np.format(
1209+
*figure.get_size_inches()
1210+
).encode('utf-8') + b'\n'
1211+
)
11951212
figure.savefig(self._file, format="pgf", **kwargs)
11961213
self._n_figures += 1
11971214
finally:

lib/matplotlib/tests/test_backend_pgf.py

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

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

0 commit comments

Comments
 (0)