Skip to content

DOC: usetex and maths font - #11718

Closed
pharshalp wants to merge 1 commit into
matplotlib:masterfrom
pharshalp:use_tex_docs_update
Closed

pharshalp wants to merge 1 commit into
matplotlib:masterfrom
pharshalp:use_tex_docs_update

Conversation

@pharshalp

@pharshalp pharshalp commented Jul 21, 2018 •

Copy link
Copy Markdown
Contributor

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

ImportanceOfBeingErnest commented Jul 21, 2018 •

Copy link
Copy Markdown
Member

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

pharshalp commented Jul 21, 2018 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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