-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow "real" LaTeX code for pgf.preamble in matplotlibrc #12674
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
Conversation
Please add an API changes note (as this could technically break rcParams that previously relied on breaking at commas). (But given that this makes possible something that was previously impossible, the change is clearly worth it.) |
attn @pwuertz |
In the documentation I used a string list as an example preamble. Didn't this already circumvent the problem matplotlib has/had with comma in strings? Or is this PR trying to enable single-string preambles?
|
Yes, from within Python scripts. Using the RC file, LaTeX code with commas in it never actually worked. |
Oh right, that's correct. +1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply the same change to text.latex.preamble (which suffers from the same issue). Also needs to be added in the whatsnew.
Also the description in matplotlibrc.template needs to be updated (right now it mentions splitting on commas explicitly).
Anyone can dismiss once handled.
You'll need to rebase on master too (https://matplotlib.org/devel/gitwash/development_workflow.html#rebasing-on-trunk). |
This allows to use the rc key "pgf.preamble" to contain "real" LaTeX code. As of before this patch, commas are used as parser separators, causing the PGF backend call to latex to fail, for example at loading packages which contain options such as: \usepackage[protrusion=true, expansion=false]{microtype} Passing a list of strings from within a Python script works fine, and with this patch it stays this way.
As per review by anntzer
As per review by anntzer
... to _validate_stringlist_or_string As per review by anntzer
As per review by tacaswell
Update documentation of text.latex.preamble. Add reference to text.latex.preamble for pgf.preamble.
Actually a copy of doc/api/next_api_changes/2018-10-30-rcparams-pgf.preamble-full-LaTeX-support.rst
... in order to also accept tuples as input, not only lists.
Let me know if that worked. |
The change applied in |
The current matplotlib.rcParams validator for the preamble splits the string on commas. The resulting list is subsequently re-joined with newlines, causing TeX to fail when the preamble contained commas (e.g., key-value configuration of a package). Two pull requests switching to a proper TeX validator have been accepted and should be included when matplotlib 3.1.0 is released: * matplotlib/matplotlib#12674 * matplotlib/matplotlib#12805 In the meantime, we can work around this by replacing the validator with a call to str.splitlines(). The workaround is implemented in a future-proof manner as it is only installed if the TeX validator could not be imported, i.e., as soon as it is used with a version of matplotlib containing the validator the workaround should be ignored. This also adds a couple of unit tests which use the preamble to set custom fonts. The font used is Cotham Sans, released under the SIL Open Font License 1.1.
Can we pass several usepackage commands in matplotlibrc file? Previously, it was possible by passing comma-separated \usepackage{package1}, \usepackage{package2} to text.latex.preamble option in matplotlibrc file. Now it appears that this is not possible anymore. I liked the opportunity to create the same-looking graphs using the same matplotlibrc across a project. But now it seems that I need to manually edit every script and include preamble there via rcParams. Is there still an option to use matplotlibrc for specifying preamble consisting of several lines? I probably just did not catch the idea. |
Just put everything in a single line: |
This allows to use the rc key "pgf.preamble" to contain "real" LaTeX code. As of before this patch, commas are used as parser separators, causing the PGF backend call to latex to fail, for example at loading packages which contain options such as:
\usepackage[protrusion=true, expansion=false]{microtype}
Passing a list of strings from within a Python script works fine, and with this patch it stays this way.
Any feedback would be appreciated.