Repository navigation
Conversation
LaTeX has three spellings of one thing and this compiler got each of them
wrong somewhere. `~` is catcode 13 and expands to `\nobreakspace`
(latex.ltx 9413); `\nobreakspace` is `\DeclareRobustCommand{\nobreakspace}
{\leavevmode\nobreak\ }` (latex.ltx 9411); a non-breaking space typed into a
UTF-8 source is mapped onto the same command by `inputenc`. All three are an
interword space of the current font with no legal line break at it.
* `~` inside a macro body printed a literal tilde. `\newcommand{\fig}
{Figure~7}` set `Figure~7`.
* `\nobreakspace` raised `error: \nobreakspace is not supported by this
compiler version` and typeset **nothing** -- the space was deleted.
* `\,` `\!` `\:` `\;` `\>` inside a macro body printed the bare character,
so `\newcommand{\ab}{A\,B}` set `A,B` in text mode.
## One cause behind all three
The lexer records a control symbol's escape only in the *width* of its span
(`\,` is the word `,` spanning two bytes), and a token copied out of a
macro's replacement text carries the span of the **invocation**, whose width
says nothing about how the token was written. Every decision made from
`token.span` there is made from unrelated bytes. `~` had the same shape one
level up: the character was carried through the text stream as the source
byte `~` and a later stage was expected to recognise the tie by reading the
source back, which replacement text makes impossible -- and which cannot be
guessed either, because `\textasciitilde` produces the same character and
must stay a tilde.
So the escape is no longer re-derived:
* `ExpandedToken::escape_span` returns the token's own bytes (the recorded
definition bytes for replacement text), and `control_symbol_kern`'s two
call sites read that instead of `token.span`. `token.span` stays the
invocation span, which is what diagnostics and incremental relayout need.
* `lexer::apply_text_ligatures` -- already the one place that turns source
characters into the characters TeX sets (`--` into an en dash, `` ` ``
into a curly quote) -- resolves `~` to `lexer::NO_BREAK_SPACE` (U+00A0).
The text stream is self-describing from then on. `\verb` and `verbatim`
never reach that function, which is exactly where pdflatex also stops
treating `~` as active, so `\verb|~/.local|` keeps its tilde.
* `text_builtins::kernel_tie` gives `\nobreakspace` the same character.
It is deliberately **not** a row in `TEXT_SYMBOLS`: it is a kernel
command, not a `\DeclareTextCommand`, so resolving it through the
encoding tables is what produced `unavailable in encoding OT1` for the
commonest space in LaTeX. The `*.dfu` row naming U+00A0 describes only
the other direction.
The math hand-off has the same span confusion and is a separate lane's fix
(PR #286, `parser::math_token`); nothing here touches it.
## How broad this actually was
Narrower than it looks, and worth saying so. Across the 22 real-world
corpus fixtures there are **98 `~` in the sources and exactly one** that was
typeset as a literal tilde (`article-twocolumn`, a `\bibitem` continuation
line). The other 97 were already correct, because a `~` written directly in
the source has an exact span. The broken cases are macro replacement text
and `\nobreakspace`, which the corpus happens barely to exercise and real
documents do.
## Verification
`\ `-width and breakpoint behaviour were checked against pdflatex (TeX Live
2025) rather than assumed. A paragraph engineered to want to break exactly
at the tie breaks after `Figure` with a space and keeps `Figure 7` together
with `~`, which is what pdflatex does with the same source; the tie's width
is the font's interword space (3.3209bp at 10pt) and is unaffected by the
preceding sentence period, as `\ ` requires.
`cargo test --release --no-fail-fast`: **498 passed, 0 failed**, 9 new tests
in `tests/tie.rs`. The regenerated `supported-latex.json` / `coverage.md` /
`docs/user/compiler.md` and the sha256-gated Mac copy come from
`scripts/render_supported_latex.sh` and `apps/mac/scripts/sync-supported-latex.sh`.
Implementation-Agent: claude-opus-5 (engine lane, linux-primary/NixOS).
Commit-Executor: claude-opus-5 direct git; no Cursor CLI is installed on
this machine, so the direct-agent route is the only available one.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
This was referenced Sep 14, 2026
This was referenced Sep 15, 2026
Merged
Contributor
Author
|
Closed under the old-engine freeze (DESIGN.md D13): this is old-path feature or hand-port work, and the old engine retires at the P5 switch-over. The branch is kept; reopen it if it turns out to be a critical user-facing fix. — kabir-claude (Commander), nightly review 2026-09-30 |
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.
LaTeX has three spellings of one thing, and this compiler got each of them wrong somewhere.
~is catcode 13 and expands to\nobreakspace(latex.ltx 9413);\nobreakspaceis\DeclareRobustCommand{\nobreakspace}{\leavevmode\nobreak\ }(latex.ltx 9411); a non-breaking space typed into a UTF-8 source is mapped onto the same command byinputenc. All three are an interword space of the current font with no legal line break at it.~at top level~in a\newcommand/\defbody\nobreakspaceerror: not supported by this compiler version, and the space was deleted\,\!\:\;\>in a macro body (text mode)\newcommand{\ab}{A\,B}setA,B\textasciitildeHow broad
~actually is — measured, and narrower than it soundsThe report that reached this lane was that
~prints literally in "almost every real document". It does not, and inflating it would have been the wrong call. Rendering all 22fixtures/real-worldfixtures and looking for a literal tilde in the output:~in the sources, exactly 1 typeset as a tilde (article-twocolumn, thepp.~1119--1184continuation line of a\bibitem).listings-manualwrites\texttt{\textasciitilde/.local/bin}.\textbf,\emph,\section,itemize,footnote,center,quote,\title, before\ref/\cite, and~inside a macro argument.The dividing line is exact: a
~written directly in the source has a span that covers its own byte, and everything already worked from that. Broken were macro replacement text and\nobreakspace— which this corpus barely exercises and real documents do (\newcommand{\eg}{e.g.~},\newcommand{\figref}[1]{Figure~\ref{#1}}).The breakpoint test, against pdflatex
Width alone is not the claim; the tie must also remove the breakpoint. A paragraph was engineered to want to break exactly there, and run both ways under pdflatex TeX Live 2025 and through the engine:
... llll Figure... llll Figure~... llll Figure 7... llll Figure 7Identical, 0 overfull/underfull in both pdflatex runs. The tie's width is the font's own interword space (3.321bp at 10pt) and is not inflated by a preceding sentence period (
Dr.~Smithmeasures 3.321bp, not the space-factor-3000 width), which is what\requires.One cause behind all of it
The lexer records a control symbol's escape only in the width of its span —
\,is the word,spanning two bytes — and a token copied out of a macro's replacement text carries the span of the invocation, whose width says nothing about how the token was written. Any decision made fromtoken.spanthere is made from unrelated bytes.~was the same shape one level up: the source byte was carried through the text stream and a later stage was expected to recognise the tie by reading the source back. Replacement text makes that impossible, and it cannot be guessed either, because\textasciitildeproduces the same character and must stay a tilde.So the escape is no longer re-derived:
ExpandedToken::escape_spanreturns the token's own bytes (the recorded definition bytes for replacement text);control_symbol_kern's two call sites read that instead oftoken.span.token.spanstays the invocation span, which is what diagnostics and incremental relayout need.lexer::apply_text_ligatures— already the one place that turns source characters into the characters TeX sets (--into an en dash,`into a curly quote) — resolves~tolexer::NO_BREAK_SPACE(U+00A0). The text stream is self-describing from then on.\verbandverbatimnever reach that function, which is exactly where pdflatex also stops treating~as active.text_builtins::kernel_tiegives\nobreakspacethe same character. It is deliberately not a row inTEXT_SYMBOLS: it is a kernel command, not a\DeclareTextCommand, so resolving it through the encoding tables is what producedunavailable in encoding OT1for the commonest space in LaTeX. The*.dfurow naming U+00A0 describes only the other direction.The math hand-off has the same span confusion and is a separate lane's fix (#286,
parser::math_token). Nothing here touches it; this is the text-mode twin, which that PR does not cover —\newcommand{\ab}{A\,B}in ordinary prose still printed a comma.Gates
crates/compilercargo test --release --no-fail-fast: 498 passed, 0 failed, against the same-directory control built from the same base5baa9e6e: 489 passed, 0 failed. The 9 new tests aretests/tie.rs.~became U+00A0. No fixture gained or lost a diagnostic. The single surviving literal tilde islistings-manual's\textasciitilde, which is correct.supported_latexdrift gate passes with\nobreakspaceadded to the inventory;supported-latex.json,coverage.mdanddocs/user/compiler.mdwere regenerated byscripts/render_supported_latex.sh, and the sha256-gated Mac copy byapps/mac/scripts/sync-supported-latex.sh.Vendor re-pin needed for the render pipeline
crates/render-pipelinebuilds againstvendor/compiler, a pinned mirror, so it does not see this change. Its own tie handling is fixed in a companion pipeline PR, which is written to be correct both before and after a re-pin; the macro-body case reaches the Latin Modern producer only oncevendor/compileris re-pinned past this commit. No vendor files are committed here.Implementation-Agent: claude-opus-5 (engine lane, linux-primary/NixOS).
Commit-Executor: claude-opus-5 direct git; no Cursor CLI is installed on this machine, so the direct-agent route is the only available one.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu