Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Include underscore.sty #20706

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 9 commits into from
Jul 30, 2021
Merged

Include underscore.sty #20706

merged 9 commits into from
Jul 30, 2021

Conversation

kir0ul
Copy link
Contributor

@kir0ul kir0ul commented Jul 21, 2021

PR Summary

This PR closes #17774.
It includes the underscore.sty package in the LaTeX preamble to take care of underscores.
Most of the changes were proposed by @anntzer in #18357 (comment).

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@jklymak
Copy link
Member

jklymak commented Jul 21, 2021

Looks like you based this off an old version of master. Can you update?

@jklymak jklymak closed this Jul 21, 2021
@jklymak jklymak reopened this Jul 21, 2021
@jklymak
Copy link
Member

jklymak commented Jul 21, 2021

(ooops sorry for hitting the close button)

@jklymak
Copy link
Member

jklymak commented Jul 21, 2021

I'm not sure vendoring underscore.sty is a great solution, and I'm not sure what the consequences of including our vendored version in everyone's preamble are. Is there a reason we can't just suggest people install underscore.sty themselves, and include it in their preamble? Otherwise, I stand by my assertion this is a pandas problem.

kir0ul added 2 commits July 21, 2021 10:20
Include `underscore.sty` in the LaTeX preamble to take care of underscores
@anntzer
Copy link
Contributor

anntzer commented Jul 21, 2021

I don't have a super-strong opinion on this, but 1) note that text.latex.preamble is "officially unsupported" (because arbitrary packages can mess up with our tex setup in arbitrary ways), so we may need to change that to something like "officially unsupported, except for the following packages (underscore, etc.) which are known to work", and 2) it's not actually a pandas problem, per #17774 (comment).

@jklymak
Copy link
Member

jklymak commented Jul 21, 2021

Sure, you can reproduce w/o pandas, but it is pandas that is inserting this automatically and causing the headache. Presumably most folks who want to use LaTeX for anything know not to put underscores anywhere.

As for "officially unsupported" I'm not suggesting we start support mucking with the preamble, just that it is a viable workaround for people who have this problem. I'm not sure the alternative of forcing the use of underscore.sty doesn't have other un-intended consequences. I assume it is an optional style file for good reason.

@tacaswell
Copy link
Member

I am weakly in favor of this as it brings the allowed strings when using latex or not in sync. Because our internal mathtex engine only kicks in when in math mode (e.g. $XYZ$) and not for normal text which means that:

fig, ax0 = plt.subplots()
ax0.text(.5, .5, 'a\_b')
ax0.text(.5, .4, 'a\_b', usetex=True)
fig.savefig('/tmp/so.png')
plt.show()

so

renders significantly differently if you are using latex or not. On further consideration I think that my suggestion in #17774 (comment) is wrong and that we can not pre-process strings as we have no way of knowing what the usetex state will be when we actually get to render time.

I think the options here are :

  1. make underscore.sty a required latex dependency (pro: easy on us con: might be hard on the users)
  2. make underscore.sty an optional latex dependency (pro: easy on us, won't explode on users, con: leaves behavior silently dependent on installation of a latex package)
  3. vendor and inject underscore.sty as this PR is doing
  4. write a Python side function the at draw time in Text.draw to try and escape any _ not in math mode

I'm inclined to 3 or 4.


Pandas is not at fault here, they are just an abundant source of labels with _ in them that expose the underlying inconsistency in how text _ are handled by us vs LaTeX.

@kir0ul
Copy link
Contributor Author

kir0ul commented Jul 25, 2021

Refactored this PR according to what has been decided during the meeting.
Let me know if I missed anything 🙂

@timhoffm
Copy link
Member

There are two TeX-related test failures. Can you make sense of these?

@kir0ul
Copy link
Contributor Author

kir0ul commented Jul 27, 2021

Hum... not completely sure what's happening here since I can't reproduce the tests failing on my local machine...

However, having a closer look at the underscore package docs, they say:

Deficiencies
[...]
You must avoid “_” in file names and in cite or ref tags, or you must use the babel package,
with its active-character controls, or you must give the [strings] option, which attempts to
redefine several commands (and may not work perfectly). Even without the [strings] option
or babel, you can use occasional underscores like: “\include{file\string_name}”.

And since all the failing tests have an underscore in the file name like in the error below, I'd suspect this is the problem:

! Missing number, treated as zero.
<to be read again> 
                   \protect 
l.36 ...aphics*[angle=90]{/tmp/tmp_fyboc3t/tmp.ps}
                                                  
No pages of output.

@jklymak
Copy link
Member

jklymak commented Jul 27, 2021

Looks like you fixed it, except for a listing error ;-)

@anntzer
Copy link
Contributor

anntzer commented Jul 27, 2021

I think(?) the additional dependency needs an api_changes entry?

@QuLogic
Copy link
Member

QuLogic commented Jul 29, 2021

Yes, that would be preferred; it should go in the development section.

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@QuLogic QuLogic added this to the v3.5.0 milestone Jul 30, 2021
@QuLogic QuLogic merged commit 01fb7bb into matplotlib:master Jul 30, 2021
@QuLogic
Copy link
Member

QuLogic commented Jul 30, 2021

Thanks @kir0ul! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

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.

Cannot make Latex plots when Pandas dataframe has underscore in variable name
6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.