Skip to content

Register the CJK font in util_rand_resp — five figures render Chinese as tofu - #274

Open
mmcky wants to merge 1 commit into
mainfrom
fix/util-rand-resp-cjk-font
Open

Register the CJK font in util_rand_resp — five figures render Chinese as tofu#274
mmcky wants to merge 1 commit into
mainfrom
fix/util-rand-resp-cjk-font

Conversation

@mmcky

@mmcky mmcky commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Fixes tofu on five figures in util_rand_resp, live on the site since publish-2026aug24b.

What is wrong

The lecture draws five figures whose labels, legends and annotations are Chinese — 真话边界, 诚实回答, 说谎, 等方差曲线, 最优设计 — but it is one of 36 lectures carrying no i18n font registration. matplotlib therefore falls back to DejaVu Sans, which has no CJK glyphs, and the characters render as boxes.

bin/check-tofu --site on the republished site reports it as the only affected page of 145:

util_rand_resp
    characters lost: 优回实差方曲最界真等答线计设诚话说谎边
    Glyph 20248 (\N{CJK UNIFIED IDEOGRAPH-4F18}) missing from font(s) DejaVu Sans

Why it appeared now, and why that is reassuring rather than alarming

The lecture text did not change. Comparing the two release tarballs directly: publish-2026aug24's util_rand_resp.html contains 0 occurrences of missing from font, and publish-2026aug24b's contains 19. Both render 7 images.

The difference is which execution produced the figures. The earlier release drew them from the 2026-08-17 cache artifact; that artifact's environment happened to resolve a CJK-capable face without the lecture asking for one. The 2026-08-24 cache run executed the lecture afresh and did not. So the defect was latent, not new — the lecture has been one environment change away from this for as long as it has had Chinese labels, and a re-execution finally exposed it.

This is worth stating plainly because it means the earlier "clean" check-tofu result was luck, not correctness.

The fix

The same block career.md uses, which publishes Chinese figures correctly. The DejaVu Sans fallback is retained deliberately: this lecture mixes Chinese labels with LaTeX math and Latin axis text (Pr(A|yes)), so a fallback is worth having.

Scope

Of the 36 lectures with no font registration, util_rand_resp is the only one with Chinese inside plotting calls. The other 35 are latent in the same way and would break identically the day a label is translated. Making the registration unconditional across the corpus — or emitting it from the engine — is the durable answer and is not attempted here.

This touches a code cell, so the lecture re-executes at the next build rather than coming from cache. That is one lecture's execution, not a full run.

🤖 Generated with Claude Code

The lecture draws five figures whose labels, legends and annotations are
Chinese — 真话边界, 诚实回答, 说谎, 等方差曲线, 最优设计 — but it is one of
36 lectures carrying no i18n font registration, so matplotlib falls back
to DejaVu Sans, which has no CJK glyphs.

This surfaced on publish-2026aug24b. The previous release rendered the
page from an execution cached on 2026-08-17 and showed no warning; the
2026-08-24 cache run executed it afresh and emitted 19 missing-glyph
warnings, losing 优回实差方曲最界真等答线计设诚话说谎边. The lecture text
never changed — only the environment it was executed in — so the tofu was
latent rather than new, and re-execution exposed it.

Use the same block as career.md, with the DejaVu fallback retained
because this lecture mixes Chinese labels with LaTeX math and Latin axis
text.

Of the 36 lectures with no font registration this is the only one with
Chinese inside plotting calls; the other 35 are latent and would break
the same way if labels were ever translated.

Refs #205

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 24, 2026 11:37
@netlify

netlify Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploy Preview for astonishing-narwhal-a8fc64 ready!

Name Link
🔨 Latest commit 6160d0c
🔍 Latest deploy log https://app.netlify.com/projects/astonishing-narwhal-a8fc64/deploys/6a8c2ce5b1814f0008768847
😎 Deploy Preview https://deploy-preview-274--astonishing-narwhal-a8fc64.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes missing Chinese glyphs (“tofu” boxes) in figures generated by the util_rand_resp lecture by registering the repository’s CJK font with Matplotlib and setting an appropriate font family fallback, aligning util_rand_resp with other lectures that already do this.

Changes:

  • Register fonts/SourceHanSerifSC-SemiBold.otf with Matplotlib’s font manager in util_rand_resp.
  • Set plt.rcParams['font.family'] to prefer Source Han Serif SC with a DejaVu Sans fallback to support mixed CJK + Latin/math text.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown

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