Skip to content

Fix unicode_minus + usetex. #14567

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
Jun 19, 2019
Merged

Fix unicode_minus + usetex. #14567

merged 1 commit into from
Jun 19, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 18, 2019

... by telling TeX to treat \u2212 (unicode minus) as a minus sign.

This also uncovered a bug in _parse_enc (basically, there can be
multiple character entries per line, so one needs to use .split()
instead of .split("\n").

Closes #8423 (more accurately, #8423 (comment); the original version of the bug is already closed by #11381).

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

... by telling TeX to treat \u2212 (unicode minus) as a minus sign.

This also uncovered a bug in _parse_enc (basically, there can be
multiple character entries per line, so one needs to use `.split()`
instead of `.split("\n")`.
@dstansby dstansby added this to the v3.2.0 milestone Jun 18, 2019
@@ -989,7 +989,7 @@ def _parse_enc(path):
with open(path, encoding="ascii") as file:
no_comments = "\n".join(line.split("%")[0].rstrip() for line in file)
array = re.search(r"(?s)\[(.*)\]", no_comments).group(1)
lines = [line for line in array.split("\n") if line]
lines = [line for line in array.split() if line]
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the previous version was buggy: on an encoding file like http://tug.ctan.org/info/fontname/8r.enc, you can see there are multiple entries per line (/.notdef /dotaccent /...) and lines are starting with a space, so the previous parser would fail immediately below when asserting that all lines start with a /, and even without the assertion, would misparse the file.

@timhoffm timhoffm merged commit 63d96d2 into matplotlib:master Jun 19, 2019
@anntzer anntzer deleted the texminus branch June 19, 2019 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnicodeDecodeError when making a plot using the 'classic' style and text.usetex=True
3 participants