Skip to content

Accents positioning looks wrong #4561

Open

Description

@themiurgo

Accents seem positioned wrongly on top of letters.

This is already visible in the documentation, but it's perhaps more evident with some letters, like f, than with others.

How it looks:
screen shot 2015-06-26 at 12 45 48

how it should look:
screen shot 2015-06-26 at 12 44 19

Activity

  1. tacaswell commented on Jul 5, 2015

    @tacaswell
    Member

    attn @mdboom Is there anything we can do about this in the current text render? It looks like the accent is aligned with the left edge.

  2. added this to the milestone on Jul 5, 2015
  3. tacaswell commented on Feb 15, 2016

    @tacaswell
    Member

    Closing as this now looks correct in 1.5.1

  4. themiurgo commented on Feb 16, 2016

    @themiurgo
    Author

    Doesn't look correct on my machine, running 1.5.1. Could you try the following snippet it on your machine, too?

    example

    import matplotlib
    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    ax.set_xlabel(r'$\tilde{f}$', fontsize=24)
    ax.set_ylabel(r'$\tilde{y}$', fontsize=24)
    ax.set_title("matplotlib " + matplotlib.__version__)
    fig.tight_layout()
  5. modified the milestones: , on Feb 16, 2016
  6. themiurgo commented on Feb 16, 2016

    @themiurgo
    Author

    Also the tilde on the a is slightly away from the center, but this is especially visible on the f and the y (and perhaps some other characters too, w, ...?).

  7. zblz commented on Feb 16, 2016

    @zblz
    Member

    They look centered to me (and that is what I believe is done in the accent function in mathtext.py), but our eye is very good at correcting for tilt of the main letter. Maybe we could try a correction so that on tilted letter the accents are right-aligned?

  8. QuLogic commented on Feb 16, 2016

    @QuLogic
    Member

    Hmm, yes, I think this is probably the same as #5999. For reference, using a very simple LaTeX document:

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \begin{document}
    Text: \~f \~y
    
    \vspace*{1cm}
    
    Math: $\tilde{f} \tilde{y}$
    \end{document}

    the accents are shifted a bit to the right in math mode:
    screenshot from 2016-02-16 15-42-40
    It is definitely visible on the f and very slightly on the y.

  9. themiurgo commented on Feb 17, 2016

    @themiurgo
    Author

    It's exactly how @QuLogic describes it, in LaTeX the tilde doesn't look right-aligned, but definitely slightly shifted to the right.

  10. efiring commented on May 2, 2016

    @efiring
    Member

    @mdboom, @zblz, is there a problem currently? I don't want this to hold up 2.0.

  11. zblz commented on May 3, 2016

    @zblz
    Member

    @efiring: This has not been solved yet.

    I gave it a shot trying various combinations of right-aligned and introducing padding as a function of the letter height above x-height. However, I didn't manage to find a way that didn't also introduce problems in other letter that look good now. There must be a way, though, so I will try again at some point.

    In any case, I'm not sure whether this should hold 2.0. @mdboom?

  12. mdboom commented on May 9, 2016

    @mdboom
    Member

    This is just a shot in the dark: Some TTF fonts do have "Italic Angle" stored as metadata, which is accessible in our wrapper as the fifth element of get_ps_font_info(). Maybe that is useful?

  13. modified the milestones: , on Nov 10, 2016
  14. modified the milestones: , on Oct 3, 2017
  15. anntzer commented on Aug 28, 2020

    @anntzer
    Contributor

    Another example, which shows that the problem is not just about italic (in roman the accents seem too much to the right:

    from pylab import *
    figtext(.49, .7, r"$\mathrm{\ddot{e}\acute{e}\grave{e}\hat{e}\breve{e}\bar{e}\tilde{n}}$",
            ha="right", size=30)
    figtext(.51, .7, "ëéèêĕēñ", ha="left", size=30)
    figtext(.49, .5, r"$\mathsf{\ddot{e}\acute{e}\grave{e}\hat{e}\breve{e}\bar{e}\tilde{n}}$",
            ha="right", size=40, usetex=True)
    figtext(.51, .5, "ëéèêĕēñ", ha="left", size=40, usetex=True)
    figtext(.49, .3, "e" + chr(0x302), ha="right", size=30)
    figtext(.51, .3, chr(0xea), ha="left", size=30)
    show()

    test
    (top: mathtext, mid: usetex, bottom: checking that FreeType handles decomposed characters just fine)

    My guess is that a fix would be to run <accent> + <character> through unicodedata.normalize("NFC", ...) to get (if possible) a single precomposed character instead (https://en.wikipedia.org/wiki/Precomposed_character), when that character exists (both as unicode and as a glyph in the font). Or alternatively apparently FreeType is able to compose the characters itself (per the last line), not sure if we can use that.

    Edit: although that may not work for Computer Modern fonts (which is the OP's case) which has no such combining charachers. I think the long-term solution is to switch to a more modern version of it, which likely means http://www.gust.org.pl/projects/e-foundry/lm-math. In the short term, if one does want to add a code path just for Bakoma (well, for TeX fonts, really), the algorithm is at http://cahiers.gutenberg.eu.org/cg-bin/article/CG_1998___28-29_44_0.pdf; we can either hardcode fontdimen1 (slant) or also extend the Tfm parser already in dviread (see http://www.tug.org/TUGboat/Articles/tb02-1/tb02fuchstfm.pdf) and ship cmmi.tfm; or just extract the fontdimens once and hard-code them.

  16. github-actions commented on Mar 14, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  17. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Actiontopic: text/mathtext

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions