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

Skip to content

Problem with Lualatex backend #11463

Closed
Closed
@cristobaltapia

Description

@cristobaltapia

Bug report

Changing the rcParams option pgf.texsystem to lualatex is not working in my installation (Ubuntu 18.04 with python 3.6 and latest version of matplotlib installed from pip).

Code for reproduction

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

mpl.use("pgf")
pgf_with_lualatex = {
    "text.usetex": True,
    "pgf.rcfonts": False,
    "pgf.texsystem": 'lualatex',
    "text.latex.preamble": [
        r"\usepackage{fontspec}",
        r"\setmainfont{Arial}",
    ],
}

mpl.rcParams.update(pgf_with_lualatex)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.linspace(0,10,10), marker='o')

fig.savefig('test.pdf')

Actual outcome

|| [python /home/tapiac/Dokumente/test_python.py]
|| Traceback (most recent call last):
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/texmanager.py", line 335, in _run_checked_subprocess
||     stderr=subprocess.STDOUT)
||   File "/home/tapiac/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 336, in check_output
||     **kwargs).stdout
||   File "/home/tapiac/.pyenv/versions/3.6.1/lib/python3.6/subprocess.py", line 418, in run
||     output=stdout, stderr=stderr)
|| subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', '/home/tapiac/.cache/matplotlib/tex.cache/2d2af434dea92760ceaac4d24cdcd139.tex']' returned non-zero exit status 1.
|| 
|| During handling of the above exception, another exception occurred:
|| 
|| Traceback (most recent call last):
||   File "/home/tapiac/Dokumente/test_python.py", line 25, in <module>
||     fig.savefig('test.pdf')
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/figure.py", line 2035, in savefig
||     self.canvas.print_figure(fname, **kwargs)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2263, in print_figure
||     **kwargs)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 2586, in print_pdf
||     self.figure.draw(renderer)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
||     return draw(artist, renderer, *args, **kwargs)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/figure.py", line 1475, in draw
||     renderer, self, artists, self.suppressComposite)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
||     a.draw(renderer)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
||     return draw(artist, renderer, *args, **kwargs)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2607, in draw
||     mimage._draw_list_compositing_images(renderer, self, artists)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
||     a.draw(renderer)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
||     return draw(artist, renderer, *args, **kwargs)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/axis.py", line 1192, in draw
||     renderer)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/axis.py", line 1130, in _get_tick_bboxes
||     extent = tick.label1.get_window_extent(renderer)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/text.py", line 922, in get_window_extent
||     bbox, info, descent = self._get_layout(self._renderer)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/text.py", line 300, in _get_layout
||     ismath=False)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 2148, in get_text_width_height_descent
||     renderer=self)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/texmanager.py", line 501, in get_text_width_height_descent
||     dvifile = self.make_dvi(tex, fontsize)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/texmanager.py", line 365, in make_dvi
||     texfile], tex)
||   File "/home/tapiac/.virtualenvs/py36/lib/python3.6/site-packages/matplotlib/texmanager.py", line 344, in _run_checked_subprocess
||     exc=exc.output.decode('utf-8')))
|| RuntimeError: latex was not able to process the following string:
|| b'lp'
|| 
|| Here is the full report generated by latex:
|| This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex)
||  restricted \write18 enabled.
|| entering extended mode
|| (/home/tapiac/.cache/matplotlib/tex.cache/2d2af434dea92760ceaac4d24cdcd139.tex
|| LaTeX2e <2017-04-15>
|| Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
|| (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
|| Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
|| (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
|| (/usr/share/texlive/texmf-dist/tex/latex/type1cm/type1cm.sty)
|| (/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty
|| (/usr/share/texlive/texmf-dist/tex/latex/base/ts1enc.def))
|| (/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
|| (/usr/share/texlive/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
|| (/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3.sty
|| (/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
|| (/usr/share/texlive/texmf-dist/tex/latex/l3kernel/l3dvips.def)))
|| 
|| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|| !
|| ! Fatal fontspec error: "cannot-use-pdftex"
|| ! 
|| ! The fontspec package requires either XeTeX or LuaTeX.
|| ! 
|| ! You must change your typesetting engine to, e.g., "xelatex" or
|| ! "lualatex"instead of "latex" or "pdflatex".
|| ! 
|| ! See the fontspec<!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda-->
<!--If you installed from conda, please specify which channel you used if not the default--> documentation for further information.
|| ! 
|| ! For immediate help type H <return>.
|| !...............................................  
||                                                   
|| l.44 \msg_fatal:nn {fontspec} {cannot-use-pdftex}
||                                                  
|| No pages of output.
|| Transcript written on 2d2af434dea92760ceaac4d24cdcd139.log.
|| 
|| 

Expected outcome

A pdf version of the plot generated with Lualatex.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.6

I installed python in a virtual environment and then installed matplotlib with pip.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions