Skip to content
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

What subset of LaTeX is rendered without 'usetex'? #14766

Open
llorracc opened this issue Jul 13, 2019 · 8 comments
Open

What subset of LaTeX is rendered without 'usetex'? #14766

llorracc opened this issue Jul 13, 2019 · 8 comments

Comments

@llorracc
Copy link

It would be great to have a description of the exact subset of LaTeX that is rendered by the default version of matplotlib (with usetex=False).

And it would also be useful to have an explicit statement about some commonly used packages that are NOT supported. In particular, many of the queries about LaTeX in matplotlib, both here and on stackexchange, reflect users' (incorrect) expectation that the American Mathematical Society packages are built in. Many scientific papers begin with

\usepackage{amsmath, amsthm, amssymb, amsfonts}

so that writers are not aware that tools that they use all the time are not actually part of the base distribution of LaTeX. (It would be great if a future release of matplotlib could include the functionality in these packages -- but I realize that is harder than it sounds because matplotlib's fast and compact built-in renderer is hand crafted).

Related issues: #14235, #1888, #12427, #7738, #1366, #9165

@jklymak
Copy link
Member

jklymak commented Jul 13, 2019

Where would you expect to see this info? A PR doing this would be great. OTOH I’m not sure making AMS packages a default is a good idea unless we really think the vast majority of folks who want Latex in their plots also want the AMS packages. There is an Rc entry to allow different packages to be loaded. So maybe an example that shows the use of the AMS packages?

@ImportanceOfBeingErnest
Copy link
Member

I'm not sure the AMS package(s) are included by default on any/all latex distributions. Meaning, if AMS is included in the default preamble it might break some/many existing scripts.

Surely, making the need to include AMS package(s) in the preamble in case certain commands are needed more transparent is desireable. Any PR in that direction would be helpful or sure.

I think the main burden is to inform people consistently about the difference between the inbuilt "MathText" and the external latex functionality and the difference between the two. Personally I would consider the docs to be quite clear about it, on the other hand, people who are just discovering those tools are probably more firm on spotting inconsistencies and hence possible improvements in the docs on that matter.

@anntzer
Copy link
Contributor

anntzer commented Jul 14, 2019

I think the list of supported commands is at https://matplotlib.org/tutorials/text/mathtext.html

@alexrudy
Copy link
Contributor

We talked at SciPy about adding some things from AMS to mathtext – what might be most useful here?

@llorracc
Copy link
Author

I posted this issue as a followup to a conversation with @alexrudy and other members of the matplotlib team at SciPy 2019. It turns out that some members of the team themselves have had to find personal kludges to get some of the missing AMS functionality.

The amsmath package is the second-most frequently used LaTeX package among the people participating in this tex.stackexchange thread, so it's not surprising that there are so many matplotlib related issues (above). (I suspect that amssymb, amsfont, and amsthm are almost always included when people use amsmath)

I think the maplotlib folks felt that it would be a no-brainer to include this functionality if it were easy. Turns out not to be at all easy, hence @alexrudy's query about what specific AMS functionality would be most valuable.

The thing I'd like most is \underline. It is a common notational convention to use $\underline{x}$ and $\overline{x}$ for the smallest and largest possible values of variable $x$ (\overline exists in the base distribution but \underline does not).

Other commonly used features are the \text command and various extra over and underline like commands like \varlimsup.

The one thing that team-mpl thought MIGHT be fairly easy was inclusion of a larger (or maybe complete) set of the symbols and other font items, for example the stuff in the amssymb package. One other thing that might be easy is the expanded set of predefined operators like \cot and \liminf.

Responses to other comments:

  • "There is an Rc entry to allow different packages to be loaded." That only works with usetex=True, which requires installation of the whole giant latex package -- which can a crippling requirement for example for a notebook on MyBinder.

@llorracc llorracc reopened this Jul 14, 2019
@llorracc
Copy link
Author

Sorry for closing -- am on a flight and turbulence bumped my finger. Continuing responses:

@ImportanceOfBeingErnest: "I'm not sure the AMS package(s) are included by default on any/all latex distributions. Meaning, if AMS is included in the default preamble it might break some/many existing scripts."

  • The ams packages are part of all of the "required" component of all the major distributions (TeXLive, MikTeX, etc)

@anntzer: "I think the list of supported commands is at https://matplotlib.org/tutorials/text/mathtext.html"

  • I interpreted that as an overview and tutorial rather than a complete census of everything supported

@oscargus
Copy link
Contributor

After a bit of digging (and thinking that all supported commands are actually listed), I've realized the following. The symbol lists are based on https://github.com/matplotlib/matplotlib/blob/main/doc/sphinxext/math_symbol_table.py

An obvious improvement would be to base parts of this list on the information already in the parser

_binary_operators = set(
'+ * - \N{MINUS SIGN}'
r'''
\pm \sqcap \rhd
\mp \sqcup \unlhd
\times \vee \unrhd
\div \wedge \oplus
\ast \setminus \ominus
\star \wr \otimes
\circ \diamond \oslash
\bullet \bigtriangleup \odot
\cdot \bigtriangledown \bigcirc
\cap \triangleleft \dagger
\cup \triangleright \ddagger
\uplus \lhd \amalg
\dotplus \dotminus'''.split())
_relation_symbols = set(r'''
= < > :
\leq \geq \equiv \models
\prec \succ \sim \perp
\preceq \succeq \simeq \mid
\ll \gg \asymp \parallel
\subset \supset \approx \bowtie
\subseteq \supseteq \cong \Join
\sqsubset \sqsupset \neq \smile
\sqsubseteq \sqsupseteq \doteq \frown
\in \ni \propto \vdash
\dashv \dots \doteqdot'''.split())
_arrow_symbols = set(r'''
\leftarrow \longleftarrow \uparrow
\Leftarrow \Longleftarrow \Uparrow
\rightarrow \longrightarrow \downarrow
\Rightarrow \Longrightarrow \Downarrow
\leftrightarrow \longleftrightarrow \updownarrow
\Leftrightarrow \Longleftrightarrow \Updownarrow
\mapsto \longmapsto \nearrow
\hookleftarrow \hookrightarrow \searrow
\leftharpoonup \rightharpoonup \swarrow
\leftharpoondown \rightharpoondown \nwarrow
\rightleftharpoons \leadsto'''.split())
_spaced_symbols = _binary_operators | _relation_symbols | _arrow_symbols
_punctuation_symbols = set(r', ; . ! \ldotp \cdotp'.split())
_overunder_symbols = set(r'''
\sum \prod \coprod \bigcap \bigcup \bigsqcup \bigvee
\bigwedge \bigodot \bigotimes \bigoplus \biguplus
'''.split())
_overunder_functions = set("lim liminf limsup sup max min".split())
_dropsub_symbols = set(r'''\int \oint'''.split())
_fontnames = set("rm cal it tt sf bf bfit "
"default bb frak scr regular".split())
_function_names = set("""
arccos csc ker min arcsin deg lg Pr arctan det lim sec arg dim
liminf sin cos exp limsup sinh cosh gcd ln sup cot hom log tan
coth inf max tanh""".split())
_ambi_delims = set(r"""
| \| / \backslash \uparrow \downarrow \updownarrow \Uparrow
\Downarrow \Updownarrow . \vert \Vert""".split())
_left_delims = set(r"( [ \{ < \lfloor \langle \lceil".split())
_right_delims = set(r") ] \} > \rfloor \rangle \rceil".split())
_delims = _left_delims | _right_delims | _ambi_delims

Also, just running math_symbol_table.py will print out which symbols are defined but not documented.

@llorracc
Copy link
Author

Glad to see this is reviving! Actually it dovetails with something I'm working on right now with @camriddell and @DrDrij and @MridulS. We're trying to build an as-compact-as-possible distribution of some software tools that include LaTeX, and it has been a real struggle to figure out what must be included, what should be included, and what can be included.

In one of my papers, for example, I use the character '\thorn' which is included in several LaTeX font bundles but in pacakages not in most base distributions. (It's an old Norse/Icelandic character that encapsulates the sound we make when we say words like "thunder" and "thor".) I'd dearly love to use this in an online MathJax compatible version of my paper, but the steps to figuring out how to make it work robustly across platforms and distributions are ... daunting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants