Skip to content

texts: keep fontweight on TeX labels, keep lone dollars literal, add Fonts and Labels example - #85

Merged
CSSFrancis merged 2 commits into
mainfrom
fix/texts-tex-weight-dollar
Oct 22, 2026
Merged

CSSFrancis merged 2 commits into
mainfrom
fix/texts-tex-weight-dollar

Conversation

@CSSFrancis

Copy link
Copy Markdown
Owner

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

  1. fontweight was lost on TeX labels. _drawMarkerText called _drawTex without weight, and _drawTex rebuilds ctx.font from opts.weight. So fontweight="bold" with "$\mathrm{Fe}_{K\alpha}$" drew in normal weight. It now passes weight: ms.fontweight.
  2. A single $ changed plain labels. Any $ sent a label to _drawTex, where _texRuns treats 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's cbook.is_math_text. Axis labels are unchanged; they always go through _drawTex.

Tests: test_bold_survives_tex_typesetting (1-D and 2-D) and test_odd_dollars_stay_literal ("$$$", "Cost $5"), as screenshot tests. All four fail on #83 and pass here; test_text_style.py passes 45/45.

Example

Examples/Markers/plot_fonts_and_labels.py, a Fonts and Labels gallery page with one figure per topic:

  • the panel's own title, axis labels and colorbar label with fontsize and TeX;
  • size and weight;
  • an outline (halo) over a busy image;
  • rotation in radians about the anchor;
  • a 3×3 grid of horizontal and vertical alignments, with the anchor points marked;
  • math in markers (sub/superscripts, Greek, \mathrm, bold TeX) next to a plain $5 label;
  • a live 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

_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-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.07%. Comparing base (01b6b12) to head (3ae27c7).
⚠️ Report is 26 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CSSFrancis
CSSFrancis merged commit 3dbe814 into main Oct 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants