Skip to content

Navigation Menu

Sign in
Appearance settings

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

Commit 6cc144b

Browse filesBrowse files
committed
Tweak mathtext/tex docs.
- Fix typos/mismatched parentheses/markup in mathtext.py. - Make the title of pgf.py consistent with the title of usetex.py. - Prefer "modern" approach for setting fonts in usetex.py, but keep the old approach around (as the new API is only on Matplotlib 3.5). - Clarify non-standard tex settings.
1 parent 30db833 commit 6cc144b
Copy full SHA for 6cc144b

File tree

Expand file treeCollapse file tree

3 files changed

+48
-47
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+48
-47
lines changed

‎tutorials/text/mathtext.py

Copy file name to clipboardExpand all lines: tutorials/text/mathtext.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
its own TeX expression parser, layout engine, and fonts. The layout engine
1010
is a fairly direct adaptation of the layout algorithms in Donald Knuth's
1111
TeX, so the quality is quite good (Matplotlib also provides a ``usetex``
12-
option for those who do want to call out to TeX to generate their text (see
12+
option for those who do want to call out to TeX to generate their text; see
1313
:doc:`/tutorials/text/usetex`).
1414
1515
Any text element can use math text. You should use raw strings (precede the
1616
quotes with an ``'r'``), and surround the math text with dollar signs ($), as
1717
in TeX. Regular text and mathtext can be interleaved within the same string.
1818
Mathtext can use DejaVu Sans (default), DejaVu Serif, the Computer Modern fonts
19-
(from (La)TeX), `STIX <http://www.stixfonts.org/>`_ fonts (with are designed
19+
(from (La)TeX), `STIX <http://www.stixfonts.org/>`_ fonts (which are designed
2020
to blend well with Times), or a Unicode font that you provide. The mathtext
21-
font can be selected with the customization variable ``mathtext.fontset`` (see
21+
font can be selected via :rc:`mathtext.fontset` (see
2222
:doc:`/tutorials/introductory/customizing`)
2323
2424
Here is a simple example::

‎tutorials/text/pgf.py

Copy file name to clipboardExpand all lines: tutorials/text/pgf.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
r"""
2-
*********************************************************
3-
Typesetting with XeLaTeX/LuaLaTeX via the ``pgf`` backend
4-
*********************************************************
2+
************************************************************
3+
Text rendering with XeLaTeX/LuaLaTeX via the ``pgf`` backend
4+
************************************************************
55
66
Using the ``pgf`` backend, Matplotlib can export figures as pgf drawing
77
commands that can be processed with pdflatex, xelatex or lualatex. XeLaTeX and

‎tutorials/text/usetex.py

Copy file name to clipboardExpand all lines: tutorials/text/usetex.py
+42-41Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,7 @@
1919
itself (only LaTeX is supported). The executables for these external
2020
dependencies must all be located on your :envvar:`PATH`.
2121
22-
There are a couple of options to mention, which can be changed using
23-
:doc:`rc settings </tutorials/introductory/customizing>`. Here is an example
24-
matplotlibrc file::
25-
26-
font.family : serif
27-
font.serif : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman
28-
font.sans-serif : Helvetica, Avant Garde, Computer Modern Sans Serif
29-
font.cursive : Zapf Chancery
30-
font.monospace : Courier, Computer Modern Typewriter
31-
32-
text.usetex : true
33-
34-
The first valid font in each family is the one that will be loaded. If the
35-
fonts are not specified, the Computer Modern fonts are used by default. All of
36-
the other fonts are Adobe fonts. Times and Palatino each have their own
37-
accompanying math fonts, while the other Adobe serif fonts make use of the
38-
Computer Modern math fonts. See the PSNFSS_ documentation for more details.
39-
40-
To use LaTeX and select Helvetica as the default font, without editing
41-
matplotlibrc use::
42-
43-
import matplotlib.pyplot as plt
44-
plt.rcParams.update({
45-
"text.usetex": True,
46-
"font.family": "sans-serif",
47-
"font.sans-serif": ["Helvetica"]})
48-
# for Palatino and other serif fonts use:
49-
plt.rcParams.update({
50-
"text.usetex": True,
51-
"font.family": "serif",
52-
"font.serif": ["Palatino"],
53-
})
54-
# It's also possible to use the reduced notation by directly setting font.family:
55-
plt.rcParams.update({
56-
"text.usetex": True,
57-
"font.family": "Helvetica"
58-
})
59-
60-
Currently, the supported fonts are:
22+
Only a small number of fonts (defined by the PSNFSS_ scheme) are supported:
6123
6224
================= ============================================================
6325
family fonts
@@ -73,6 +35,34 @@
7335
``'monospace'`` ``'Courier'``, ``'Computer Modern Typewriter'``
7436
================= ============================================================
7537
38+
The default font is Computer Modern. All of the other fonts are Adobe fonts.
39+
Times and Palatino each have their own accompanying math fonts, while the other
40+
Adobe serif fonts make use of the Computer Modern math fonts.
41+
42+
To enable LaTeX and select a font, use e.g.::
43+
44+
plt.rcParams.update({
45+
"text.usetex": True,
46+
"font.family": "Helvetica"
47+
})
48+
49+
or equivalently, set your :doc:`matplotlibrc
50+
</tutorials/introductory/customizing>` to::
51+
52+
text.usetex : true
53+
font.family : Helvetica
54+
55+
It is also possible to instead set ``font.family`` to one of the generic family
56+
names and then configure the corresponding generic family; e.g.::
57+
58+
plt.rcParams.update({
59+
"text.usetex": True,
60+
"font.family": "sans-serif",
61+
"font.sans-serif": "Helvetica",
62+
})
63+
64+
(this was the required approach until Matplotlib 3.5).
65+
7666
Here is the standard example,
7767
:doc:`/gallery/text_labels_and_annotations/tex_demo`:
7868
@@ -86,13 +76,23 @@
8676
Non-ASCII characters (e.g. the degree sign in the y-label above) are supported
8777
to the extent that they are supported by inputenc_.
8878
79+
.. note::
80+
For consistency with the non-usetex case, Matplotlib special-cases newlines,
81+
so that single-newlines yield linebreaks (rather than being interpreted as
82+
whitespace in standard LaTeX).
83+
84+
Matplotlib uses the underscore_ package so that underscores (``_``) are
85+
printed "as-is" in text mode (rather than causing an error as in standard
86+
LaTeX). Underscores still introduce subscripts in math mode.
87+
8988
.. note::
9089
Certain characters require special escaping in TeX, such as::
9190
92-
# $ % & ~ _ ^ \ { } \( \) \[ \]
91+
# $ % & ~ ^ \ { } \( \) \[ \]
9392
9493
Therefore, these characters will behave differently depending on
95-
:rc:`text.usetex`.
94+
:rc:`text.usetex`. As noted above, underscores (``_``) do not require
95+
escaping outside of math mode.
9696
9797
PostScript options
9898
==================
@@ -164,5 +164,6 @@
164164
.. _Poppler: https://poppler.freedesktop.org/
165165
.. _PSNFSS: http://www.ctan.org/tex-archive/macros/latex/required/psnfss/psnfss2e.pdf
166166
.. _PSfrag: https://ctan.org/pkg/psfrag
167+
.. _underscore: https://ctan.org/pkg/underscore
167168
.. _Xpdf: http://www.xpdfreader.com/
168169
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.