8000 Don't insert spurious newlines by joining tex.preamble. by anntzer · Pull Request #12805 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 1 commit into from
Nov 19, 2018

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Nov 14, 2018

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

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

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.
@anntzer anntzer added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: text/usetex labels Nov 14, 2018
@anntzer anntzer added this to the v3.1 milestone Nov 14, 2018
@sxntxn
Copy link
Contributor
sxntxn commented Nov 14, 2018

Thanks! I forgot about that...

elif isinstance(s, Iterable):
return '\n'.join(s)
else:
raise TypeError
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@jklymak
Copy link
Member
jklymak commented Nov 19, 2018

There are no reasonable tests for this?

@anntzer
Copy link
Contributor Author
anntzer commented Nov 19, 2018

I'm sure some could be added, but note that text.latex.preamble is "officially not supported".

@jklymak jklymak merged commit 0f22259 into matplotlib:master Nov 19, 2018
@anntzer anntzer deleted the texpreamble branch November 19, 2018 16:54
bcbnz added a commit to bcbnz/matplotlib-pgfutils that referenced this pull request Mar 23, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: text/usetex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usetex produces preamble with one character per line
4 participants
0