-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
\bf\it in mathtext #19393
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
Comments
I have some (no-guarantee) plans to fix that, but that'll likely wait after the deprecation in #18378 elapses (so 3.6 timeframe) as that'll likely require large amounts of surgery and maintaining backcompat on all the internals would be a lot of work... |
But that is how TeX works, right? |
The textbf / textit commands on the other hand can be nested. The point is to allow bold-italic which currently isn't possible in mathtext. |
Actually, looking at this again, we don't supply textbf/textit at all, but mathbf/mathit, which cannot be nested. The correct solution seems to be to provide |
Just doing some preliminary checkings for this... First, let's see what currently works. Because of the way things are currently implemented (font specs get stored as State.font and rm/bf/it get additionally stored as State.font_class), the only combos that can possibly work are one of rm/bf/it together with one of {none,tt,cal,sf,default,bb,frak,scr}. Let's look at all of them (in uppercase, as e.g. cal doesn't cover lowercase at all): We see that the only multicombos that currently work are it+bb, bf+bb, bf+frak, and, for stix only, bf+sf, it+sf. (A quick check with usetex=True and Looking at https://ctan.gutenberg.eu.org/fonts/stix/doc/stix.pdf, reasonable additional combos we may want to support are bfit, bfscr, bfsfit, bfbbit, and expand the support for bfsf, sfit for other fonts. https://ctan.gutenberg.eu.org/macros/unicodetex/latex/unicode-math/unicode-math.pdf further mentions bfcal, bfscr, bffrak, although I don't known if we actually have any fonts with such glyphs. I think the API here that maintains reasonable levels of compatibility with TeX is to actually stop making The implementation, for reference: from matplotlib import pyplot as plt
plt.rcParams["text.latex.preamble"] = r"\usepackage{amssymb}"
fig = plt.figure(figsize=(15, 8))
sfs = fig.subfigures(2, 3)
fontsets = ["dejavusans", "dejavuserif", "cm", "stixsans", "stix"]
styles = ["rm", "it", "bf"]
families = ["", "tt", "cal", "sf", "default", "bb", "frak", "scr"]
for sf, fs in zip(sfs.ravel(), fontsets):
sf.suptitle(fs, size=16)
for x, st in enumerate(styles):
for y, fm in enumerate(families[::-1]):
# Upper-case text as some fonts, e.g. cal, don't cover lowercase.
s = ("$\math%s{\math%s{%s+%s}}$" % (st, fm, st.upper(), fm.upper())
if fm else
"$\math%s{%s}$" % (st, st.upper()))
sf.text(
(x+.5)/len(styles), (y+.5)/(len(families)+1), s,
math_fontfamily=fs, size=16, ha="center")
plt.show() |
Here is a related issue that probably can be solved simultaneously (and is another twist of the same topic): #22056 |
Hi, getting bold italics on matplotlib would be interesting, if no one is working on this, I would like to take this issue. |
Uh oh!
There was an error while loading. Please reload this page.
Problem
\bf
and\it
are both supported in mathtext but if used together, only the inner style is applied.Proposed Solution
Apply both styles if both
\bf
and\it
are used together. Alternatively, a new\bfit
command could be introduced which enables text to be set in bold and italic.Additional context and prior art
This would be very useful when setting the experiment label in figures for the ATLAS experiment, which requires the name of the experiment in bold-italic followed by text describing the status of that figure in ordinary text. Additional text below this label communicates various experimental conditions that are often useful in interpreting the figure. In the absence of rich text functionality, mathtext (or
usetex
) is the only way to do this.I currently handle this in beojan/atlas-mpl by using
usetex
. However, this requires the user to have a full LaTeX installation available, along with the TeX Gyre fonts in that installation in order to meet the font family requirements of the experiment.@andrzejnovak handles the same issue in scikit-hep/mplhep by setting the various parts of the label separately, heuristically calculating the offsets needed. This is suboptimal compared to using the text layout algorithms built into the Matplotlib text engine.
The text was updated successfully, but these errors were encountered: