Skip to content

engine: \selectfont brings the font back, and \voidb@x exists - #6

Merged
tannevaled merged 1 commit into
mainfrom
fix/node-text
Aug 17, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix/node-text

Conversation

@tannevaled

@tannevaled tannevaled commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

A TikZ node's text typesets and positions correctly.

The cause

\selectfont installs the font that the current family, weight and shape call for. The engine defined it as doing nothing.

What matters is how it is used: a package switches to \nullfont around material it wants to measure without typesetting, then restores the real font with \selectfont. With \selectfont inert, the font never came back — everything that followed was typeset in a font with no characters at all. pgf does this for every figure: hence a node's empty text box and its lost letters.

This engine keeps one font per family rather than the NFSS tables, so \selectfont re-selects the base font (roman, \normalsize); the change is carried by a group like any other.

\voidb@x, the kernel's permanent empty box, was also missing: \setbox<n>=\box\voidb@x is how a package empties a register, and without that name the idiom read register 0 and stole its contents.

Result

\node at (1.5,1) {Bonjour}; inside a 3×2 rectangle comes out centered on the rectangle — verified by rendering the SVG (rsvg-convert), and pdftotext reads the whole word.

In PDF the letters still land at the figure's origin: there the glyphs are drawn by the text driver, outside the transformation scopes that the vector stream carries. This is a separate point, noted for later.

Verification

  • 778 tests pass, 0 skips, 0 failures; go vet and gofmt clean.
  • Conformance ratchet, corpus and scripts/fidelity.sh --check: OK.
  • New code at 100% coverage.
  • I wrote and then reverted a placement adjustment (\pgfsys@hboxsynced): with this fix the SVG placement is already correct, and the two variants stay indistinguishable on this case — I do not ship what I cannot prove.

\selectfont installs the font the current family, series and shape call for.
The engine defined it as doing nothing.

That matters because of what it is used for: a package switches to \nullfont
around material it wants measured but not set, and brings the real font back
with \selectfont. With \selectfont inert the font never came back, so
everything typeset afterwards was set in a font with no characters at all.
pgf does this for every picture — which is why a TikZ node's text box came
out empty, and its letters were lost.

This engine keeps one text face per family rather than NFSS's tables, so
\selectfont re-selects the base (roman, \normalsize) face; the switch is
scoped like any other, so a group restores what was in force before it.

\voidb@x, the kernel's permanently empty box, was missing too.
\setbox<n>=\box\voidb@x is how a package empties a register, and without the
name that idiom read register 0 instead and stole whatever was in it.

A node's text now composes and is placed where it belongs: \node at (1.5,1)
{Bonjour}; in a 3-by-2 rectangle comes out centred on the rectangle, verified
by rendering the SVG. In PDF the letters still land at the picture's origin —
there the glyphs are drawn by the text driver, outside the transform scopes
the vector stream carries, which is a separate thing to fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@tannevaled
tannevaled merged commit 6e3715c into main Aug 17, 2026
18 checks passed
tannevaled added a commit that referenced this pull request Oct 18, 2026
…s style group (#621)

Two errors of opposite sign that were cancelling each other, which is why the
visible symptom was a quarter of either one.

1ex WAS HALF THE FONT SIZE. TeX takes it from \fontdimen5 — tex.web §455 ("The
x-height for cur_font" → x_height(cur_font)) and §10675 ("param[5]=x_height is
the size of one ex in the font"). Measured against the reference at 10pt in
Latin Modern:

                 before    after    reference
    1ex           5.0pt    4.31pt      4.31pt
    1em          10.0pt   10.0pt      10.0pt
    3.5ex        17.5pt   15.08499    15.08499
    2.3ex        11.5pt    9.913pt     9.913pt

16% too big, on every dimension a class states in ex — and classes state a great
many. article's \section alone is

    \@startsection{section}{1}{\z@}{-3.5ex plus -1ex minus -.2ex}{2.3ex plus .2ex}

so each heading took 4.00pt more vertical space than the reference gives it.

AND THE HEADING'S \par RAN OUTSIDE ITS STYLE GROUP, where LaTeX's \@SecT puts it
inside: \begingroup #6\relax … #8\@@Par \endgroup. The heading's last line
therefore ended under the BODY's \baselineskip instead of the heading's, worth
−5.978pt per heading.

−5.978 + 4.00 = −1.98, and the symptom that started this was 1.99pt per section.
Fixing either alone makes headings WORSE than leaving both; together they land
on the reference. Three witnesses, each measured between two words of the same
type size so poppler's word-box bias (a constant 1.41 ratio between engines)
cancels:

    witness                        before    after     reference
    article's \section             52.804    54.795    54.793
    \@startsection, rigid skips    48.791    54.769    54.767
    \@startsection, article's      52.804    54.795    54.793

All three within 0.002pt.

HOW ex IS OBTAINED, in TeX's order of authority: an ASSIGNED \fontdimen5 if the
document wrote one, as extraSpaceOf already honours \fontdimen7; otherwise the
height of the glyph 'x' in that face, which is what the x-height IS and keeps
this to the fontFace interface the engine already has; and only with no font at
all, half the size — the old approximation, kept for the one case it was right
for. A face whose 'x' has zero height falls back rather than returning 0, since a
0pt ex would collapse every ex-stated skip in the document.

Seven tests. TestEmExUnits changes: it asserted 1ex = 5.0pt, half the size, which
is the defect. spMock reports 7pt for every glyph, so its 'x' is 7pt and the new
expectation discriminates — half the size would still be 5.0pt.

⚠ The \par placement is asserted by the SHAPE of the kernel definition, which is
weaker than asserting behaviour and is deliberate: its effect is a 5.978pt shift
that only the oracle resolves, and mutate showed that moving the brace back
survives every other test here. The TeX property it relies on — a \par inside a
group takes that group's \baselineskip — is tested on its own.

Co-authored-by: Claude Opus 5 <[email protected]>
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.

1 participant