-
-
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
Conversation
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.
To change font to bold and italic enclose the text in a font command as | ||
shown: | ||
|
||
.. code-block:: |
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.
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.
.. code-block::
r'$\boldsymbol{a+2+\alpha}$'
(note also that the closing quote is missing anyway)
hlist.append(c) | ||
else: | ||
hlist.append(c) | ||
self.pop_state() |
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.
Didn't really check, but does that work with nesting? (i.e.\boldsymbol{\mathnormal{foo}}
-- the inner one should win)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
7371e42
to
1447b6d
Compare
The PR linked above has been merged, is this still waiting on anything? |
Hi @ksunden, This PR is not waiting, I opened it for review. Thanks! |
fig_test.text(0.1, 0.1, r"$\boldsymbol{abc0123\alpha}$") | ||
fig_test.text(0.1, 0.2, r"$\boldsymbol{\mathrm{abc0123\alpha}}$") | ||
|
||
fig_ref.text(0.1, 0.1, r"$\boldsymbol{abc0123\alpha}$") |
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 this should use \mathbfit, no?
I'm sorry for doing this review in a piecemeal fashion, but I think that we still don't know exactly what are the semantics of boldsymbol in tex and should thus figure this out exactly first. |
After exploring a bit on I generated this image for (some symbols weren't rendered properly, I'm guessing due to LaTeX package differences) This is the link that I used for reference. http://tug.ctan.org/tex-archive/macros/amstex/doc/amsguide.pdf |
lib/matplotlib/_mathtext.py
Outdated
.lower(), | ||
range(ord('\N{GREEK SMALL LETTER ALPHA}'), | ||
ord('\N{GREEK SMALL LETTER OMEGA}') + 1))) | ||
allLatin = [*lw, *up] |
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.
This is equal to string.ascii_letters
.
lib/matplotlib/_mathtext.py
Outdated
for c in name: | ||
if isinstance(c, Char): | ||
c.font = "bf" | ||
if str(c)[1] in allLatin or str(c)[2:-1] in smGreek: |
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.
str(c)[1:-1]
is equal to c.c
for Char
, I think?
if str(c)[1] in allLatin or str(c)[2:-1] in smGreek: | |
if c.c in string.ascii_letters or c.c[1:] in lower_greek: |
lib/matplotlib/_mathtext.py
Outdated
smGreek = list(map(lambda a: unicodedata.name(chr(a)) | ||
.split()[-1] | ||
.lower(), | ||
range(ord('\N{GREEK SMALL LETTER ALPHA}'), | ||
ord('\N{GREEK SMALL LETTER OMEGA}') + 1))) |
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.
Should rename for PEP8, and maybe also prefer list comprehensions
smGreek = list(map(lambda a: unicodedata.name(chr(a)) | |
.split()[-1] | |
.lower(), | |
range(ord('\N{GREEK SMALL LETTER ALPHA}'), | |
ord('\N{GREEK SMALL LETTER OMEGA}') + 1))) | |
lower_greek = [ | |
unicodedata.name(chr(a)).split()[-1].lower() | |
for a in range(ord('\N{GREEK SMALL LETTER ALPHA}'), | |
ord('\N{GREEK SMALL LETTER OMEGA}') + 1))] |
6e7850e
to
3ac9e61
Compare
Boldsymbol mathtext command ``\boldsymbol`` | ||
----------------------------------------------------- |
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.
Should match text length to underline.
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.
Trying the image test code out on normal LaTeX, it seems like the single + should not be bold?
OK! I guess my point really was that the + in Is it really different or is there just some pixel snapping issue in the test image that makes it look that way? |
Good catch! |
dd805ef
to
10a1ad7
Compare
lib/matplotlib/_mathtext.py
Outdated
if isinstance(c, Hlist): | ||
k = c.children[1] | ||
if isinstance(k, Char): | ||
k.font = "bf" | ||
k._update_metrics() | ||
if isinstance(c, Char): | ||
c.font = "bf" | ||
if c.c in latin_alphabets or c.c[1:] in small_greek: | ||
c.font = "bfit" | ||
c._update_metrics() | ||
c._update_metrics() | ||
hlist.append(c) | ||
else: | ||
hlist.append(c) |
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.
if isinstance(c, Hlist): | |
k = c.children[1] | |
if isinstance(k, Char): | |
k.font = "bf" | |
k._update_metrics() | |
if isinstance(c, Char): | |
c.font = "bf" | |
if c.c in latin_alphabets or c.c[1:] in small_greek: | |
c.font = "bfit" | |
c._update_metrics() | |
c._update_metrics() | |
hlist.append(c) | |
else: | |
hlist.append(c) | |
if isinstance(c, Hlist): | |
k = c.children[1] | |
if isinstance(k, Char): | |
k.font = "bf" | |
k._update_metrics() | |
elif isinstance(c, Char): | |
c.font = "bf" | |
if c.c in latin_alphabets or c.c[1:] in small_greek: | |
c.font = "bfit" | |
c._update_metrics() | |
c._update_metrics() | |
hlist.append(c) |
lib/matplotlib/_mathtext.py
Outdated
state = self.get_state() | ||
small_greek = [unicodedata.name(chr(i)).split()[-1].lower() for i in | ||
range(ord('\N{GREEK SMALL LETTER ALPHA}'), | ||
ord('\N{GREEK SMALL LETTER OMEGA}') + 1)] |
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.
Maybe one should move this to be a member of the parser class so that it is not recreated every time?
(And considering that it is only used for testing membership, make it a set
?)
Nice that you got it to work! Just some minor suggestions for clarity and performance. |
2cfd449
to
05a3261
Compare
PR Summary
Fixes #25643
Fixes #1366
Depends on PR #25359
Add boldsymbol command
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst