Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Accents positioning looks wrong #4561

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

Open
themiurgo opened this issue Jun 26, 2015 · 13 comments
Open

Accents positioning looks wrong #4561

themiurgo opened this issue Jun 26, 2015 · 13 comments
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/mathtext

Comments

@themiurgo
Copy link

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

@tacaswell
Copy link
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.

@tacaswell tacaswell added this to the proposed next point release milestone Jul 5, 2015
@tacaswell
Copy link
Member

Closing as this now looks correct in 1.5.1

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

@tacaswell tacaswell modified the milestones: 2.0 (style change major release), 2.1 (next point release) Feb 16, 2016
@tacaswell
Copy link
Member

I was looking at the docs which look ok both for 1.5.1 and current master

http://matplotlib.org/users/mathtext.html#accents
http://matplotlib.org/devdocs/users/mathtext.html#accents

but they do not hit 'f'

related to #5999

attn @zblz

@tacaswell tacaswell reopened this Feb 16, 2016
@themiurgo
Copy link
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, ...?).

@zblz
Copy link
Member

zblz commented Feb 16, 2016

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?

@QuLogic
Copy link
Member

QuLogic commented Feb 16, 2016

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.

@themiurgo
Copy link
Author

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

@efiring
Copy link
Member

efiring commented May 2, 2016

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

@zblz
Copy link
Member

zblz commented May 3, 2016

@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?

@mdboom
Copy link
Member

mdboom commented May 9, 2016

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?

@NelleV NelleV modified the milestones: 2.1 (next point release), 2.0 (style change major release) Nov 10, 2016
@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@anntzer
Copy link
Contributor

anntzer commented Aug 28, 2020

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.

@github-actions
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Mar 14, 2023
@anntzer anntzer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/mathtext
Projects
None yet
Development

No branches or pull requests

9 participants