Skip to content

Fix glyphs for angle brackets #26518

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

Closed
wants to merge 2 commits into from
Closed

Fix glyphs for angle brackets #26518

wants to merge 2 commits into from

Conversation

devRD
Copy link
Contributor

@devRD devRD commented Aug 14, 2023

PR summary

Fixes #18740

Figure_1_cal

PR checklist

@devRD devRD marked this pull request as ready for review August 15, 2023 11:12
@QuLogic
Copy link
Member

QuLogic commented Aug 19, 2023

I'm not sure about the spacing of the result. The rightmost side of the left angle appears to be half as close as the leftmost side of the right angle. For the first three examples, it's about 1 vs 2 pixels, while about 2 vs 4 on the rightmost largest one.

If you take your test and call it with only <> or only \langle\rangle and revert the other changes, then the text between <> all appear centred (though of course the other version is broken as in #18740.) Something like:

@image_comparison(baseline_images=['math_angle_brackets.png']*2)
def test_math_angle_brackets():
    tests = [
        r'$\left< x \right>$',
        r'$\left< ? \right>$',
        r'$\left< \frac{1}{2}\right>$',
        r'$\left< \frac{\sum_{0}^{1}}{2}\right>$',
        r'$\left<\frac{\sum_{0}^{1}}{\sum_{0}^{1}}\right>$'
    ]
    for left, right in [('<', '>'), (r'\langle', r'\rangle')]:
        fig = plt.figure(figsize=(5, 1))
        for idx, text in enumerate(tests):
            fig.text((idx + 0.3)/len(tests), 0.5,
                     text.replace('<', left).replace('>', right),
                     math_fontfamily='cm')

@devRD
Copy link
Contributor Author

devRD commented Aug 21, 2023

I reverted the changes and tested the code again. The misalignment appears due to the missing sizing of the angle brackets, but reordering the sizing for the glyphs following this diff, generates the following image, which seems to be centered(?) with cm but a bit wonky with custom fonts

--- a/lib/matplotlib/_mathtext.py
+++ b/lib/matplotlib/_mathtext.py
@@ -419,10 +419,10 @@ class BakomaFonts(TruetypeFonts):
                         ('ex', '\xbb'), ('ex', '\x26')],
         r'\rceil':     [('ex', '\xa8'), ('ex', '\x6d'),
                         ('ex', '\xbc'), ('ex', '\x27')],
-        r'\langle':    [('ex', '\xad'), ('ex', '\x44'),
-                        ('ex', '\xbf')],
-        r'\rangle':    [('ex', '\xae'), ('ex', '\x45'),
-                        ('ex', '\xc0')],
+        r'\langle':    [('ex', '\xad'), ('ex', '\x2a'),
+                        ('ex', '\xbf'), ('ex', '\x44')],
+        r'\rangle':    [('ex', '\xae'), ('ex', '\x2b'),
+                        ('ex', '\xc0'), ('ex', '\x45')],
         r'\__sqrt__':  [('ex', '\x70'), ('ex', '\x71'),
                         ('ex', '\x72'), ('ex', '\x73')],
         r'\backslash': [('ex', '\xb2'), ('ex', '\x2f'),
@@ -433,6 +433,8 @@ class BakomaFonts(TruetypeFonts):
                         ('ex', '\x64')],
         r'\widetilde': [('rm', '\x7e'), ('ex', '\x65'), ('ex', '\x66'),
                         ('ex', '\x67')],
+        r'<':          [('ex', '\x44')],
+        r'>':          [('ex', '\x45')]
         }

Image for CM font:
math_angle_brackets

Image for Custom font:
math_angle_brackets

@QuLogic
Copy link
Member

QuLogic commented Apr 18, 2025

Sorry it's taken a while to get back to this PR. I don't believe it is the correct approach as the glyph order is correct at the moment.

The problem is really that the character code gets mapped twice. I've opened #29936 to correct this, which should replace this 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.

Incorrect glyphs selected for angle brackets
3 participants