Skip to content

Don't bother checking luatex's version. #11228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 11 additions & 31 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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 = []
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 0 additions & 37 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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