Repository navigation
compiler: \ref in a heading or caption resolves, instead of typesetting its key - #635
Merged
Merged
Conversation
…ng its key
`\section{Back to \ref{sec:a} again}` typeset the literal "sec:a". So did
`\caption{See \ref{sec:a} here}`, and `\pageref`/`\eqref` behaved the same way.
Headings, captions and style arguments are flattened into a token list and run
through `inlines_from_tokens` rather than being re-parsed, and that converter
handles only a few commands by name. `\ref` was not among them, so the command
was dropped and its braced argument survived as ordinary text.
The arm added here emits the same `Inline::Reference` the main token loop builds,
so resolution, `\pageref`'s page number, `\eqref`'s parentheses and the bold `??`
for an undefined key are now identical in both places.
This is also why a cross-reference after an unclosed brace printed its key: the
recovery path in `style_command` falls through to `inlines_from_tokens` when
`closed_group_start()` finds no closing brace. That case is fixed by the same
arm, and `\ref{sec:b}` again carries the whole `\ref{...}` span with the resolved
number -- which is what the Mac's NavigationRealCompilerTests fixture expects.
compiler: 737 passed, 0 failed.
Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)
GoKubar
added a commit
that referenced
this pull request
Sep 15, 2026
/#635 grew the inventory docs/user/compiler.md (generated) conflicted again; took main's copy and regenerated via render_supported_latex.sh so \underbar and main's additions both appear, sync --check clean. Implementation-Agent: fable-rebase-a Commit-Executor: fable-rebase-a (direct; Cursor usage limit)
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.
The bug
typesets "Back to sec:a again". It should be "Back to 1 again". The same happened in captions, and
\pageref/\eqrefbehaved identically:\section{Back to \ref{sec:a} again}Back tosec:aagainBack to1again\caption{See \ref{sec:a} here}Seesec:ahereSee1here\section{P \pageref{sec:a} E \eqref{sec:a}}Psec:aEsec:aP1E(1)\section{Missing \ref{nope} here}MissingnopehereMissing??hereCross-references in headings and captions are ordinary LaTeX, so this is squarely user-facing.
Cause
Headings, captions and style arguments are not re-parsed — they are flattened into a token list and run through
inlines_from_tokens, which dispatches only a handful of commands by name (\color, siunitx, style commands…).\refwas not among them, so the command token was dropped and its braced argument survived as ordinary text.Running text was always fine, because the main token loop builds an
Inline::Referenceatparser.rs's"ref" | "pageref" | "eqref"arm. The new arm emits exactly that same inline, so resolution,\eqref's parentheses and the bold??for an undefined key are identical in both places.It also fixes the unclosed-brace case
style_commandre-enters a closed group properly ("so math and other commands inside it are parsed normally") but falls through toinlines_from_tokenswhenclosed_group_start()finds no closing brace. So one unclosed\textbf{in an\inputed file made every later\refprint its key:That span-and-value pair is what the Mac's
NavigationRealCompilerTestsfixture asserts, so this clears one of the five known Mac test failures.Tests
compiler: 737 passed, 0 failed, plus a newreference_in_a_heading_is_a_reference_not_textpinning that the heading's\refis anInline::Referenceand that the key does not survive as text.Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)