matplotlib / matplotlib/matplotlib
Newlines should not be scaped when using setting usetex=True
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 23.2k
- Forks
- 8.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 66
Description
The documentation mentions this behavior, but only as a passing note in the middle of the tutorial.
https://github.com/matplotlib/matplotlib/blob/f94fce68abe66f29e3045d0d4f20ccd0effa6767/galleries/users_explain/text/usetex.py#L87-L94
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,
```python
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 the [troubleshooting](https://github.com/matplotlib/matplotlib/blob/f94fce68abe66f29e3045d0d4f20ccd0effa6767/lib/matplotlib/text.py#L1282-L1297) at the end of the same page, at least.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the multiline example with usetex=True, then read galleries/users_explain/text/usetex.py at the linked lines and the troubleshooting section in lib/matplotlib/text.py. Determine whether the issue is addressed by changing newline handling or by clarifying the documentation; done means the chosen behavior is documented or the example no longer produces the cryptic LaTeX error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- latex, python
- Domain
- data-visualization, documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100