Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e05645c

Browse files
authored
Merge pull request #18938 from anntzer/usetexdoc
Edit usetex docs.
2 parents fa54783 + 0a3e303 commit e05645c

File tree

2 files changed

+35
-69
lines changed

2 files changed

+35
-69
lines changed

lib/matplotlib/texmanager.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@
55
66
Requirements:
77
8-
* latex
8+
* LaTeX
99
* \*Agg backends: dvipng>=1.6
10-
* PS backend: psfrag, dvips, and Ghostscript>=8.60
11-
12-
Backends:
13-
14-
* \*Agg
15-
* PS
16-
* PDF
10+
* PS backend: psfrag, dvips, and Ghostscript>=9.0
1711
1812
For raster output, you can get RGBA numpy arrays from TeX expressions
1913
as follows::
2014
2115
texmanager = TexManager()
22-
s = ('\TeX\ is Number '
23-
'$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!')
16+
s = "\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!"
2417
Z = texmanager.get_rgba(s, fontsize=12, dpi=80, rgb=(1, 0, 0))
2518
26-
To enable tex rendering of all text in your matplotlib figure, set
19+
To enable TeX rendering of all text in your Matplotlib figure, set
2720
:rc:`text.usetex` to True.
2821
"""
2922

tutorials/text/usetex.py

Lines changed: 31 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,17 @@
33
Text rendering With LaTeX
44
*************************
55
6-
Rendering text with LaTeX in Matplotlib.
7-
8-
Matplotlib has the option to use LaTeX to manage all text layout. This
9-
option is available with the following backends:
10-
11-
* Agg
12-
* PS
13-
* PDF
14-
15-
The LaTeX option is activated by setting ``text.usetex : True`` in your rc
16-
settings. Text handling with matplotlib's LaTeX support is slower than
17-
matplotlib's very capable :doc:`mathtext </tutorials/text/mathtext>`, but is
18-
more flexible, since different LaTeX packages (font packages, math packages,
6+
Matplotlib can use LaTeX to render text. This is activated by setting
7+
``text.usetex : True`` in your rcParams, or by setting the ``usetex`` property
8+
to True on individual `.Text` objects. Text handling through LaTeX is slower
9+
than Matplotlib's very capable :doc:`mathtext </tutorials/text/mathtext>`, but
10+
is more flexible, since different LaTeX packages (font packages, math packages,
1911
etc.) can be used. The results can be striking, especially when you take care
2012
to use the same fonts in your figures as in the main document.
2113
22-
Matplotlib's LaTeX support requires a working LaTeX_ installation, dvipng_
23-
(which may be included with your LaTeX installation), and Ghostscript_
24-
(GPL Ghostscript 9.0 or later is required). The executables for these
14+
Matplotlib's LaTeX support requires a working LaTeX_ installation. For the
15+
\*Agg backends, dvipng_ is additionally required; for the PS backend, psfrag_,
16+
dvips_ and Ghostscript_ are additionally required. The executables for these
2517
external dependencies must all be located on your :envvar:`PATH`.
2618
2719
There are a couple of options to mention, which can be changed using
@@ -30,7 +22,7 @@
3022
3123
font.family : serif
3224
font.serif : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman
33-
font.sans-serif : Helvetica, Avant Garde, Computer Modern Sans serif
25+
font.sans-serif : Helvetica, Avant Garde, Computer Modern Sans Serif
3426
font.cursive : Zapf Chancery
3527
font.monospace : Courier, Computer Modern Typewriter
3628
@@ -50,7 +42,7 @@
5042
"text.usetex": True,
5143
"font.family": "sans-serif",
5244
"font.sans-serif": ["Helvetica"]})
53-
## for Palatino and other serif fonts use:
45+
# for Palatino and other serif fonts use:
5446
plt.rcParams.update({
5547
"text.usetex": True,
5648
"font.family": "serif",
@@ -65,11 +57,12 @@
6557
:align: center
6658
:scale: 50
6759
68-
TeX Demo
69-
7060
Note that display math mode (``$$ e=mc^2 $$``) is not supported, but adding the
7161
command ``\displaystyle``, as in the above demo, will produce the same results.
7262
63+
Non-ASCII characters (e.g. the degree sign in the y-label above) are supported
64+
to the extent that they are supported by inputenc_.
65+
7366
.. note::
7467
Certain characters require special escaping in TeX, such as::
7568
@@ -78,40 +71,21 @@
7871
Therefore, these characters will behave differently depending on
7972
:rc:`text.usetex`.
8073
81-
.. _usetex-unicode:
82-
83-
usetex with unicode
84-
===================
85-
86-
It is also possible to use unicode strings with the LaTeX text manager, here is
87-
an example taken from :file:`/gallery/text_labels_and_annotations/tex_demo`.
88-
The axis labels include Unicode text:
89-
90-
.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png
91-
:target: ../../gallery/text_labels_and_annotations/tex_demo.html
92-
:align: center
93-
:scale: 50
94-
95-
TeX Unicode Demo
96-
97-
.. _usetex-postscript:
98-
99-
Postscript options
74+
PostScript options
10075
==================
10176
102-
In order to produce encapsulated postscript files that can be embedded in a new
103-
LaTeX document, the default behavior of matplotlib is to distill the output,
104-
which removes some postscript operators used by LaTeX that are illegal in an
105-
eps file. This step produces results which may be unacceptable to some users,
106-
because the text is coarsely rasterized and converted to bitmaps, which are not
107-
scalable like standard postscript, and the text is not searchable. One
108-
workaround is to set ``ps.distiller.res`` to a higher value (perhaps 6000)
77+
In order to produce encapsulated PostScript (EPS) files that can be embedded
78+
in a new LaTeX document, the default behavior of Matplotlib is to distill the
79+
output, which removes some PostScript operators used by LaTeX that are illegal
80+
in an EPS file. This step produces results which may be unacceptable to some
81+
users, because the text is coarsely rasterized and converted to bitmaps, which
82+
are not scalable like standard PostScript, and the text is not searchable. One
83+
workaround is to set :rc:`ps.distiller.res` to a higher value (perhaps 6000)
10984
in your rc settings, which will produce larger files but may look better and
110-
scale reasonably. A better workaround, which requires Poppler_ or Xpdf_, can be
111-
activated by changing the ``ps.usedistiller`` rc setting to ``xpdf``. This
112-
alternative produces postscript without rasterizing text, so it scales
113-
properly, can be edited in Adobe Illustrator, and searched text in pdf
114-
documents.
85+
scale reasonably. A better workaround, which requires Poppler_ or Xpdf_, can
86+
be activated by changing :rc:`ps.usedistiller` to ``xpdf``. This alternative
87+
produces PostScript without rasterizing text, so it scales properly, can be
88+
edited in Adobe Illustrator, and searched text in pdf documents.
11589
11690
.. _usetex-hangups:
11791
@@ -152,21 +126,20 @@
152126
that your LaTeX syntax is valid and that you are using raw strings
153127
if necessary to avoid unintended escape sequences.
154128
155-
* Most problems reported on the mailing list have been cleared up by
156-
upgrading Ghostscript_. If possible, please try upgrading to the
157-
latest release before reporting problems to the list.
158-
159-
* The ``text.latex.preamble`` rc setting is not officially supported. This
129+
* :rc:`text.latex.preamble` is not officially supported. This
160130
option provides lots of flexibility, and lots of ways to cause
161131
problems. Please disable this option before reporting problems to
162132
the mailing list.
163133
164134
* If you still need help, please see :ref:`reporting-problems`
165135
166-
.. _LaTeX: http://www.tug.org
167136
.. _dvipng: http://www.nongnu.org/dvipng/
137+
.. _dvips: https://tug.org/texinfohtml/dvips.html
168138
.. _Ghostscript: https://ghostscript.com/
169-
.. _PSNFSS: http://www.ctan.org/tex-archive/macros/latex/required/psnfss/psnfss2e.pdf
139+
.. _inputenc: https://ctan.org/pkg/inputenc
140+
.. _LaTeX: http://www.tug.org
170141
.. _Poppler: https://poppler.freedesktop.org/
142+
.. _PSNFSS: http://www.ctan.org/tex-archive/macros/latex/required/psnfss/psnfss2e.pdf
143+
.. _psfrag: https://ctan.org/pkg/psfrag
171144
.. _Xpdf: http://www.xpdfreader.com/
172145
"""

0 commit comments

Comments
 (0)