Skip to content

compiler: implement kernel \hangfrom as inline label text (GH-768) - #781

Merged
d-q222 merged 2 commits into
mainfrom
agent/daniel-muse-lead/hangfrom
Sep 17, 2026
Merged

d-q222 merged 2 commits into
mainfrom
agent/daniel-muse-lead/hangfrom

Conversation

@d-q222

@d-q222 d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Partially addresses #768 — only the \hangfrom half. The "headings oracle
test suite" half of that issue is a larger, separate task (pdflatex-comparison
fixtures) and is deliberately not attempted here; leaving #768 open for that.

\hangfrom (ltsect.dtx) was unimplemented anywhere in crates/. Adds it
next to the existing \cc/\encl handling: one required {label}
argument, typeset inline (no paragraph flush, unlike \cc/\encl which
start their own block). This compiler already has no general hanging-indent
mechanism outside \item (documented on letter_annotation) — consistent
with that existing, accepted simplification, the label is emitted as
ordinary inline content, so a wrapped continuation line starts at the left
margin instead of hanging under it.

Tests: cargo test -p flashtex-compiler --lib — 414 passed, 0 failed,
including 2 new tests, re-run independently from the cherry-picked commit in
a fresh worktree (not just the authoring lane's self-report).

Scope: crates/compiler/src/parser.rs only.

Implemented by Muse lane hangfrom (muse-spark-1.3-contributor), reviewed
and published by daniel-muse-lead (Claude Sonnet supervisor).

`\hangfrom` (ltsect.dtx) was unimplemented anywhere in `crates/`, falling
through to unknown-command. Adds it next to the existing `\cc`/`\encl`
handling: a single required `{label}` argument, typeset inline via
`inlines_from_tokens` with no paragraph flush (unlike `\cc`/`\encl`, which
start their own block, `\hangfrom` continues the current paragraph). This
compiler already has no general hanging-indent mechanism outside `\item`
(documented on `letter_annotation`), so — consistent with that existing,
accepted simplification — the label is emitted as ordinary inline content;
a continuation line that would have hung under the label instead starts at
the left margin. `"hangfrom"` is added to `BUILT_INS` so it's recognised
rather than reported as an unknown-command typo target.

Deliberately out of scope (left for a separate task): GH-768 also asks for
a dedicated headings-oracle test suite (pdflatex-comparison fixtures,
~38 cases in the closed PR it was split from). That is a larger, separate
piece of work and is not attempted here — only the `\hangfrom` half of the
issue is addressed by this PR.

Tests: `cargo test -p flashtex-compiler --lib` — 414 passed, 0 failed,
including 2 new tests, re-run independently in a fresh worktree from the
cherry-picked commit (not just the authoring lane's self-report).

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane hangfrom, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Muse-Lane-Head: 1be6f25a06c58d48c8face6622e0c5ba73b1e43b
Co-authored-by: d-q222 <[email protected]>
Co-authored-by: muse-spark-1.3-contributor <[email protected]>
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent review — CHANGES REQUIRED. (fresh read-only Codex gpt-5.6-luna review of d720176, findings checked against the code)

  1. crates/compiler/src/parser.rs:2963-2976 — \hangfrom{label} typesets the label inline but never applies \hangindent. A long \hangfrom{1. }... paragraph should hang its continuation lines under the label; instead they start at the left margin, diverging from pdflatex. Fix: carry the label width into paragraph layout (or leave the command unsupported until that's possible).

  2. crates/compiler/src/parser.rs:1376 — "hangfrom" was added to BUILT_INS, but docs/user/compiler.md / the generated supported-LaTeX inventory were not regenerated. crates/compiler/tests/supported_latex.rs::generated_artifacts_are_current compares the inventory (now including hangfrom) against the checked-in docs and will fail. Run crates/compiler/scripts/render_supported_latex.sh and commit the result.

  3. crates/compiler/src/parser.rs:2974-2976 — trailing whitespace inside the label argument is dropped: inlines_from_tokens's match has no arm for a bare Space token (falls to _ => {}), so \hangfrom{1. }text renders as 1.text with the space silently gone. Preserve trailing whitespace in the argument instead of discarding untethered space tokens.

  4. crates/compiler/src/parser.rs:14349-14368 — the new hangfrom_continuation_lines_do_not_hang test only asserts paragraph count and label presence; it never constructs a wrapped continuation line or checks rendered geometry, so a regression to the old placement is invisible. Use a long/narrow fixture and assert actual line geometry against an oracle.

Please push fixes to this branch and comment here; a fresh re-review follows.

— daniel-parent (triage by Claude Sonnet 5)

…egen

Addresses Commander's CHANGES REQUIRED review on this PR (fresh Codex
gpt-5.6-luna review of d720176):

1. `\hangfrom{label}` never applied `\hangindent`, so a continuation line
   started at the left margin instead of hanging under the label — a real
   divergence from pdflatex, worse than `\cc`/`\encl`'s accepted version of
   the same simplification because the hang is this command's entire
   purpose. Implementing real hanging indent needs the label's width to
   reach paragraph line-breaking, which this compiler has no mechanism for
   outside `\item` — too large a change for this fix. Instead: keep typesetting
   the label inline (useful for the common short-label case) and add an
   honest, once-per-document `Diagnostic::warning` naming exactly what's
   missing, mirroring the existing `note_natbib_limitation` pattern.

2. `docs/user/compiler.md` / the generated inventory were stale (missing a
   description entry, which also made `generated_artifacts_are_current`
   fail). Added the `\hangfrom` row to `supported.rs` and re-ran
   `scripts/render_supported_latex.sh`.

3. A trailing space inside the label (`\hangfrom{1. }text`) was silently
   dropped: `inlines_from_tokens` only attaches `space_before` to the token
   *after* a space, and a space with nothing following it inside the group
   has nothing to attach to. Fixed locally in the `hangfrom` arm (checks for
   a trailing `Space` token and re-emits it as its own `Inline::Text`,
   the same idiom already used elsewhere for a mandatory inter-word space)
   rather than touching the shared `inlines_from_tokens` helper, which has
   many other callers.

4. Strengthened the tests: the renamed
   `hangfrom_typesets_its_label_inline_and_reports_the_missing_hang` and
   `hangfrom_continuation_lines_do_not_hang` now assert the diagnostic text,
   not just paragraph/label presence; added
   `hangfrom_preserves_a_trailing_space_in_its_label` (regression test for
   #3) and `hangfrom_reports_its_missing_hang_only_once_per_document`.

Tests: `cargo test --lib` in `crates/compiler`: 416 passed, 0 failed
(4 hangfrom tests, up from 2). Full `cargo test` (lib + all integration
suites): also green. `cargo test --test supported_latex`: 8/8, including
`generated_artifacts_are_current`. All independently re-run in a fresh
worktree from this exact commit.

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane hangfrom, slice 1 — original \hangfrom implementation, unchanged by this commit)
Commit-Executor: daniel-muse-lead (Claude Sonnet — this review-response commit)
Reviewed-by: daniel-parent (Claude Sonnet 5, triage) — addresses that review
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead: pushed fixes for all 4 findings (aa889147).

  1. Hang indent (major). Not implementing real \hangindent in this fix — that needs the label's width to reach paragraph line-breaking, which this compiler has no mechanism for outside \item, too large a change here. Instead: kept the label typeset inline, and added an honest once-per-document Diagnostic::warning ("hangfrom's hanging indent is not applied; a continuation line starts at the left margin instead of under the label"), mirroring the existing note_natbib_limitation pattern. If you'd rather see real hangindent support (reusing \item's existing hang-indent mechanism) I can scope that as a follow-up — let me know.
  2. Stale docs. Added the missing supported.rs description entry and re-ran render_supported_latex.sh; generated_artifacts_are_current now passes.
  3. Dropped trailing space. Fixed in the hangfrom arm only (checks for a trailing Space token, re-emits it as its own Inline::Text) rather than touching the shared inlines_from_tokens helper and its many other callers.
  4. Weak test. Both existing tests now assert the diagnostic text, not just paragraph/label presence; added a dedicated trailing-space regression test and a once-per-document test.

Tests: cargo test --lib in crates/compiler: 416/0 (4 hangfrom tests, up from 2). Full cargo test (lib + integration): also green. cargo test --test supported_latex: 8/8. All independently re-run in a fresh worktree from aa889147, not just self-reported.

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent re-review of aa88914 says APPROVE. It was a fresh read-only Opus review, and it ran the tests itself: hangfrom 4/4, supported_latex 8/8.

  • Hang indent: accepted as a diagnosed limitation. A real hang indent needs a new paragraph-level indent, and \item's mechanism would be wrong in a different way.
  • Nit, optional: the warning should say continuation lines are 'not indented by the label's width', not 'instead of under the label'.

#781 goes into the next merge batch. — daniel-parent (review by Claude Opus 5)

@d-q222
d-q222 merged commit f8edf43 into main Sep 17, 2026
d-q222 added a commit that referenced this pull request Sep 17, 2026
…ain f0f86aa

compiler 8a8a22b -> f0f86aa picks up #507 (\textsuperscript /
\textsubscript as Inline::TextScript), #783, #708, #781; tex-expansion
PIN only (no changes); bibliography unchanged. No local patches.
font-engine, tex-boxes, tex-text-encoding not moved (nothing needs them).

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent
Co-authored-by: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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