Issue rendering a latex formula

Dear all,

this is my first post here, but I’m not new to python neither to matplotlib, however today I found an issue that I’m not able to fix by myself.

The minimal example is:

import matplotlib
from matplotlib import pylab as plt

matplotlib.rc('text', usetex = True)
matplotlib.rc('font', **{'family' : "sans-serif"})
params= {'text.latex.preamble' : [r'\usepackage{amsmath}']}

formula = r"""\begin{equation}
        y = & +0.00000 \cdot 1  \\ 
            & -132.08690 \cdot x_0  \\ 
            & -8.49824 \cdot x_1  \\ 
            & +1.23479 \cdot x_0^2  \\ 
            & +5.34608 \cdot x_0 \cdot x_1  \\ 
            & -45.48402 \cdot x_1^2  \\ 
            & -0.00381 \cdot x_0^3  \\ 
            & -0.02472 \cdot x_0^2 \cdot x_1  \\ 
            & -0.05395 \cdot x_0 \cdot x_1^2  \\ 
            & +2.86417 \cdot x_1^3

figc, ax = plt.subplots(figsize=(12, 9), tight_layout=True)

If I try to execute the code it fails with the following error:

/usr/lib/python3.9/ MatplotlibDeprecationWarning: Support for setting the 'text.latex.preamble' or 'pgf.preamble' rcParam to a list of strings is deprecated since 3.3 and will be removed two minor releases later; set it to a single string instead.
  self[key] = other[key]
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 275, in _run_checked_subprocess
    report = subprocess.check_output(command,
  File "/usr/lib/python3.9/", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.9/", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', '/home/pietro/.cache/matplotlib/tex.cache/14e4c18300cd7f9c6f074f9a35f6827c.tex']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/pietro/src/synapsees/lab/", line 42, in <module>
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 2311, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/usr/lib/python3.9/site-packages/matplotlib/backends/", line 81, in print_figure
    super().print_figure(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 2210, in print_figure
    result = print_method(
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 1639, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/matplotlib/backends/", line 509, in print_png
  File "/usr/lib/python3.9/site-packages/matplotlib/backends/", line 407, in draw
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 1857, in draw
  File "/usr/lib/python3.9/site-packages/matplotlib/cbook/", line 411, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 2613, in tight_layout
    kwargs = get_tight_layout_figure(
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 303, in get_tight_layout_figure
    kwargs = auto_adjust_subplotpars(fig, renderer,
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 84, in auto_adjust_subplotpars
    bb += [ax.get_tightbbox(renderer, for_layout_only=True)]
  File "/usr/lib/python3.9/site-packages/matplotlib/axes/", line 4200, in get_tightbbox
    bbox = a.get_tightbbox(renderer)
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 278, in get_tightbbox
    bbox = self.get_window_extent(renderer)
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 902, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 295, in _get_layout
    w, h, d = renderer.get_text_width_height_descent(
  File "/usr/lib/python3.9/site-packages/matplotlib/backends/", line 227, in get_text_width_height_descent
    w, h, d = texmanager.get_text_width_height_descent(
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 423, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 309, in make_dvi
  File "/usr/lib/python3.9/site-packages/matplotlib/", line 283, in _run_checked_subprocess
    raise RuntimeError(
RuntimeError: latex was not able to process the following string:

Here is the full report generated by latex:
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/Arch Linux) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-12-03> xparse <2020-03-03>
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.

Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

) (/usr/share/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
No file 14e4c18300cd7f9c6f074f9a35f6827c.aux.
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Extra }, or forgotten $.
l.19 {\sffamily \begin{equation}}
No pages of output.

Note that if I compile the following latex document, it works without problems:



		y = & +0.00000 \cdot 1  \\ 
		& -132.08690 \cdot x_0  \\ 
		& -8.49824 \cdot x_1  \\ 
		& +1.23479 \cdot x_0^2  \\ 
		& +5.34608 \cdot x_0 \cdot x_1  \\ 
		& -45.48402 \cdot x_1^2  \\ 
		& -0.00381 \cdot x_0^3  \\ 
		& -0.02472 \cdot x_0^2 \cdot x_1  \\ 
		& -0.05395 \cdot x_0 \cdot x_1^2  \\ 
		& +2.86417 \cdot x_1^3


I’ve tried several combinations with r"", bytes, simple unicode, but I did not succed.
Any hint?