-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
boldsymbol support for mathtext #25661
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Boldsymbol mathtext command ``\boldsymbol`` | ||
------------------------------------------- | ||
|
||
Supports using the ``\boldsymbol{}`` command in mathtext: | ||
|
||
To change symbols to bold enclose the text in a font command as | ||
shown: | ||
|
||
.. code-block:: | ||
|
||
r'$\boldsymbol{a+2+\alpha}$' | ||
|
||
.. math:: | ||
\boldsymbol{a+2+\alpha} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import re | ||
import types | ||
import unicodedata | ||
import string | ||
|
||
import numpy as np | ||
from pyparsing import ( | ||
|
@@ -1811,6 +1812,11 @@ class _MathStyle(enum.Enum): | |
_right_delims = set(r") ] \} > \rfloor \rangle \rceil".split()) | ||
_delims = _left_delims | _right_delims | _ambi_delims | ||
|
||
_small_greek = set([unicodedata.name(chr(i)).split()[-1].lower() for i in | ||
range(ord('\N{GREEK SMALL LETTER ALPHA}'), | ||
ord('\N{GREEK SMALL LETTER OMEGA}') + 1)]) | ||
_latin_alphabets = set(string.ascii_letters) | ||
|
||
def __init__(self): | ||
p = types.SimpleNamespace() | ||
|
||
|
@@ -1933,6 +1939,9 @@ def csnames(group, names): | |
|
||
p.operatorname = cmd(r"\operatorname", "{" + ZeroOrMore(p.simple)("name") + "}") | ||
|
||
p.boldsymbol = cmd( | ||
r"\boldsymbol", "{" + ZeroOrMore(p.simple)("value") + "}") | ||
|
||
p.placeable <<= ( | ||
p.accent # Must be before symbol as all accents are symbols | ||
| p.symbol # Must be second to catch all named symbols and single | ||
|
@@ -1949,6 +1958,7 @@ def csnames(group, names): | |
| p.sqrt | ||
| p.overline | ||
| p.text | ||
| p.boldsymbol | ||
) | ||
|
||
p.auto_delim <<= ( | ||
|
@@ -2597,3 +2607,29 @@ def auto_delim(self, s, loc, toks): | |
# if "mid" in toks ... can be removed when requiring pyparsing 3. | ||
toks["mid"].asList() if "mid" in toks else [], | ||
toks["right"]) | ||
|
||
def boldsymbol(self, s, loc, toks): | ||
self.push_state() | ||
state = self.get_state() | ||
hlist = [] | ||
name = toks["value"] | ||
for c in name: | ||
if isinstance(c, Hlist): | ||
k = c.children[1] | ||
if isinstance(k, Char): | ||
k.font = "bf" | ||
k._update_metrics() | ||
hlist.append(c) | ||
elif isinstance(c, Char): | ||
c.font = "bf" | ||
if (c.c in self._latin_alphabets or | ||
c.c[1:] in self._small_greek): | ||
c.font = "bfit" | ||
c._update_metrics() | ||
c._update_metrics() | ||
hlist.append(c) | ||
else: | ||
hlist.append(c) | ||
self.pop_state() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't really check, but does that work with nesting? (i.e. I'm not actually sure what the semantics of boldsymbol are in TeX, but shouldn't it just be an alias for mathbfit? (and perhaps the test could be based on check_figures_equal too) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return Hlist(hlist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not fully get this warning, but I guess it must be fixed one way or the other. Maybe better to add a figure in the other PR, like
plt.text(...)
and then add the alternative version in that figure here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, I am getting these results from the current implementation. Should I add the
mathbfit
to the other PR, and theboldsymbol
to the current one?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is just missing a blank line.
(note also that the closing quote is missing anyway)