Skip to content

Correctly read the 'style' argument while processing 'genfrac'. #23034

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 7 commits into from
Jun 16, 2022

Conversation

tfpf
Copy link
Contributor

@tfpf tfpf commented May 11, 2022

PR Summary

An attempt to fix #23008.

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).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@tfpf tfpf marked this pull request as ready for review May 12, 2022 08:40
@tfpf
Copy link
Contributor Author

tfpf commented May 12, 2022

Thought I'd try one more thing before IntEnum. Automatically converting the style code into an enum by making style_literal a separate function seems to be a better approach? (It solves the double conversion problem, too.)

@anntzer
Copy link
Contributor

anntzer commented May 12, 2022

Sure, that works too.

@tfpf
Copy link
Contributor Author

tfpf commented May 12, 2022

Some backend tests have failed—I don't suppose they are related to these changes? (I remember that they had passed after commit b7dee27.)

@anntzer
Copy link
Contributor

anntzer commented May 12, 2022

Indeed, these are irrelevant.
Probably this could use a test using check_figures_equal comparing genfrac and dfrac?

@tfpf
Copy link
Contributor Author

tfpf commented May 13, 2022

Yes, I could add a test for that. One point, though: \genfrac needs rulesize, which only accepts floating-point numbers, whereas \dfrac uses a rule size of self.get_state().get_current_underline_thickness(). Not sure how to proceed.

If I set the rule size to 1 (e.g. \genfrac{}{}{1}{0}{2x}{3y} compared with \dfrac{2x}{3y}), the test passes (it fails for 0 and 2). But that doesn't look like a good test?

@tfpf
Copy link
Contributor Author

tfpf commented May 20, 2022

One point, though: \genfrac needs rulesize, which only accepts floating-point numbers, whereas \dfrac uses a rule size of self.get_state().get_current_underline_thickness().

I am open to suggestions!

@anntzer
Copy link
Contributor

anntzer commented May 21, 2022

I agree this is a bit annoying :( Probably I would cheat a bit and, in the test, use

thickness = matplotlib._mathtext.TruetypeFonts.get_underline_thickness(None, None, fontsize=<whatever>, dpi=<whatever>)

and insert that value into the test genfrac.

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.

Minor nits, which don't prevent the approval IMO.

@tfpf tfpf force-pushed the genfrac-style branch from b9274e1 to 8e6c885 Compare May 27, 2022 16:31
@tfpf
Copy link
Contributor Author

tfpf commented May 27, 2022

Rebased on the current main branch, since a temporary fix for the failing macOS tests appears to be in place.

@tfpf tfpf marked this pull request as draft June 16, 2022 07:51
@tfpf
Copy link
Contributor Author

tfpf commented Jun 16, 2022

Fixed merge conflicts and rebased again. There are a couple of back-and-forth changes, so I will combine everything into a single commit.

The test failures are due to an unidentified image error. Not sure what went wrong.

@tfpf tfpf marked this pull request as ready for review June 16, 2022 11:05
@oscargus oscargus merged commit 4acd3be into matplotlib:main Jun 16, 2022
@oscargus
Copy link
Member

I squashed the commit. Thanks!

@tfpf tfpf deleted the genfrac-style branch June 16, 2022 15:43
oscargus pushed a commit to oscargus/matplotlib that referenced this pull request Jun 18, 2022
…lotlib#23034)

* Correctly read the 'style' argument while processing 'genfrac'.

* Default to text style if style not specified.

* Hard-coded enumerations. Support script_stype and script_script_style.

* Automatically convert style number to enumerated type.

* Used double quotes for strings.

* Verify that genfrac's displaystyle == dfrac.

* Use rcParams instead of rcParamsDefault in the test.

The test changes the DPI of the figure, but compares images after saving them, so rcParams['savefig.dpi'] is more appropriate.
@QuLogic QuLogic added this to the v3.6.0 milestone Jun 21, 2022
jklymak pushed a commit to jklymak/matplotlib that referenced this pull request Jun 24, 2022
…lotlib#23034)

* Correctly read the 'style' argument while processing 'genfrac'.

* Default to text style if style not specified.

* Hard-coded enumerations. Support script_stype and script_script_style.

* Automatically convert style number to enumerated type.

* Used double quotes for strings.

* Verify that genfrac's displaystyle == dfrac.

* Use rcParams instead of rcParamsDefault in the test.

The test changes the DPI of the figure, but compares images after saving them, so rcParams['savefig.dpi'] is more appropriate.
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.

[ENH]: Use \genfrac in display style?
4 participants