Skip to content

DOC: usetex and maths font #11718

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

Closed
wants to merge 1 commit into from
Closed

DOC: usetex and maths font #11718

wants to merge 1 commit into from

Conversation

pharshalp
Copy link
Contributor

@pharshalp pharshalp commented Jul 21, 2018

PR Summary

Issues #11586, #8436, #6041, #3999.

The current documentation doesn't say that setting text.usetex = True doesn't set the correct maths font (applicable to mathematical symbols and the numbers in the tick labels).

Based on the answer given here https://stackoverflow.com/a/16345065 and here #6041 (by @mdboom) and as suggested by @jklymak in #11586, this is an attempt to fix the documentation at https://matplotlib.org/tutorials/text/usetex.html.

I am not sure about how the sphinx gallery works and where to add the png files.

usetex_maths_DejaVu-Sans.png
usetex_maths_dejavu-sans

usetex_maths_cmbright.png
usetex_maths_cmbright

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Jul 21, 2018

I found that the easiest option is to turn the use of tex off for the ScalarFormatter,

ax.xaxis.get_major_formatter()._usetex = False
ax.yaxis.get_major_formatter()._usetex = False

as I now also commented on the other issue. This will of course simply circumvent the problem of having to set the math mode font. But I think one of the most common problems is really related to the ticklabels.

@pharshalp
Copy link
Contributor Author

pharshalp commented Jul 21, 2018

but then the tick labels won't be rendered using TeX (and other mathematical symbols, numbers will still be using TeX when text.usetex=True) which is inconsistent. When the user sets text.usetex = True the expected result is that all the fonts will be rendered using TeX. Hence, it would be better to ask the user to control the font by using text.latex.preamble.

@ImportanceOfBeingErnest
Copy link
Member

The point is most often when using tex (usetex=True) you do not necessarly need any math symbols. You just want to make your plot look consistent. What hinders this currently is that the default ScalarFormatter formats the ticklabels as math tex (i.e. with $ around that). A solution to that is as easy as ax.xaxis.get_major_formatter()._usetex = False, which simply removes the $ from the ticks.

A versatile and general solution is of course the one that sets the math font of latex to a different one. This solution is presented in the pgf-system example and essentially this PR wants to use the same concept.

@pharshalp pharshalp closed this Sep 9, 2018
@pharshalp pharshalp deleted the use_tex_docs_update branch September 9, 2018 23:46
@pharshalp pharshalp restored the use_tex_docs_update branch September 9, 2018 23:46
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.

3 participants