Repository navigation
texts: keep fontweight on TeX labels, keep lone dollars literal, add Fonts and Labels example - #85
Merged
Merged
Conversation
_drawTex rebuilds ctx.font from opts.weight, so math labels dropped back
to normal weight. And any '$' sent a label to the TeX path, where a lone
dollar toggles math mode and vanishes ("Cost $5" lost its dollar).
Mirror matplotlib's is_math_text: typeset only an even, non-zero count of
unescaped dollars.
Assisted-by: claude-code:claude-opus-5-5
Assisted-by: claude-code:claude-opus-5-5
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #85 +/- ##
==========================================
+ Coverage 91.26% 92.07% +0.80%
==========================================
Files 41 42 +1
Lines 5004 5489 +485
==========================================
+ Hits 4567 5054 +487
+ Misses 437 435 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #83, stacked on it: this branch contains #83's commit plus two more. Merge #83 first and this diff shrinks to the follow-up commits, or merge this alone to land both.
Fixes
fontweightwas lost on TeX labels._drawMarkerTextcalled_drawTexwithoutweight, and_drawTexrebuildsctx.fontfromopts.weight. Sofontweight="bold"with"$\mathrm{Fe}_{K\alpha}$"drew in normal weight. It now passesweight: ms.fontweight.$changed plain labels. Any$sent a label to_drawTex, where_texRunstreats each unescaped$as switching math mode on or off. So"Cost $5"lost its dollar sign, and"$$$"drew nothing. Labels are now typeset only when they have an even, non-zero number of unescaped dollars, matching matplotlib'scbook.is_math_text. Axis labels are unchanged; they always go through_drawTex.Tests:
test_bold_survives_tex_typesetting(1-D and 2-D) andtest_odd_dollars_stay_literal("$$$","Cost $5"), as screenshot tests. All four fail on #83 and pass here;test_text_style.pypasses 45/45.Example
Examples/Markers/plot_fonts_and_labels.py, a Fonts and Labels gallery page with one figure per topic:fontsizeand TeX;\mathrm, bold TeX) next to a plain$5label;set(...)update.I rendered every figure in headless Chromium to check the layout. One limitation surfaced: the mini-TeX parser doesn't support TeX spacing commands.
\,draws a comma and\drops the space, so the example uses plain spaces.Assisted-by: claude-code:claude-opus-5-5