Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
The documentation mentions this behavior, but only as a passing note in the middle of the tutorial.
matplotlib/galleries/users_explain/text/usetex.py
Lines 87 to 94 inf94fce6
.. note:: | |
For consistency with the non-usetex case, Matplotlib special-cases newlines, | |
so that single-newlines yield linebreaks (rather than being interpreted as | |
whitespace in standard LaTeX). | |
Matplotlib uses the underscore_ package so that underscores (``_``) are | |
printed "as-is" in text mode (rather than causing an error as in standard | |
LaTeX). Underscores still introduce subscripts in math mode. |
When passing slightly complex latex code to matplotlib, a user might be tempted to use multi-line strings, and the error that matplotlib produces is quite cryptic. For example,
ax.annotate(text=r"""\begin{tabular}{cc} a & b \\ c & d \end{tabular}""",xy=(0.5,0.5),xycoords="figure fraction",xytext=(0,0))
produces
RuntimeError: latex was not able to process the following string: b'\\\\begin{tabular}{cc} '
I think it would be better to fix this behavior, but if not, it would be nice to give more visibility to it or include it in thetroubleshooting at the end of the same page, at least.