Skip to content

Add overset and underset support for mathtext #18916

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

Merged
merged 3 commits into from
Jan 18, 2021

Conversation

aitikgupta
Copy link
Contributor

@aitikgupta aitikgupta commented Nov 8, 2020

PR Summary

This PR addresses #18241, adds \overset and its variant \underset LaTeX symbol, which looks like this:

  • Overset:
    mathtext_cm_83
  • Underset:
    mathtext_cm_84

Also see: http://tex.wikidot.com/snippets:overset-and-underset

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@aitikgupta
Copy link
Contributor Author

I followed the developer guide for image comparisons, ref, and I pass the tests locally.
Although, going through the result_images, I find there weren't any svg extensions generated for the test I appended - It only generated png and pdf extensions.
For all the previous baseline_images, there are svgs along with pngs and pdfs.

Is there something I missed, since previous PRs related to mathtext do have svgs in them? For example, #8151.

@aitikgupta
Copy link
Contributor Author

Hey @QuLogic, could you take a look at this too? Thanks :D

@aitikgupta
Copy link
Contributor Author

Removed the extra commits

@QuLogic QuLogic changed the title Add overset and underset suppport for mathtext Add overset and underset support for mathtext Dec 22, 2020
@timhoffm timhoffm requested a review from anntzer December 23, 2020 22:28
@timhoffm
Copy link
Member

Doc build failure seems due to #19163. @aitikgupta could you please rebase on master to pick up that change, so that docs build cleanly?

@anntzer I'd like to have your review as our "master of fonts" 😄. Feel free to turn the request down if you don't have time.

@dopplershift dopplershift added this to the v3.4.0 milestone Dec 24, 2020
@anntzer
Copy link
Contributor

anntzer commented Dec 24, 2020

I didn't really follow @QuLogic's discussion about alignments, but right now looking at

rcParams["text.latex.preamble"] = r"\usepackage{amsmath}"
s = r"$\overset{a}{a}\overset{p}{a}\overset{a}{b}\overset{p}{b}\underset{a}{a}\underset{b}{a}\underset{a}{p}\underset{b}{p}$"
figtext(.5, .6, s, usetex=True)
figtext(.5, .4, s)

we get
test
It looks like TeX's approach is to make sure the baselines of the main symbols stay always aligned (which seems more useful than trying to align the decorators?); likely we should do the same?

@aitikgupta
Copy link
Contributor Author

Looks like what @QuLogic said about underset being a bit lower than overset is in TeX backend too:

usetex=True

usetex=False

With the latest commit, alignment looks like this:

@anntzer
Copy link
Contributor

anntzer commented Dec 26, 2020

I would think it would be better if the p's baselines could also be aligned?

@aitikgupta
Copy link
Contributor Author

aitikgupta commented Dec 26, 2020

I would think it would be better if the p's baselines could also be aligned?

@anntzer Something like this?

@anntzer
Copy link
Contributor

anntzer commented Dec 26, 2020

Yes (unless someone wants to argue in favor of the previous behavior...).

@jklymak
Copy link
Member

jklymak commented Dec 26, 2020

But thT is still not the same?

@aitikgupta
Copy link
Contributor Author

aitikgupta commented Dec 26, 2020

But thT is still not the same?

@jklymak I'm not sure I understand, do you mean the baselines do not match? Maybe this will help:

@jklymak
Copy link
Member

jklymak commented Dec 26, 2020

The overset and underset baselines are not aligned

@timhoffm
Copy link
Member

They are not aligned in TeX either, but the spread here is a bit larger than in TeX. Personally, I don't find that too bad.

@aitikgupta
Copy link
Contributor Author

aitikgupta commented Dec 26, 2020

The spread is a bit larger even for a normal text:

We could reduce the gap in the final hlist theoretically, it will look something like this (have not pushed):

Just for reference, here is the current version (which is currently in the PR):

Should I update the PR to remove the gap?
@jklymak @timhoffm

@timhoffm
Copy link
Member

@aitikgupta I meant the spread of the baselines of the sub/supersets between a and p.
But you are right that the character spread is a bit larger too.

Personally I'm ok with both variants in both cases, but I'm not the most critical one here.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Great work, and thanks for your patience handling the reviews :) I'll give it a day in case anyone else wants to comment but other than that, anyone can merge.
(Also, you can consider adding a whatsnew entry.)

@anntzer
Copy link
Contributor

anntzer commented Dec 29, 2020

@timhoffm Given your comment at #19186 (comment), do you want to comment wrt. baseline images? (Everything else looks great to me.)

@timhoffm
Copy link
Member

timhoffm commented Dec 29, 2020

@anntzer TL;DR For the sake of simplicity, you can just merge with the new baseline images.

Here it's "only" a little over 40kB of baseline images and the positioning here is much more complex. I think this should be tested and adding the baseline images is okish. (The alternative would be splitting the tests into a separte PR and keep that open until we have less data heavy ways of doing the test - either with separated baseline images or by only using a subset; probably we don't need all combinations of fonts and output formats?).

Btw. what's the status with separating baseline images from the code repo?

@anntzer
Copy link
Contributor

anntzer commented Dec 29, 2020

I agree positioning matters here much more than for the sqrt PR (for which I agree we could do without the test images...).

Btw. what's the status with separating baseline images from the code repo?

Some day I'll have time to get back to it. But that day is not particularly close :(

@anntzer anntzer self-assigned this Dec 29, 2020
@anntzer
Copy link
Contributor

anntzer commented Dec 29, 2020

@aitikgupta Actually let's see whether we can resolve #19186 (comment) first to save a lot of disk space on the baseline images problem. However I don't want you to believe that I'm needlessly temporizing on this so regardless of whether the proposal at #19186 (comment) gets implemented I will make sure this is merged before 3.4 is released (hence the self-assignment).

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Actually #19201 turned out to quite simple to implement, so let's decide on that PR first.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

For whenever we figure out test images.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

@aitikgupta this needs to be rebased to use the new (cheaper) baseline images mechanism. (I can do the rebase if you prefer, just let me know.)

@aitikgupta
Copy link
Contributor Author

(I can do the rebase if you prefer, just let me know.)

No that's fine, I'll do it

@aitikgupta
Copy link
Contributor Author

I think just rebasing wouldn't work, I'd need to generate the baseline images too?

@anntzer
Copy link
Contributor

anntzer commented Jan 17, 2021

Yes, sorry I forgot to mention that.

@aitikgupta
Copy link
Contributor Author

Is it fine the way it is now?
Or should I consider breaking down the current test into 2 (one for overset, one for underset), since the tests only compare a single png now

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Let's still stick to a single test, it's also useful to be able to compare the alignment behaviors of over and underset easily.

@anntzer anntzer merged commit 19bd709 into matplotlib:master Jan 18, 2021
@anntzer
Copy link
Contributor

anntzer commented Jan 18, 2021

Thanks for the PR :)

@aitikgupta
Copy link
Contributor Author

Uh, while rebasing the last time to add the new baseline images, one of my commits vanished: the whatsnew entry.
It was this commit I suppose: 0a030d3

Now this is merged, but without the whatsnew entry.
Should we do something about it?
@anntzer @QuLogic

@anntzer
Copy link
Contributor

anntzer commented Feb 10, 2021

Open a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants