Title: Fix stale usetex text metrics when text.latex.preamble changes by himanchalkaushale · Pull Request #32473 · matplotlib/matplotlib · GitHub
Open Graph Title: Fix stale usetex text metrics when text.latex.preamble changes by himanchalkaushale · Pull Request #32473 · matplotlib/matplotlib
X Title: Fix stale usetex text metrics when text.latex.preamble changes by himanchalkaushale · Pull Request #32473 · matplotlib/matplotlib
Description: Closes #32413 Summary Fixes stale text metrics in usetex mode when text.latex.preamble changes. _get_text_metrics_with_cache caches the results of renderer.get_text_width_height_descent using the text, font properties, math mode, and DPI as cache keys. However, in usetex mode, the rendered dimensions also depend on text.latex.preamble, which was not included in the cache key. As a result, changing the preamble could leave existing Text objects with stale metrics. Since Matplotlib 3.10 moved the cache from individual Text objects to the renderer, newly created Text objects in the same figure could also reuse stale metrics. Creating a new figure avoided the issue because it created a new renderer with a fresh cache. This PR addresses the issue by including the LaTeX preamble in the cache key when ismath == "TeX". For non-TeX text, the preamble remains None, preserving the existing cache-key behavior. The change is intentionally limited to the preamble. Other TexManager configuration options, such as font settings, are left unchanged because they are outside the scope of this issue. Tests Adds a regression test that: Renders a string with usetex enabled. Changes the preamble to \usepackage{helvet}. Verifies that the existing Text object, a newly created Text object in the same figure, and a Text object in a new figure all report consistent text widths. The test is skipped when the required helvet LaTeX package is unavailable. The existing test_metrics_cache and test_metrics_cache2 assertions continue to pass. AI Disclosure AI assistance was used to draft the regression test cases. The implementation and final test changes were reviewed by me. PR Checklist Added a regression test for the reported issue. Verified the existing text metrics cache tests. [N/A] Plotting example required. [N/A] Release notes required. [N/A] Documentation changes required.
Open Graph Description: Closes #32413 Summary Fixes stale text metrics in usetex mode when text.latex.preamble changes. _get_text_metrics_with_cache caches the results of renderer.get_text_width_height_descent using the t...
X Description: Closes #32413 Summary Fixes stale text metrics in usetex mode when text.latex.preamble changes. _get_text_metrics_with_cache caches the results of renderer.get_text_width_height_descent using the t...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/32473
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:eef69ba1-cac4-9405-6e52-1465e4d20c6c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 91D2:3373A3:1F6487D:2954E5D:6B068EDD |
| html-safe-nonce | 1826e0cc72bfa17dcdb7214501719a51dc5026cf575672bb4742c52754e5f424 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUQyOjMzNzNBMzoxRjY0ODdEOjI5NTRFNUQ6NkIwNjhFREQiLCJ2aXNpdG9yX2lkIjoiMjY1MDc4NTgxMDM3NDYyNzAzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cd8008560fae655ab8c95151ce64e2bda128ab644dba2b31d49dd56fcfd30553 |
| hovercard-subject-tag | pull_request:4844997412 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/32473/files |
| twitter:image | https://avatars.githubusercontent.com/u/202173031?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/202173031?s=400&v=4 |
| og:image:alt | Closes #32413 Summary Fixes stale text metrics in usetex mode when text.latex.preamble changes. _get_text_metrics_with_cache caches the results of renderer.get_text_width_height_descent using the t... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4462ff7ebfd3d551f202659f2423dae617b6849d23b1df6465dc504ef497d14a |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6d3909414814ff86ce7da4c51a0f4918a13fb41b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width