Skip to content

Correct position of the mathtext accent - #25210

Closed
saranti wants to merge 1 commit into
matplotlib:mainfrom
saranti:accent
Closed

saranti wants to merge 1 commit into
matplotlib:mainfrom
saranti:accent

Conversation

@saranti

@saranti saranti commented Feb 14, 2023

Copy link
Copy Markdown
Contributor

PR Summary

Fixes #23257. Apply #23257 (comment) to correct the positioning of the accent when mathtext is used in italics.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build 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 in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@oscargus

Copy link
Copy Markdown
Member

Thanks!

As the rendering will change, the result images must be updated as well.

If I recall correctly, and I may not, there are some edge cases where this actually will not work properly. Probably in the cases where the error is large (like 31 instead of 3-4). I think the current approach works if there is a single character for the hyphen, but not for multicharacter hyphens. So probably one should check that the length of the HList is 1?

Related is #23189 although that takes it a bit further to use a character with accent if available. And I realize that there are probably a similar issue there...

@oscargus

oscargus commented Feb 14, 2023 •

Copy link
Copy Markdown
Member

Edit: I looked at the wrong image the first time. Image 39 is indeed a multicharacter accent, so I guess what is said above was somewhat correct.

mathtext_dejavuserif_39

Comment on lines 2162 to +2164
centered = HCentered([Hbox(sym.width / 4.0), accent_box])
while isinstance(sym, Hlist):
sym = sym.children[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm probably wrong, but shouldn't line 2162 go below the two newly added lines? The way it currently is, sym is a Char in case of \dot s and an Hlist with kerning in case of \dot{s}, whereby centered will be different in those two cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good observation! I believe that as well. (Probably a bit clearer on the changed images.)

@saranti

saranti commented Feb 19, 2023

Copy link
Copy Markdown
Contributor Author

If I recall correctly, and I may not, there are some edge cases where this actually will not work properly. Probably in the cases where the error is large (like 31 instead of 3-4). I think the current approach works if there is a single character for the hyphen, but not for multicharacter hyphens.

Yes this also affects _wide_accents like widehat because it strips away all but the first index from the Hlist.

So probably one should check that the length of the HList is 1?

It doesn't seem this simple. The length of a Hlist is always more than 1 because it includes the char + the kerning amount. Therefore this fix would never have an affect on Hlists.

If we want to get the accents on Hlists and chars to line up, we might need to manipulate the amount of kerning that each character gets, which is something I don't yet know how to do. I'm open to suggestions 😺

@jklymak jklymak added status: needs clarification Issues that need more information to resolve. status: needs comment/discussion needs consensus on next step labels Feb 24, 2023
@saranti
saranti marked this pull request as draft March 5, 2023 14:54
@oscargus

Copy link
Copy Markdown
Member

Sorry for letting this slip. I guess I do not really know how to proceed...

I think the correct way is to check as is done now, just more "careful", to see if there is more than one character or not.

However, I also think that another solution, probably better in the long term, but more complicated, is to make sure that the additional kerning is not added for groups consisting of groups and so on (basically \"a and \"{{{{{{a}}}}}} should result in the same Hlist). I am not really sure why the kerning is added as part of the parsing the brackets (if I understand it correctly).

@saranti saranti closed this Mar 23, 2024
@saranti
saranti deleted the accent branch March 23, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs clarification Issues that need more information to resolve. status: needs comment/discussion needs consensus on next step topic: text/mathtext

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: mathtext not always rendering combining accents in the same way

4 participants