GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix glyphs for angle brackets by devRD · Pull Request #26518 · matplotlib/matplotlib

Conversation

@devRD

@devRD devRD commented Aug 14, 2023

Copy link
Copy Markdown
Contributor

PR summary

Fixes #18740

Figure_1_cal

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devRD devRD added the topic: text/mathtext label Aug 14, 2023
@devRD
devRD force-pushed the mt-angled branch from cb79aea to 90e4015 Compare August 14, 2023 19:03
@devRD
devRD marked this pull request as ready for review August 15, 2023 11:12
ksunden
ksunden approved these changes Aug 16, 2023
View reviewed changes
@QuLogic

QuLogic commented Aug 19, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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')
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devRD

devRD commented Aug 21, 2023

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devRD
devRD force-pushed the mt-angled branch from 135e3c1 to e8f11ac Compare August 22, 2023 10:10
devRD added 2 commits August 22, 2023 15:40
@devRD
Fix glyphs for angle brackets
23ef1e0
@devRD
Reorder glyph sizes for angular brackets
fc54666
@devRD
devRD force-pushed the mt-angled branch from e8f11ac to fc54666 Compare August 22, 2023 10:10
@QuLogic

QuLogic commented Apr 18, 2025

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic closed this Apr 18, 2025
@QuLogic QuLogic added the status: superseded label Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ksunden ksunden ksunden approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

status: superseded topic: text/mathtext

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Incorrect glyphs selected for angle brackets

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@devRD @QuLogic @ksunden
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.