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

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
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 4 doc/api/next_api_changes/development/20706-AP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Improve underscore support in LaTeX
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `underscore <https://ctan.org/pkg/underscore>`_ package is now a requirement to improve support for underscores in LaTeX.
8 changes: 6 additions & 2 deletions 8 doc/devel/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,13 @@ Required:

* a minimal working LaTeX distribution
* `Graphviz <http://www.graphviz.org/download>`_
* the LaTeX packages *cm-super* and *dvipng* (if your OS bundles TeXLive, the
* the following LaTeX packages (if your OS bundles TeXLive, the
"complete" version of the installer, e.g. "texlive-full" or "texlive-all",
will often automatically include these packages)
will often automatically include these packages):

* `cm-super <https://ctan.org/pkg/cm-super>`_
* `dvipng <https://ctan.org/pkg/dvipng>`_
* `underscore <https://ctan.org/pkg/underscore>`_

Optional, but recommended:

Expand Down
18 changes: 16 additions & 2 deletions 18 lib/matplotlib/tests/test_usetex.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,22 @@ def test_usetex_packages(pkg):
text.get_window_extent())


def test_textcomp_full():
plt.rcParams["text.latex.preamble"] = r"\usepackage[full]{textcomp}"
@pytest.mark.parametrize(
"latex_statement",
[r"\usepackage[full]{textcomp}", r"\usepackage{underscore}"],
)
def test_latex_pkg_already_loaded(latex_statement):
plt.rcParams["text.latex.preamble"] = latex_statement
kir0ul marked this conversation as resolved.
Show resolved Hide resolved
fig = plt.figure()
fig.text(.5, .5, "hello, world", usetex=True)
fig.canvas.draw()


def test_usetex_with_underscore():
plt.rcParams["text.usetex"] = True
df = {"a_b": range(5)[::-1], "c": range(5)}
fig, ax = plt.subplots()
ax.plot("c", "a_b", data=df)
ax.legend()
ax.text(0, 0, "foo_bar", usetex=True)
plt.draw()
6 changes: 6 additions & 0 deletions 6 lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def _get_preamble(self):
# relies on a custom preamble to change the geometry.
r"\usepackage[papersize=72in, margin=1in]{geometry}",
self.get_custom_preamble(),
# Use `underscore` package to take care of underscores in text
# The [strings] option allows to use underscores in file names
r"\makeatletter"
r"\@ifpackageloaded{underscore}{}"
r"{\usepackage[strings]{underscore}}"
r"\makeatother",
# textcomp is loaded last (if not already loaded by the custom
# preamble) in order not to clash with custom packages (e.g.
# newtxtext) which load it with different options.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.