-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Don't insert spurious newlines by joining tex.preamble. #12805
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
The rc validator already makes it a single string. Also reject non-strings in the validator, as there isn't much use to them anyways in this context.
Thanks! I forgot about that... |
elif isinstance(s, Iterable): | ||
return '\n'.join(s) | ||
else: | ||
raise TypeError |
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.
The try-except seem unnecessary. Afaics, this can only come from the explicit raise and thus can be simplified.
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.
No, it can also happen if s is not an iterable of strings.
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.
Ok.
There are no reasonable tests for this? |
I'm sure some could be added, but note that text.latex.preamble is "officially not supported". |
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.
The rc validator already makes it a single string.
Also reject non-strings in the validator, as there isn't much use to
them anyways in this context.
Closes #12804, I think.
PR Summary
PR Checklist