Skip to content

Rendering fixes: math-punctuation, fonts, and a render regression test#1309

Merged
daira merged 6 commits into
zcash:mainfrom
daira:rendering-fixes
Jun 24, 2026
Merged

Rendering fixes: math-punctuation, fonts, and a render regression test#1309
daira merged 6 commits into
zcash:mainfrom
daira:rendering-fixes

Conversation

@daira

@daira daira commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

A batch of fixes to the ZIP rendering pipeline, plus a regression test so they don't silently break again.

Commits

  • Makefile: ensure that changing static files causes them to be re-copied.Makefile.uptodate now depends on the static files, so editing style.css etc. triggers a re-copy into rendered/ (previously a stale copy could be served).
  • Correct a CSS comment — the .katex .textit comment now describes what the rule actually does.
  • Update README.rst (ZIP 258 Discussions-To) — fills in ZIP 258's zips#1304 discussion link in the generated index (not captured when Add draft NU6.3 deployment and Version 6 Transaction Format ZIPs #1301 landed).
  • Fix the punctuation-after-math problem once and for allrender.sh rewrites trailing punctuation into the math span robustly: it matches whole $...$ spans, so the opening $ of a span whose content starts with punctuation (e.g. $-x$) is not corrupted; \textsf in math matches the body font (Roboto); and style.css now loads after the KaTeX CSS so our .katex .* overrides win the cascade. This let almost all the manual punctuation spacing / line-breaking hacks across ZIPs be removed.
  • style.css: fix Raleway-Italic weight for emphasis and pool names — declares the variable font's 100–900 weight range and pins emphasis (em and .katex .textit) to weight 500, so pool names render at a consistent weight in running text and in math, on Firefox and Chromium.
  • test: add a render.sh math/CSS regression test, run in CI — a golden-file test over one rst and one Markdown fixture, checking render.sh's post-sed intermediate output and the stylesheet load order. This is exposed via make test and wired into the Check Renderability workflow.

Filed with the assistance of Claude Opus 4.8 (1M context).

daira and others added 5 commits June 24, 2026 17:24
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
Rendered KaTeX output can linebreak between a math span and following
punctutation (KaTeX/KaTeX#1233). This is a very
common case in practice. There is also too large a gap between the math
and the punctuation.

We used to manually put the punctuation inside the math span as a hacky
workaround. This has several problems:

* it's easy to forget;
* it's terrible, presentation-oriented markup;
* the punctuation is in the wrong font (math instead of body).

A previous attempt at fixing this used `render.sh` to apply the hack
automatically. Until recently this was only done for rst;
7629f6a started doing it for Markdown
as well. However,

* this was fragile because it can break the markup syntax if the
  punctuation character is not followed immediately by whitespace or
  end-of-line (e.g. $t$-of-$n$, $k$-byte);
* the rewrite could potentially fire on the *opening* `$` of a span
  whose content starts with punctuation, rather than the closing one
  as intended;
* it still used the wrong font.

This commit cleans all of that up. `\textsf` in math now exactly matches
the body font (Roboto Regular). The rewrites are not applied when they
would break the markup, and more punctuation is handled correctly. This
allowed almost all manual applications of the hack to be removed. As a
bonus, instances of "and", "if", "otherwise", etc. in math now use
`\textsf` and are in the body font. The serif font can still be accessed
via `\text`.

Note that the rewriting is line-by-line, so a multi-line `$...$` span
(which is valid in Markdown) is not matched: punctuation immediately after
such a span won't get the spacing or linebreak correction. Also, a line
holding both one span's close and another's open can still mismatch. Both
cases are rare, surface when reviewing rendered output, and are easy to
work around.

Punctuation after a $$ span, e.g. `$${xyzzy}$$.`, will not be rewritten.
This can be replaced by `$${xyzzy}\textsf{.}$$`.

There were some intricacies in making sure that our intended font overrides
take precedence over the KaTeX fonts. Previously, `style.css` was loaded
after the KaTeX CSS for rst, and before for Markdown, resulting in confusing
differences between the two. We use the `!important` sledgehammer on the
overrides to make sure, but we also make the load order consistent
(`style.css` last) to ease future debugging.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
The `raleway` and `ralewayitalic` @font-face rules point at variable fonts
(`...VariableFont_wght.ttf`, wght axis 100–900, default 100) but declared a single
`font-weight: normal`. With only one weight declared, browsers disagree on which
axis instance to render — Firefox and Chromium differ — so `*Ironwood pool*` (which
uses `ralewayitalic`) rendered at different weights. The running-text `em` rule
requested `font-weight: 720`, which fell outside the single declared weight and so
was unreliable; and math-mode pool names (`.katex .textit`) pinned no weight at all,
so they did not match the running-text emphasis.

Declare the full `100–900` range on both @font-face rules, then pin emphasis to a
consistent medium weight: `em` and `.katex .textit` both use `font-weight: 500`.
Emphasis and pool names now render at the same weight in running text and in math,
and consistently on Firefox and Chromium.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
run: nix develop --profile /tmp/dev-profile --command make all-zips

- name: Render regression tests
run: nix develop --profile /tmp/dev-profile --command make test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a missing test target for the Makefile, or was this supposed to make rendered/test?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

make test is correct.

render.sh's math-punctuation rewriting and the stylesheet load order are subtle
and easy to regress. Add a golden-file test:

- test/render/test-render-{rst,md}.{rst,md}: one rst and one Markdown fixture
  (identical content bar extension + title syntax) covering trailing punctuation,
  hyphen/em-dash/close-paren after a span, the leading `$-x$` opening-delimiter
  case, mid-token non-matches, `\$` escaping, and a multi-line span left untouched.
- test/render/*.intermediate: the golden post-sed output for each.
- test/render-test.sh + `make test`: renders the fixtures via the Makefile
  (capturing render.sh's post-sed stream through the new RENDER_INTERMEDIATE hook),
  diffs against the goldens, and checks that style.css loads after the KaTeX CSS.

render.sh gains RENDER_INTERMEDIATE, defaulting to /dev/null so normal runs are
byte-for-byte unaffected. The Makefile gains rendered/test/%.html rules (with
css/ and assets/ symlinked so the pages are viewable in a browser) and a `test`
target. The Check Renderability workflow now runs `make test`.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
@daira daira force-pushed the rendering-fixes branch from 876affc to 2b33f26 Compare June 24, 2026 17:48

@ValarDragon ValarDragon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Punctuation around math-mode, removal of \small and \text -> \textsf changes LGTM

Didn't re-render anything myself, so utACK

@daira daira merged commit c087ae1 into zcash:main Jun 24, 2026
3 checks passed
@daira daira deleted the rendering-fixes branch June 24, 2026 18:52
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.

3 participants