Skip to content

Conversation

tfpf
Copy link
Contributor

@tfpf tfpf commented Jun 6, 2022

This fixes #18085.

When an overunder symbol has a subscript, it goes below the symbol, and the baseline of the Vlist thus created is actually the baseline of the lowest item in the Vlist. Hence, it must be moved only if there is a subscript, and not otherwise.

PR Summary

MWE derived from the above-mentioned issue.

import matplotlib.pyplot as plt
(fig, ax) = plt.subplots()
ax.text(.01, .7, r"$\sum x\quad\sum^nx\quad\sum_nx\quad\sum_n^nx$", size=35); ax.axhline(.7)
ax.text(.01, .3, r"$\prod x\quad\prod^nx\quad\prod_nx\quad\prod_n^nx$", size=35); ax.axhline(.3)
plt.show()

Before:
Matplotlib_pull_before

After:
Matplotlib_pull_after

(Admittedly, the spacing could be much better. It is just right if there is no subscript and superscript, but not otherwise.)

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

When an overunder symbol has a subscript, it goes below the symbol, and the baseline of the Vlist thus created is actually the baseline of the lowest item in the Vlist. Hence, it must be moved only if there is a subscript, and not otherwise.
Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

It would be nice with some tests (primarily so that this isn't broken later), but I cannot really figure out a way to do that without adding yet another set of images (which should be avoided to reduce the git load). I think I'll open an issue an try to collect things to put in new tests.

@jklymak
Copy link
Member

jklymak commented Jun 6, 2022

I don't think we should be avoiding image tests where they are needed, like this PR.

@oscargus
Copy link
Member

oscargus commented Jun 6, 2022

I was quite sure that I recently saw a PR going in which some tests were removed, so I was about to give you some input on what else to add in the test, but I cannot seem to find it now...

I must admit that I do not really understand when test images should be added and not.

@jklymak
Copy link
Member

jklymak commented Jun 6, 2022

There are lots of things that can be tested with "figures_equal" or with hard coded value tests. Other things, however, really require a render to test. In this case I don't think there is anyway to test that the rendering is correct without an image test.

@tfpf
Copy link
Contributor Author

tfpf commented Jun 6, 2022

All right, I'll add a test here with \sum and \prod, perhaps similar to the MWE above. (Not very familiar with adding image comparison tests, but I can try.)

Should the test go in math_tests or lightweight_math_tests?

@timhoffm
Copy link
Member

timhoffm commented Jun 6, 2022

Not an expert here, but I think there should be no differences between fonts, so lightweight_math_tests is sufficient.

I hope this helps with writing the image comparison test:
https://matplotlib.org/stable/devel/testing.html#writing-an-image-comparison-test

@tfpf
Copy link
Contributor Author

tfpf commented Jun 9, 2022

I added the test. Is there anything else to be done?

@oscargus
Copy link
Member

oscargus commented Jun 9, 2022

should be no differences between fonts

You are correct in that it should not be any difference, but I think there is (at least based on other examples). However, I still think this is enough as things like spacing is not really what it could be. The PR solves the problem it claims to do, so I think it is good to go.

@timhoffm
Copy link
Member

timhoffm commented Jun 9, 2022

Hi-five ✋ on merging your first pull request to Matplotlib, @tfpf ! We hope you stick around and invite you to continue to take an active part in Matplotlib!

Your choices aren’t limited to programming 😉 – you can review pull requests, help us stay on top of new and old issues, develop educational material, refresh our documentation, work on our website, create marketing materials, translate website content, write grant proposals, and help with other fundraising initiatives. For more info, check out: https://matplotlib.org/stable/devel/index

f you haven’t yet, do join us on gitter and discourse 🗣. The former is a chat platform, which is great when you have any questions on process or how to fix something, the latter is a forum which is useful for longer questions and discussions.

Last but not least, we have a monthly meeting 👥 for new contributors and a weekly meeting for the maintainers, everyone is welcome to join both! You can find out more about our regular project meetings in this calendar page.

@timhoffm timhoffm added this to the v3.5.3 milestone Jun 9, 2022
@timhoffm timhoffm merged commit f278686 into matplotlib:main Jun 9, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 9, 2022
@timhoffm timhoffm added the PR: bugfix Pull requests that fix identified bugs label Jun 9, 2022
tacaswell added a commit that referenced this pull request Jun 9, 2022
…209-on-v3.5.x

Backport PR #23209 on branch v3.5.x (Fix the vertical alignment of overunder symbols.)
@tfpf
Copy link
Contributor Author

tfpf commented Jun 10, 2022

Thanks! Yep, will most certainly hang around!

@tfpf tfpf deleted the overunder-valign branch June 10, 2022 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bugfix Pull requests that fix identified bugs topic: text/mathtext
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vertical alignment of \sum depends on the presence of subscripts and superscripts
4 participants