Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ksunden merged 1 commit intomatplotlib:mainfromdevRD:boldsym
Jul 11, 2023
Merged

Conversation

devRD
Copy link
Contributor

@devRDdevRD commentedApr 11, 2023
edited
Loading

PR Summary

Fixes#25643
Fixes#1366
Depends on PR#25359
Add boldsymbol command

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (andpytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

Copy link
Member

@oscargusoscargus left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good! One may consider updating the what's new-note in#25359 in some way instead of having a separate one, but for now this is as good as it can be.

And maybe add something to the documentation, but will be easier once#25359 is in.

To change font to bold and italic enclose the text in a font command as
shown:

.. code-block::
Copy link
Member

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, likeplt.text(...) and then add the alternative version in that figure here?

Copy link
ContributorAuthor

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 themathbfit to the other PR, and theboldsymbol to the current one?

image

Copy link
Member

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()
Copy link
Contributor

@anntzeranntzerApr 20, 2023
edited
Loading

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)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thecheck_figures_equal test in the PR currently gives this output:
test_boldsymbol png

@devRDdevRDforce-pushed theboldsym branch 3 times, most recently from7371e42 to1447b6dCompareApril 21, 2023 16:11
@ksunden
Copy link
Member

The PR linked above has been merged, is this still waiting on anything?

@devRDdevRD marked this pull request as ready for reviewApril 26, 2023 04:20
@devRD
Copy link
ContributorAuthor

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}$")
Copy link
Contributor

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?

@anntzer
Copy link
Contributor

anntzer commentedMay 2, 2023
edited
Loading

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.
In particular, looking at this again, it seems like\boldsymbol{\mathrm{foo}} prints foo in bold roman (try with text.latex.preamble = "\usepackage{amsmath}" and usetex=True, which suggests to me that boldsymbol is in factnot synonym with mathbfit at all, but perhaps simply toggles the boldness of the font without touching italicness or anything else?

@devRD
Copy link
ContributorAuthor

After exploring a bit onboldsymbol, I agree that it slightly differs frommathbfit. From my limited understanding, I suppose the format differs in accordance with various symbols.
For e.g.:
Digits from0-9 are uprightbold
AlphabetsA-Za-z arebold+italic
Greek symbols like\alpha and\omega arebold+italic but...
symbols\Gamma and\Omega are just uprightbold.

I generated this image for\boldsymbol,\boldsymbol{\mathrm{foo}} and\mathbfit (in order) usingtext.preamble andtext.usetex=True

(some symbols weren't rendered properly, I'm guessing due to LaTeX package differences)
image

This is the link that I used for reference.http://tug.ctan.org/tex-archive/macros/amstex/doc/amsguide.pdf

.lower(),
range(ord('\N{GREEK SMALL LETTER ALPHA}'),
ord('\N{GREEK SMALL LETTER OMEGA}') + 1)))
allLatin = [*lw, *up]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is equal tostring.ascii_letters.

for c in name:
if isinstance(c, Char):
c.font = "bf"
if str(c)[1] in allLatin or str(c)[2:-1] in smGreek:
Copy link
Member

@QuLogicQuLogicJun 12, 2023
edited
Loading

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 toc.c forChar, I think?

Suggested change
ifstr(c)[1]inallLatinorstr(c)[2:-1]insmGreek:
ifc.cinstring.ascii_lettersorc.c[1:]inlower_greek:

Comment on lines 2612 to 2616
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)))
Copy link
Member

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

Suggested change
smGreek=list(map(lambdaa: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()
forainrange(ord('\N{GREEK SMALL LETTER ALPHA}'),
ord('\N{GREEK SMALL LETTER OMEGA}')+1))]

@devRDdevRDforce-pushed theboldsym branch 2 times, most recently from6e7850e to3ac9e61CompareJune 13, 2023 09:10
Comment on lines 1 to 2
Boldsymbol mathtext command ``\boldsymbol``
-----------------------------------------------------
Copy link
Member

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.

Copy link
Member

@oscargusoscargus left a 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?

@devRD
Copy link
ContributorAuthor

I checked the+ using an online LaTeX document and withtext.usetex=True. It looks like a bold+ when I compare it with\mathrm{+}. I got the following figure usingtext.usetex=True
Figure_1

@oscargus
Copy link
Member

OK! I guess my point really was that the + in\boldsymbol{\Gamma + \Omega} looks different compared to\boldsymbol{+}, but it seems like I draw the wrong conclusion about the reason.

Is it really different or is there just some pixel snapping issue in the test image that makes it look that way?

@devRD
Copy link
ContributorAuthor

devRD commentedJun 24, 2023
edited
Loading

Good catch!
Looking further into this, it is different. The\Gamma + \Omega seems to parse the+ in this context as anHlist and not an instance ofChar so thestate.font is not applying.

@devRDdevRDforce-pushed theboldsym branch 4 times, most recently fromdd805ef to10a1ad7CompareJune 26, 2023 08:44
Comment on lines 2640 to 2632
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
ifisinstance(c,Hlist):
k=c.children[1]
ifisinstance(k,Char):
k.font="bf"
k._update_metrics()
ifisinstance(c,Char):
c.font="bf"
ifc.cinlatin_alphabetsorc.c[1:]insmall_greek:
c.font="bfit"
c._update_metrics()
c._update_metrics()
hlist.append(c)
else:
hlist.append(c)
ifisinstance(c,Hlist):
k=c.children[1]
ifisinstance(k,Char):
k.font="bf"
k._update_metrics()
elifisinstance(c,Char):
c.font="bf"
ifc.cinlatin_alphabetsorc.c[1:]insmall_greek:
c.font="bfit"
c._update_metrics()
c._update_metrics()
hlist.append(c)

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)]
Copy link
Member

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 aset?)

@oscargus
Copy link
Member

Nice that you got it to work! Just some minor suggestions for clarity and performance.

devRD reacted with thumbs up emoji

@ksundenksunden merged commitfa68f46 intomatplotlib:mainJul 11, 2023
@ksundenksunden added this to thev3.8.0 milestoneJul 11, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@oscargusoscargusoscargus approved these changes

@QuLogicQuLogicQuLogic approved these changes

@ksundenksundenAwaiting requested review from ksunden

@anntzeranntzerAwaiting requested review from anntzer

Assignees
No one assigned
Projects
None yet
Milestone
v3.8.0
Development

Successfully merging this pull request may close these issues.

[ENH]: Support for\boldsymbol Support \boldsymbol. (Feature request.)
5 participants
@devRD@ksunden@anntzer@oscargus@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp