Register the CJK font in util_rand_resp — five figures render Chinese as tofu - #274
Open
mmcky wants to merge 1 commit into
Open
Register the CJK font in util_rand_resp — five figures render Chinese as tofu#274mmcky wants to merge 1 commit into
mmcky wants to merge 1 commit into
Conversation
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>
✅ Deploy Preview for astonishing-narwhal-a8fc64 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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.otfwith Matplotlib’s font manager inutil_rand_resp. - Set
plt.rcParams['font.family']to preferSource Han Serif SCwith aDejaVu Sansfallback 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.
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.
Fixes tofu on five figures in
util_rand_resp, live on the site sincepublish-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 --siteon the republished site reports it as the only affected page of 145: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'sutil_rand_resp.htmlcontains 0 occurrences ofmissing from font, andpublish-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-tofuresult was luck, not correctness.The fix
The same block
career.mduses, which publishes Chinese figures correctly. TheDejaVu Sansfallback 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_respis 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