Skip to content

[Bug]: \genfrac has bad spacing with (high) custom ruler #22172

Closed

Description

@oscargus

Bug summary

Using a high horizontal ruler overwrites denominator

Code for reproduction

import matplotlib.pyplot as plt
plt.text(0.5, 0.5, r'$\genfrac{}{}{10}{}{foo}{bar}$')
plt.draw()

Actual outcome

image

Expected outcome

This is from LaTeX rendering, but actually not that good either. It seems like the distance is also scaled with the height of the bar.

image

Additional information

Using

        vlist = Vlist([cnum,                      # numerator
                       Vbox(0, thickness * 2.0),  # space
                       Hrule(state, rule),        # rule
                       Vbox(0, thickness * 2.0 + 2 * rule),  # space
                       cden                       # denominator
                       ])

in _genfrac (that is, adding 2 * rule to the second spacer) gives

image

Which I guess it at least somewhat consistent and no overwrite. The question is if one can/want to do better?

I can include this is #22171 if it seems like a reasonable solution.

Operating system

Windows 10

Matplotlib Version

3.6.0.dev1270+g46d2a1e.d20220109

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.9.9

Jupyter version

No response

Installation

git checkout

Activity

  1. changed the title [-][Bug]: \genfrac has bad spacing[/-] [+][Bug]: \genfrac has bad spacing with (high) custom ruler[/+] on Jan 9, 2022
  2. tfpf commented on Jan 9, 2022

    @tfpf
    Contributor

    I recently created a PR (#20627) related to the alignment problem. (I don't think it fixes this issue, though, so it merits further analysis.) It went through a lot of trial and error, but I think I got the alignment to look reasonable (see #20627 (comment)).

    It seems like the distance is also scaled with the height of the bar.

    Yes, this is intentional. The space is a multiple of the height, as mentioned in the TeX book linked in #18389 (comment).

  3. oscargus commented on Jan 9, 2022

    @oscargus
    MemberAuthor

    Ah, OK! Looks like solid work! How does your PR behave with a larger rule? It didn't look like it scaled with rule in the code, but maybe that is handled some other way?

    Edit: I now noted that you shifted based on rule, so probably is OK then.

    But would be interesting to see the result with like rule=10.

  4. tfpf commented on Jan 9, 2022

    @tfpf
    Contributor

    I just took a look; that PR doesn't work with your example code! In theory, the fix should be simple …

    The clearance was being calculated using the thickness of a standard underline (that's the current behaviour, as well as the behaviour in the mentioned PR). All we need to do is use the thickness of the rule which is drawn.

    Here's the result with the said change.
    with-clearance-fix

    But what do we do if the rule is absent (i.e. is of zero thickness)? Things like \binom may break. (ETA This is covered in section 745 of the TeX book.)

    May need to dive into the TeX book again.

  5. github-actions commented on Nov 17, 2025

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

  6. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Dec 18, 2025
  7. added and removed
    status: inactiveMarked by the “Stale” Github Action
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Jan 28, 2026
  8. added this to the v3.11.0 milestone on Jan 28, 2026
  9. moved this from Waiting for other PR to In Progress in Font and text overhaulon Jan 28, 2026
  10. QuLogic commented on Apr 10, 2026

    @QuLogic
    Member

    The text-overhaul branch is now merged to main.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions