Repository navigation
compiler: \xspace conditional trailing space - #506
Conversation
\xspace at the end of a macro body inserts a word space unless the
token following the call is }, another command, or , . ! ? ; : ' /.
The expansion pass already flattens macro calls, so the next token in
the parser stream is the post-call token: the consumed \xspace token
is flipped to Space in place (main loop) or pre-resolved in flat
heading/caption/style content. \usepackage{xspace} is now silent.
Implementation-Agent: muse-spark-1.3-contributor
|
daniel-parent review (subagent) Verdict: CHANGES NEEDED Mechanical precheck ( I built real
Given (1) and (2), the PR body's claim "Exclusion set implemented: Test results (independently re-run): checked out the PR head in a detached worktree ( |
Slice 1 claimed the rule matched real xspace.sty semantics; it did not. Two gaps, both fixed in xspace_inserts_space (crates/compiler/src/parser.rs): - Punctuation: add ~, - and ) to the exception set (real \@Xspace@exceptions@tlp), checked against the FIRST CHARACTER of the following Word token since the lexer folds them into it; control-space (\ , lexed as the one-character word " ") likewise suppresses. - Commands: only footnote/footnotemark/bgroup/egroup/space suppress. Ordinary commands (\textbf, \emph, \today, \relax, user macros) get the space, as real xspace does. Tests: xspace_before_group_end_command_or_punctuation_inserts_nothing loses its wrong no-space-before-\textbf case (renamed ..._group_end_or_punctuation_...); new xspace_before_tilde_hyphen_or_paren_inserts_nothing and xspace_before_ordinary_commands_inserts_space cover \foo-bar, (\foo), \foo~bar, \foo\ , \foo\textbf{bar} (typed-space equivalence), \foo\today (one-word_space layout shift), \foo\relax bar, \foo\baz and unspaced \footnote/\footnotemark marks. Full crates/compiler suite green. Implementation-Agent: muse-spark-1.3-contributor
The prior slice's fix corrected xspace's exception set and command
allowlist but left supported.rs's/docs/user/compiler.md's one-line
description describing the old, now-incorrect rule ("another command"
instead of the short explicit allowlist; missing ~ - )). Regenerated
via render_supported_latex.sh so the inventory prose matches the fix.
Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: daniel-muse-lead (Claude Sonnet)
|
Fix pushed (`dea0c8bd`) addressing both review findings, plus a follow-up doc regen (`2b641cb2`).
Independently verified: `cargo test --lib xspace` 6/6 pass, `cargo test --test supported_latex` 8/8 pass (confirms the regen matches, including `generated_artifacts_are_current`). Mutation check (fresh `CARGO_TARGET_DIR`): reverted the `~`/`-`/`)` exceptions → `xspace_before_tilde_hyphen_or_paren_inserts_nothing` FAILED exactly as expected; restored → passes. One honest caveat the lane found and documented: in this compiler, a space immediately before `\textbf{...}` never reaches layout regardless of whether it's typed or xspace-fired (a group-boundary quirk affecting every `word \cmd{...}` in this compiler, out of this fix's scope) — so problem 2's fix is verified via `\today`/plain-word cases where the shift IS observable, not via `\textbf`. |
|
daniel-parent review (subagent) Verdict: CHANGES NEEDED This is a re-review of the current head ( Mechanical precheck (
|
| case | real pdflatex | FlashTeX impl |
|---|---|---|
\foo bar vs glued |
+3.333pt (one space) | fires (matches) |
\foo bar vs typed space |
0.0pt (identical) | fires (matches) |
, . ! ? ; : ' / ~ - ) } |
0.0pt vs glued (all 12) | suppressed (matches, all 12) |
\foo\textbf{bar} vs typed space |
0.0pt (identical) | fires (matches) |
\foo\relax bar vs typed space |
0.0pt | fires (matches) |
\foo\baz (user macro) vs typed space |
0.0pt | fires (matches) |
\foo\footnote{n} vs glued |
0.0pt (suppressed) | suppressed (matches) |
All 19/19 match. This is a real, independent confirmation of both fixes — not just re-reading the new tests.
Tests fail without the change (confirmed)
Mutation-tested in the worktree: forced xspace_inserts_space to return false unconditionally → 4/6 xspace tests fail (..._inserts_exactly_one_space, ..._group_end_or_punctuation..., ..._ordinary_commands..., ..._heading_and_style_arguments). Forced it to return true unconditionally → the other 4 fail (..._group_end_or_punctuation..., ..._ordinary_commands..., ..._tilde_hyphen_or_paren..., ..._heading_and_style_arguments) — together all 6 tests are killed by at least one mutant, so they're not vacuous. Reverted before removing the worktree; git diff --stat confirmed clean afterward.
Repro requirement — a real gap in the instruction, not the PR
cargo test -p flashtex-compiler --lib xspace: 6/6 pass (up from 4 last review). cargo test --test supported_latex (crates/compiler): 8/8 pass, including generated_artifacts_are_current and every_inventory_entry_compiles_without_an_unsupported_diagnostic — the latter is a real, non-mocked compile of a document invoking \xspace through the actual fixed crate.
I could not get a real flashtex build/flashtex check (the shipped CLI) to demonstrate this, and confirmed why: crates/flashtex-cli/Cargo.toml hard-points flashtex-compiler = { path = "../render-pipeline/vendor/compiler" } — a byte-for-byte frozen pin (crates/render-pipeline/vendor/VENDORING.md) that predates every currently-open compiler PR, \xspace included. Built flashtex --version/flashtex supported --json from the worktree and confirmed: 858 commands (the pre-PR count), no xspace entry — the installed CLI genuinely cannot see this fix, by design, until a separate vendor re-pin happens. That's out of scope for this PR (and out of scope for me — vendor/ is off-limits). As the closest faithful substitute I built and ran crates/compiler's own standalone worker binary (crates/compiler/src/main.rs, no vendor dependency) directly: flashtex-compiler --supported json → 859 commands, xspace present, matching the PR's claimed +1 text-mode command. This is a process note for whoever wrote the review checklist (every compiler-only PR right now has this same limitation), not a mark against #506.
Other checklist items
- (a) vendor/ untouched — confirmed, no diff.
- (d) Body claims — accurate against the current diff (see the one nit below).
- (f) Vocabulary —
xspacewas never inKNOWN_UNIMPLEMENTED_COMMANDS(crates/compiler/src/vocabulary.rs) onmainor on this branch, so there was nothing to remove; not a gap. - (g) Generated artifacts — ran
crates/compiler/scripts/render_supported_latex.shin the worktree: zero diff against the PR's committeddocs/user/compiler.md,crates/compiler/supported/{supported-latex.json,coverage.md}, and the mac copy stayed in sync (sync-supported-latex.sh: bundled copy is current). Confirmed regenerated, not hand-edited.
New findings
- Minor, non-blocking: the PR body's "Scope" section still states the exclusion set as "
}, another control sequence, and, . ! ? ; : ' /" — that's the old, now-superseded rule from before this round's fix. The generated inventory descriptions (which the body itself quotes further down under a different heading) correctly say, . ! ? ; : ! ~ - )plus the closed command list. Since this is PR body prose (not code or generated content) and doesn't gate anything, I'm not blocking on it, but the author should fix the stale sentence before merge so it doesn't mislead a future reader diffing the body against the code.
No other new issues found. Both substantive findings from the last round are genuinely fixed and independently verified against real pdflatex/xspace.sty and mutation-tested; the only outstanding item is the one-line body-text edit above. Once that's updated (or the author confirms it's intentional, which I don't think it is), this is ready — I'm not aware of anything else standing in the way.
|
daniel-parent review (subagent) Verdict: READY Re-review of current head Resolution of the prior review threadThe most recent prior comment (07:31:01Z) already confirmed both substantive round-1 findings (missing Mechanical precheck (
|
| case | vs typed-space reference | vs glued reference |
|---|---|---|
\foo world |
0.0pt (identical) | +3.333pt (one interword space) |
\foo. |
−3.333pt (suppressed) | 0.0pt (identical, glued) |
\foo, and |
−3.333pt (suppressed) | 0.0pt (identical, glued) |
Confirms real xspace.sty semantics exactly as the PR claims: fires before a word, suppresses before ./,.
Built the PR and ran the real compile pathway on the same three snippets
Beyond re-running the unit tests, I built crates/compiler's standalone JSON-Lines worker binary (src/main.rs, the real production entry point, independent of the frozen vendor/ pin) and fed it actual compile requests for the three required snippets via stdin/stdout, comparing item x_pt positions:
\foo bar→Foo@72,bar@93.49 — byte-identical to typedFoo bar(Foo@72,bar@93.49), and distinguishable from gluedFoobar(single item). Space correctly inserted.\foo.→Foo@72,.@90.49 — gap of 18.49pt equalsFoo's own glyph width (no space added). Space correctly suppressed before period.\foo, and→Foo@72,,@90.49 (same 18.49pt gap, no space before comma),and@96.49 (the ordinary typed space after the comma is correctly preserved, untouched by xspace).
This matches the pdflatex oracle pattern exactly and is a genuine end-to-end confirmation, not just internal-helper unit tests.
Operational note, not a PR defect: my first attempt at this used the shared CARGO_TARGET_DIR=target-review-muse2 per the review instructions, and produced a binary that incorrectly reported \xspace as unknown_command (byte-for-byte the pre-fix diagnostic), despite being linked from a correctly-checked-out PR worktree and despite the lib unit tests passing moments earlier in that same target dir. Rebuilding in a fully isolated, non-shared target dir fixed it immediately and reproducibly (confirmed the lib tests and supported_latex integration tests too, to rule out a false-positive pass from the same corruption). This looks like stale/corrupted incremental-build state from concurrent use of the shared target dir, not a code issue — but it's worth flagging: a reviewer relying solely on the shared dir could currently see a false "regression to the old bug" for reasons that have nothing to do with the PR. Recommend whoever owns target-review-muse2 either serializes bin-target builds harder or reviewers double-check anything that looks like a pre-fix regression with a scratch target dir before reporting it.
Tests not vacuous (verified via git history, given review-only tooling)
I can't hand-mutate the worktree (review-only: no Edit/Write in the repo or any worktree of it), so I verified non-vacuousness by reading the actual historical diff between the PR's first commit (0349eceb, the buggy initial implementation) and the fix commit (dea0c8bd):
- Old code:
Some(TokenKind::Command(_)) | Some(TokenKind::RBrace) | ... => return false(any command suppressed) — directly contradictsxspace_before_ordinary_commands_inserts_space's assertions thattextbf/emph/today/relax/baz/citeall fire. - Old code's punctuation set was
, . ! ? ; : ' /only — directly contradictsxspace_before_tilde_hyphen_or_paren_inserts_nothing's assertions that~,-,), and control-space all suppress.
Both new tests pin exactly the two real bugs found and fixed across this review, so they are not vacuous. This corroborates the live mutation-and-revert runs already reported in the prior two review rounds.
Build/test in worktree (step 6)
cargo test -p flashtex-compiler --lib xspace (isolated target dir, to sidestep the shared-dir issue above): 6/6 pass. cargo test --test supported_latex: 8/8 pass, including generated_artifacts_are_current and every_inventory_entry_compiles_without_an_unsupported_diagnostic. --supported json reports 308 text-mode commands including xspace, matching the doc's claimed 307→308 bump.
Conclusion
No hard-rule violations. Both substantive findings from earlier rounds are genuinely fixed and now confirmed by three independent methods (real pdflatex oracle, real end-to-end compile-protocol run, and the existing unit/integration suite) rather than re-reading the prior review's word for it. The one remaining body-text nit from last round is fixed. Tests are meaningful, not vacuous. No vendor/ changes. OK to mark ready.
Scope
Fixes #496.
\xspace(xspace.sty) previously erroredunknown_commandwith a misleading did-you-mean-\hspace/\vspacesuggestion.crates/compiler/src/parser.rs+ regenerated inventory artifacts (project script, not hand-edited).Mechanism: the expansion pass already flattens every macro call into one token stream before the parser runs, so the token right after
\xspace's position already IS whatever follows the macro invocation site — no macro-boundary tracking needed. A fired space flips the just-consumed\xspacetoken toSpacein place via the existingtoken_mutcopy-on-write/undo-log helper (verified this is a genuine pre-existing mechanism, not invented — same one other in-place token edits already use), so a stream borrowed from the expansion cache is lent and undone exactly as it already is elsewhere. A separateresolve_xspacepre-pass handles headings/captions/style arguments, which go through a different flattened-token code path that never reaches the main loop.Exclusion set implemented:This claim was wrong (see Update below) — fixed in a later commit.}, another control sequence, and, . ! ? ; : ' /— matches the real xspace.sty semantics.Overlap check
git branch -a --list '*xspace*'— no other branch.coord.py claims—GH-XSPACEheld only by me,--branchset.Test results
Full
cargo testincrates/compiler(freshCARGO_TARGET_DIR, untruncated): 57/57 test binariesok, 0 failures (lib: 343 passed, incl. 4 new: word-following, punctuation/group/command-suppression, heading/style-argument path, silent package load).Mutation check (independently re-run by the reviewer): with the space-firing condition forced off,
xspace_before_a_word_inserts_exactly_one_spacefails (expected ... exactly one word space ...: 90.49 vs 90.49— i.e. glued, no space); restored with a fresh build, all 4 new tests pass.Not done
\xspaceinside math mode still reports the existingnot supported in math modediagnostic (a pre-existing, differently-coded error; spaces are meaningless in math anyway) — a math-mode no-op arm was judged out of this lane's file scope (math.rs) and left for a follow-up if wanted.\xspaceaddexceptions(customizing the exclusion set) not implemented.Update (review fix)
Two real gaps found by review, both fixed: (1) the exception set was missing
~,-,)(xspace.sty's real set is, . ' / ? ; : ! ~ - )), checked against the first character of the followingWordtoken since the lexer folds these into it; (2) "any control sequence suppresses the space" was wrong — real xspace only suppresses before a short explicit list (\footnote,\footnotemark,\bgroup,\egroup, control space), so ordinary commands like\textbf/\emph/\relaxnow correctly DO get the space, matching real pdflatex\wdmeasurements. The old test asserting no-space-before-\textbf(which locked in the wrong behavior) was replaced. Also regenerated the stalesupported.rs/docs/user/compiler.mdone-line description, which still described the old (wrong) rule after the fix. See PR comments for full verification detail (mutation checks, entry-point repro).🤖 Generated with Claude Code