Skip to content

fix: \text keeps its interword spaces - #69

Merged
tannevaled merged 2 commits into
mainfrom
textspace
Nov 26, 2026
Merged

tannevaled merged 2 commits into
mainfrom
textspace

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

\text{gene }i \text{ is conditionally independent from gene } j printed as "geneiisconditionallyindependentfromgenej" (go-tex/engine, corpus paper 2407.19892, page 2). Not specific to any class: it reproduces with article + amsmath.

Cause: the tokenizer discards every blank and \text is read as an alphabet switch (\mathrm). amstext.sty typesets the argument in an \hbox in text mode, so inter-word glue is kept, leading and trailing included.

Fix: inside the braces following \text, \mbox, \hbox, \textrm, \textnormal, a run of blanks becomes one control space (6mu = cmr10's interword space). A blank after a control word is still swallowed (TeXbook ch. 8), and $...$ inside the span is maths again. Maths mode outside the span and \mathrm are unchanged.

Not done: the current text font (e.g. \textit context) is not inherited by \text; the alphabet is still upright.

Test: TestTextKeepsItsInterwordSpaces pins widths (fails before: \text{a b} and \text{ab} are both 36.00). Full suite passes.

🤖 Generated with Claude Code

The tokenizer discarded every blank, so \text{gene }i \text{ is ...} set
as "geneiis...". amstext.sty typesets the argument in an \hbox in text
mode, where a blank is interword glue. Inside the braces after \text,
\mbox, \hbox, \textrm and \textnormal a run of blanks is now one control
space (6mu, cmr10's interword space); a blank after a control word is
still swallowed, and $...$ inside the span is maths again.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… gate

The 100% coverage gate failed on the two \bgroup/\egroup branches: the text
group start read pendingText AFTER the control-word scan had cleared it, so
\text\bgroup could never open a text span (dead code). Read it before the
clear, and skip the blanks after \bgroup/\egroup as TeX does after any control
word. Test: \text\bgroup a b\egroup is \text{a b}.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@tannevaled
tannevaled merged commit c89db5b into main Nov 26, 2026
11 checks passed
@tannevaled
tannevaled deleted the textspace branch November 26, 2026 15:16
tannevaled added a commit to go-tex/docs that referenced this pull request Nov 26, 2026
…, corpus (v0.299.0-v0.300.0) (#30)

Adds four bullets to "What it does": font sizes and classes; pages and
geometry; mathematics (align tags, \text spaces); the corpus A/B measured on
v0.299.0. Source: engine #936-#950, go-tex/math#69.

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
tannevaled added a commit to go-tex/engine that referenced this pull request Nov 26, 2026
Documents font sizes in any TeX unit, a class's restated \normalsize as the
body size, \PassOptionsToClass option expansion, authblk, the elsarticle star
marks, LMSans bold and oblique, the page folio, geometry options and
heightrounded, eso-pic on even pages, align \tag placement and relation
spacing, \text spaces (go-tex/math v0.51.0), and the corpus A/B measured on
v0.299.0. Source: engine #936-#950, go-tex/math#69.

Co-authored-by: Claude Sonnet 5.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