René's URL Explorer Experiment


Title: [Bug]: usetex text drawn as paths (SVG, path effects) is narrower than its layout · Issue #32389 · matplotlib/matplotlib · GitHub

Open Graph Title: [Bug]: usetex text drawn as paths (SVG, path effects) is narrower than its layout · Issue #32389 · matplotlib/matplotlib

X Title: [Bug]: usetex text drawn as paths (SVG, path effects) is narrower than its layout · Issue #32389 · matplotlib/matplotlib

Description: Bug summary TextToPath.get_glyphs_tex always runs LaTeX at the fixed FONT_SCALE of 100 pt and ignores the size in prop. TeX fonts have a separate design for each size, so all usetex text drawn as paths (e.g., all SVG output, and text wit...

Open Graph Description: Bug summary TextToPath.get_glyphs_tex always runs LaTeX at the fixed FONT_SCALE of 100 pt and ignores the size in prop. TeX fonts have a separate design for each size, so all usetex text drawn as p...

X Description: Bug summary TextToPath.get_glyphs_tex always runs LaTeX at the fixed FONT_SCALE of 100 pt and ignores the size in prop. TeX fonts have a separate design for each size, so all usetex text drawn as p...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32389

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: usetex text drawn as paths (SVG, path effects) is narrower than its layout","articleBody":"### Bug summary\n\n`TextToPath.get_glyphs_tex` always runs LaTeX at the fixed `FONT_SCALE` of 100 pt and ignores the size in `prop`. TeX fonts have a separate design for each size, so all usetex text drawn as paths (e.g., all SVG output, and text with `path_effects` on any backend) uses the 17 pt design. At 6 to 12 pt the resulting text is 5-12% narrower than its layout and has lighter strokes. PNG and PDF output are correct.\n\n### Code for reproduction\n\n```Python\nimport re\n\nimport matplotlib as mpl\nimport matplotlib.patheffects as pe\nimport matplotlib.pyplot as plt\n\nmpl.rcParams[\"text.usetex\"] = True\ns = \"Hamburgefonstiv\"\n\n# The same 6 pt text saved as SVG and as PDF.\nfig = plt.figure(figsize=(2, 1))\nfig.text(0.1, 0.5, s, fontsize=6)\nfig.savefig(\"usetex.svg\")\nfig.savefig(\"usetex.pdf\")\nwith open(\"usetex.svg\", encoding=\"utf-8\") as f:\n    svg = f.read()\nwith open(\"usetex.pdf\", \"rb\") as f:\n    pdf = f.read()\nprint(\"SVG fonts:\", sorted(set(re.findall(r'id=\"(CM[A-Z]+\\d+)-', svg))))\nprint(\"PDF fonts:\", sorted({m.decode() for m in\n                            re.findall(rb\"/BaseFont\\s*/(?:[A-Z]{6}\\+)?(\\w+)\", pdf)}))\n\n# Right-aligned 8 pt text on Agg, without and with path effects.\nfig = plt.figure(figsize=(1.6, 0.5), dpi=600)\nfig.add_artist(plt.Line2D([0.93, 0.93], [0, 1], lw=0.3, color=\"tab:red\"))\nfig.text(0.93, 0.62, s, fontsize=8, ha=\"right\", va=\"center\")\nfig.text(0.93, 0.25, s, fontsize=8, ha=\"right\", va=\"center\",\n         path_effects=[pe.Normal()])\nfig.savefig(\"usetex_path_effects.png\")\n```\n\n### Actual outcome\n\n```text\nSVG fonts: ['CMSS17']\nPDF fonts: ['CMSS8']\n```\nThe same 6 pt text is drawn with the 17 pt design of Computer Modern Sans (CMSS17) in the SVG file, and with CMSS8, the smallest design, in the PDF file.\n\u003cimg width=\"960\" height=\"300\" alt=\"Two lines of usetex text, right-aligned on a red line; the lower line, with path effects, is narrower and ends short of the line\" src=\"https://github.com/user-attachments/assets/e89a46b5-8f54-41e2-a178-0028ab33c141\" />\n  - both lines are right-aligned on the red line, 8 pt\n  - the lower line has `path_effects=[pe.Normal()]`, so it is drawn through `get_glyphs_tex`.\n  - the lower line narrower is narrower and lighter, and it ends short of the red line\n\nThe table below compares the width matplotlib lays the text out with (`TexManager.get_text_width_height_descent`) with the ink width as drawn by `get_glyphs_tex`, and with the ink width when LaTeX runs at the text size.\n| Size | Layout width | Ink width, drawn (SVG, path effects)| Ink width, LaTeX at the text size |\n| ------- | ------- | ------- | ------- |\n| 6 pt | 44.87 pt | 39.56 pt | 44.76 pt |\n| 10 pt | 70.43 pt | 65.93 pt | 70.27 pt |\n| 24 pt | 158.55 pt | 158.22 pt | 158.22 pt |\n\nFor 17 pt and larger CMSS17 is the correct design, so larger text is not affected. The layout width includes the side bearings of the first and last glyph, so it is slightly larger than the ink width even when both use the same design. The bug is the difference between the two ink columns, which closes at 17 pt and above.\n\n### Expected outcome\n\nusetex text drawn as paths matches PNG and PDF output, with the design TeX selects for the text's size:\n\n- The SVG file uses CMSS8 for the 6 pt text, as the PDF file does.\nIn the image, the lower line matches the upper line and ends at the red line.\n- In the table, the drawn ink width equals the ink width with LaTeX at the text size, at every size.\n\n### Additional information\n\n### Likely root cause:\n`get_glyphs_tex` typesets the string with `TexManager().make_dvi(s, self.FONT_SCALE`), so LaTeX always runs at 100 pt, and its callers scale the result down to the text size. Everywhere else, LaTeX runs at the text's own size. *i.e.*, in the `draw_tex` methods of the PDF, PS, and PGF backends (`prop.get_size_in_points()`), in Agg through `dvipng`, and in the layout measurement (`TexManager.get_text_width_height_descent`). Because TeX selects a font design by size, only the paths through `get_glyphs_tex` draw with a different design from the one matplotlib measured.\n\n### Affected paths:\nThe SVG backend does not override `draw_tex`, so `RendererBase.draw_tex` draws all usetex text through `_draw_text_as_path` and `get_glyphs_tex`, for any `svg.fonttype. PathEffectRenderer` inherits the same `draw_tex`, so usetex text with path effects is affected on every backend, including Agg. `TextPath(..., usetex=True)` also calls `get_glyphs_tex`. The Cairo backend inherits `RendererBase.draw_tex` as well.\n\n### Possible fix\n```diff\n-        dvifile = TexManager().make_dvi(s, self.FONT_SCALE)\n+        size = prop.get_size_in_points()\n+        scale = self.FONT_SCALE / size\n+        dvifile = TexManager().make_dvi(s, size)\n ...\n-            xpositions.append(text.x)\n-            ypositions.append(text.y)\n-            sizes.append(text.font_size / self.FONT_SCALE)\n+            xpositions.append(text.x * scale)\n+            ypositions.append(text.y * scale)\n+            sizes.append(text.font_size / size)\n ...\n         for ox, oy, h, w in page.boxes:\n+            ox, oy, h, w = ox * scale, oy * scale, h * scale, w * scale\n```\n\nThis is a safe solution because glyph outlines are still loaded at `FONT_SCALE`, and glyph keys include the font name, so the shared `glyph_map` of the SVG backend keeps separate entries for CMSS8 and CMSS17 when a figure has mixed sizes. The LaTeX run is the one where the layout measurement is already cached, so the change adds no extra LaTeX runs.\n\nTested so far as a local patch on 3.11.2:\n\n#### Limitation for `TextPath`:\nThe fix takes the text size from `prop`, which is correct for the SVG backend and path effects, because they pass the font properties of the text. `TextPath` accepts its size separately and passes `prop` to `get_text_path` unchanged. So `TextPath((0, 0), s, size=12, usetex=True`) would run LaTeX at the default 10 pt in `prop` instead of at 12 pt. Passing a copy of `prop` with its size set to `size` in `TextPath.__init__` would fix that.\n\n### Context\nI maintain [curved-text](https://github.com/thiebes/curved-text), a package listed in the third-party registry that draws text along curves from `get_glyphs_tex` outlines. I found this while adding usetex support to it. For now it works around the bug by setting `FONT_SCALE` to the text size on its own `TextToPath` instance, which fixes curved-text but not matplotlib's own SVG and path-effects output. I would be glad to open a PR with the change above and a test, if this direction is acceptable.\n\n### AI disclosure\nI used an AI assistant (Claude) to trace the code paths, measure the widths, and test the patch. I ran the reproduction and the measurements myself and checked the results, and I reviewed the proposed change line by line.\n\n### Operating system\n\nWindows 11\n\n### Matplotlib Version\n\n3.11.2\n\n### Matplotlib Backend\n\nAgg (image), SVG and PDF via `savefig`\n\n### Python version\n\n3.13.3\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/thiebes","@type":"Person","name":"thiebes"},"datePublished":"2026-09-24T10:44:11Z","url":"https://github.com/matplotlib/matplotlib/issues/32389"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:cf5d4208-6f80-74d4-30c5-e38b8ad0eb59
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCD48:1759AA:D143C3:11D2D38:6B064EA0
html-safe-nonce37960b3df382f09b220a7470647f0db7ea51e21e7cef16341e2b0aa3de16329f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDQ4OjE3NTlBQTpEMTQzQzM6MTFEMkQzODo2QjA2NEVBMCIsInZpc2l0b3JfaWQiOiI3MDIwMTIxMTg1NjM5NjY2MjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacf22d0c70a4868e8a35915a6753c9fe82751f7e6df28136afc307d07c63b86176
hovercard-subject-tagissue:5567087203
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/32389/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b96c4764dbbbb747ff798e6f52c17275030658e39de21536719900f2ea23a0a5/matplotlib/matplotlib/issues/32389
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b96c4764dbbbb747ff798e6f52c17275030658e39de21536719900f2ea23a0a5/matplotlib/matplotlib/issues/32389
og:image:altBug summary TextToPath.get_glyphs_tex always runs LaTeX at the fixed FONT_SCALE of 100 pt and ignores the size in prop. TeX fonts have a separate design for each size, so all usetex text drawn as p...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamethiebes
hostnamegithub.com
expected-hostnamegithub.com
None772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef1f9a08f7c769a37f1dfc18ad43d463c222a7eea
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/32389#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F32389
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F32389
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/32389
Reloadhttps://github.com/matplotlib/matplotlib/issues/32389
Reloadhttps://github.com/matplotlib/matplotlib/issues/32389
matplotlibhttps://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Codehttps://github.com/matplotlib/matplotlib
Issues1k (1k)https://github.com/matplotlib/matplotlib/issues
Pull requests430 (430)https://github.com/matplotlib/matplotlib/pulls
Actionshttps://github.com/matplotlib/matplotlib/actions
Projectshttps://github.com/matplotlib/matplotlib/projects
Wikihttps://github.com/matplotlib/matplotlib/wiki
Security and qualityhttps://github.com/matplotlib/matplotlib/security
Insightshttps://github.com/matplotlib/matplotlib/insights
https://github.com/matplotlib/matplotlib
New issuehttps://github.com/login?return_to=https://github.com/matplotlib/matplotlib/issues/32389
New issuehttps://github.com/login?return_to=https://github.com/matplotlib/matplotlib/issues/32389
#32392https://github.com/matplotlib/matplotlib/pull/32392
[Bug]: usetex text drawn as paths (SVG, path effects) is narrower than its layouthttps://github.com/matplotlib/matplotlib/issues/32389#top
#32392https://github.com/matplotlib/matplotlib/pull/32392
first-contributionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22first-contribution%22
topic: text/usetexhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20text%2Fusetex%22
https://github.com/thiebes
thiebeshttps://github.com/thiebes
on Sep 24, 2026https://github.com/matplotlib/matplotlib/issues/32389#issue-5567087203
https://private-user-images.githubusercontent.com/8647427/657945855-e89a46b5-8f54-41e2-a178-0028ab33c141.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTU1NzU3NTYsIm5iZiI6MTc5NTU3NTQ1NiwicGF0aCI6Ii84NjQ3NDI3LzY1Nzk0NTg1NS1lODlhNDZiNS04ZjU0LTQxZTItYTE3OC0wMDI4YWIzM2MxNDEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MTEyNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjExMjVUMDI1NzM2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjE4Y2EyMGY4ZmRmOWI2ZjdiNjg1OThlYWJmNzEyMDE1MTNlNDJkMzRhNTM1ODE1OWE1OWM5MTZjMDY0ZWI5OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.EaWKqfC5SE416gGZaZ497AjWfrWkwsauwQGVJQvum4k
curved-texthttps://github.com/thiebes/curved-text
github-actionshttps://github.com/apps/github-actions
first-contributionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22first-contribution%22
on Sep 24, 2026https://github.com/matplotlib/matplotlib/issues/32389#event-31748774766
https://github.com/AishikDas500
AishikDas500https://github.com/AishikDas500
on Sep 24, 2026https://github.com/matplotlib/matplotlib/issues/32389#issuecomment-5815754999
melissawmhttps://github.com/melissawm
topic: text/usetexhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20text%2Fusetex%22
on Sep 24, 2026https://github.com/matplotlib/matplotlib/issues/32389#event-31782356188
https://github.com/thiebes
thiebeshttps://github.com/thiebes
on Sep 25, 2026https://github.com/matplotlib/matplotlib/issues/32389#issuecomment-5831394054
@AishikDas500https://github.com/AishikDas500
https://github.com/AishikDas500
AishikDas500https://github.com/AishikDas500
on Sep 25, 2026https://github.com/matplotlib/matplotlib/issues/32389#issuecomment-5831617267
@AishikDas500https://github.com/AishikDas500
https://github.com/krishsinghhura
krishsinghhurahttps://github.com/krishsinghhura
on Oct 10, 2026https://github.com/matplotlib/matplotlib/issues/32389#issuecomment-6096699093
@thiebeshttps://github.com/thiebes
@AishikDas500https://github.com/AishikDas500
#32392https://github.com/matplotlib/matplotlib/pull/32392
@thiebeshttps://github.com/thiebes
https://github.com/thiebes
thiebeshttps://github.com/thiebes
on Oct 11, 2026https://github.com/matplotlib/matplotlib/issues/32389#issuecomment-6110302538
@krishsinghhurahttps://github.com/krishsinghhura
https://github.com/krishsinghhura
krishsinghhurahttps://github.com/krishsinghhura
on Oct 11, 2026https://github.com/matplotlib/matplotlib/issues/32389#issuecomment-6113240273
@thiebeshttps://github.com/thiebes
#32392https://github.com/matplotlib/matplotlib/pull/32392
Sign up for freehttps://github.com/signup?return_to=https://github.com/matplotlib/matplotlib/issues/32389
Sign in to commenthttps://github.com/login?return_to=https://github.com/matplotlib/matplotlib/issues/32389
first-contributionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22first-contribution%22
topic: text/usetexhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20text%2Fusetex%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.