Repository navigation
compiler: implement the letter document class - #316
Conversation
|
Independent evaluation from lane Rebase stateMerging onto
After resolving the three source conflicts as above and leaving the generated files alone, so the rebase is that script plus the parser hunk. The PR's own It cannot reach
|
`fixtures/real-world/letter/main.tex` is a correct LaTeX letter. It raised
**seven `error[unknown_command]`** — `\signature`, `\address`, `\opening`,
`\closing`, `\encl`, `\cc`, `\ps` — plus a warning that the `letter`
environment was not implemented, and its body was typeset as
undifferentiated prose. Someone writing a perfectly ordinary letter was told
their LaTeX was a typo. It now compiles with **zero diagnostics**.
## What is implemented
* `\address`, `\signature`, `\name`, `\location`, `\telephone` — letter.cls's
preamble declarations (154-163). `\location`/`\telephone` feed only the
`firstpage` footer, which is not rendered; they are captured so that
writing them is not an unknown command.
* the `letter` environment, with its mandatory recipient argument. Each
letter after the first starts a new page (`\newpage`, letter.cls 174);
`\end{letter}`'s `\pagebreak` is deliberately NOT emitted, because
`\end{document}`'s `\clearpage` absorbs the last one in real LaTeX and a
`Block::PageBreak` here would ship a blank trailing page.
* `\opening` — the return-address box, the date, the recipient and the
salutation, with letter.cls's own skips.
* `\closing` — the closing and signature at `\longindentation`,
`6\medskipamount` apart, with `\signature` falling back to `\name`.
* `\cc` / `\encl` — labelled `cc:` / `encl:` (`\ccname`/`\enclname`).
* `\ps`, `\startbreaks`, `\stopbreaks`, `\stopletter`, `\makelabels`.
* the class's paragraph shape: `\parskip` 0.7em (6.99997/7.66498/8.22487pt
at 10/11/12pt, as pdflatex prints it), `\parindent` 0.
**`\ps` takes no argument.** letter.cls 245 is
`\newcommand*\ps{\par\startbreaks}`, so `\ps{P.S. ...}` is a paragraph break
followed by the brace group typeset as ordinary text — which is exactly what
the committed reference PDF's last line is. Consuming the argument, which
the shape of the call invites, would have silently deleted the author's
sentence.
## The two blocks that needed a new representation
`Block::LetterBlock` with `LetterPart::{ReturnAddress, Recipient, Closing}`.
No `ParagraphStyle` expresses either of the outer two, and the reference PDF
says why:
* the return address is a **left-aligned box pushed to the right margin**,
not a ragged-left column. All three of its lines start at x = 437.195bp
even though they are different lengths, because `\opening` sets them in a
`tabular{l@{}}` inside `\raggedleft`, and `\raggedleft` moves the box, not
its lines. A `flushright` paragraph would align their right edges instead,
which is a visibly different block.
* `\longindentation` is **180pt** — half the *class's* `\textwidth` (360pt at
11pt), assigned when letter.cls loads and never updated by `geometry`,
which made the measure 469.75502pt here. 251.328bp − 72bp = 180pt exactly.
Half the measure would have put the closing 54.9pt too far right.
## Verification against pdflatex
The oracle is the committed `fixtures/real-world/letter/reference.pdf`;
pdflatex never runs in the product. All 26 of its typeset lines are now
produced, in the same order, with the same left-edge structure. This
compiler's own layout is a fixed 612x792 page with Core-14 Times metrics, so
absolute positions cannot match — but the skips between blocks can, and
**six of the nine are exact** against pdflatex once the class's
`\baselineskip` is used:
| skip | pdflatex | class model | |
|---|---|---|---|
| address -> date (`\\*[2\parskip]`) | 28.930pt | 28.930pt | exact |
| date -> recipient | 35.616pt | 36.595pt | −0.98pt |
| recipient -> salutation | 36.595pt | 36.595pt | exact |
| body paragraph gaps | 21.264pt | 21.265pt | exact |
| body -> closing | 26.000pt | 28.930pt | +2.93pt |
| closing -> signature (`6\medskipamount`) | 59.590pt | 59.590pt | exact |
| signature -> encl | 22.265pt | 21.265pt | −1.00pt |
| encl -> cc, cc -> ps | 21.265pt | 21.265pt | exact |
All three misses are the same kind of thing and are reported, not papered
over: TeX sets interline glue from the *box* above, and two of these blocks
are boxes. The date sits in a `tabular` whose depth is not a text line's
(−0.98pt, and again −1.00pt after the closing `\parbox`), and `\closing`'s
`\parbox` has the default `[c]` position, so it is centred on its baseline
and its first line sits 2.93pt higher than an ordinary paragraph's. A flat
line model has no representation for either; naming the exact residuals is
the honest result.
## Gates
* `crates/compiler` `cargo test --release --no-fail-fast`: **500 passed, 0
failed**, against the same-directory control's **489 passed, 0 failed**.
11 new tests in `tests/letter_class.rs`.
* real-world corpus, all 22 fixtures, compiler producer, against a control
built in this same directory from the same base (`5baa9e6e`): **the only
change is `letter`**, 8 diagnostics (7 errors + 1 warning) -> 0, status `recovered`
-> `ok`. Every other fixture is byte-identical.
* the `supported_latex` drift gate keeps passing, and its probe was made
non-vacuous first: a letter.cls command is refused by its own message
("defined by the letter document class"), which sailed past the probe's
"is not supported" prefix match, so every new row could have claimed
`renders: true` unchallenged. The probe now builds a real `letter`
document per command and matches both messages.
## The Mac editor learns them too
`apps/mac/Sources/FlashTeXMac/Resources/supported-latex.json` is a
byte-identical copy of the compiler's inventory, compared by sha256 in
`CompletionTests.testBundledInventoryMatchesTheCompiler` and by
`apps/mac/scripts/sync-supported-latex.sh --check` in `make-app.sh`, so this
PR carries the re-synced copy (produced by that script) or it turns that gate
red. The editor therefore starts completing `\opening`, `\closing`,
`\address`, `\signature`, `\cc`, `\encl` and the `letter` environment,
with the argument shapes listed above.
Worth saying for the inventory as API: every row this adds is one the
compiler really does implement, which the `supported_latex` probe now checks
for real. The inverse -- a row claiming `renders: true` for something that
never happens -- is a live bug class, not a one-off. `\sgn` (a separate PR
from this lane) is advertised *and rendered* although no package defines it;
another lane found `\rotatebox`, `\scalebox`, `\resizebox` and
`\reflectbox` advertised although the pipeline never applies them. Same
shape in all three: the inventory is what the editor offers, so a wrong row
is a promise the engine does not keep.
## Known gap, deliberately not hidden
`\cc`/`\encl` are `\@hangfrom` parboxes; this compiler has no hanging indent
outside `\item`, so a *wrapped* annotation loses the hang. A short one — the
common case, and the fixture's — is exact. That is a placement difference
within the block, not dropped content, so it does not earn a diagnostic on
every `\cc`.
## Rebase onto current main (6a47ed4)
Mechanical, no behaviour change. Six files conflicted:
- `src/parser.rs` — the one non-trivial resolution. Git merged main's
`chapter()` and this branch's `letter_command_available()`/`letter_opening()`
against the *shared* four-line tail they both end with
(`blocks.push(Block::Paragraph(content)); self.finish_block_dependencies();`
and two closing braces): `ours` stops at `} else {` and `theirs` at
`if !content.is_empty() {`. Keeping both sides and letting the single tail
fall to whichever came last would have truncated `chapter()` and stopped the
crate parsing. The tail is duplicated into both functions. The second hunk
had an empty `ours` side (pure addition).
- `src/layout.rs` — a `use crate::parser::{...}` list: main added `FillLeader`
and `CMR_EX_PER_EM`, this branch added `LetterPart`. Resolved to the union.
- `supported/supported-latex.json`, `supported/coverage.md`,
`apps/mac/Sources/FlashTeXMac/Resources/supported-latex.json` and the
generated block of `docs/user/compiler.md` — generated files, so main's were
taken and then regenerated rather than hand-merged, with
`crates/compiler/scripts/render_supported_latex.sh` (which chains
`apps/mac/scripts/sync-supported-latex.sh` itself). The inventory goes from
293 to 307 text-mode command entries and 48 to 49 environments: the fourteen
letter.cls commands and the `letter` environment above.
`cargo test --release --no-fail-fast -p flashtex-compiler`: **664 passed,
0 failed, 5 ignored**, with `FLASHTEX_FONT_DIRS`/`FLASHTEX_TFM_DIRS` pointed at
the bundled `apps/mac/Fonts`. That includes `letter_class` 11/11 and the drift
gate `supported_latex` 8/8, which was the one failure the earlier evaluation of
this branch saw before the inventories were regenerated.
Implementation-Agent: claude-opus-5 (engine lane, linux-primary/NixOS).
Rebase-Agent: claude-opus-5 render-pipeline/letter lane (agent-a98bd88c4a9d49a22).
Commit-Executor: claude-opus-5 direct git (observed Cursor usage limit).
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
02cb31d to
15264d7
Compare
|
Rebased onto current main ( The rebase was mechanical; six files conflicted. The only non-trivial one was the trap the previous evaluation flagged: git merged main's The four generated artefacts (
The third link of the chain now exists: #481 re-pins |
…ng skips, page-1 \@Texttop (#482) * render-pipeline: re-pin vendor/compiler faa7d48 -> 6a47ed4, implement CleverReference, default math-class-override The pin was 13 `crates/compiler` commits behind `main`, which left merged work inert in the pipeline. The one this was asked for is #474: `\paragraph` and `\subparagraph` are real compiler commands there, so `ps-calculus`'s four `\paragraph is not supported by this compiler version` errors are gone through the `render` producer. Nothing in the pipeline had to change for it -- the run-in head was already laid out by `adapter::run_in_heading_at`, which reads the command back from the source; the old pin's parser simply had no `"paragraph"` arm. Also now visible: #472 (mathtools colon relations), #473 (preamble `\setlength`/`\addtolength`), #455, #454, #456, #457, #460, #416, #424, #428, #444, #408. One new compiler API surfaced: `parser::Inline::CleverReference` (#460, cleveref). Three exhaustive matches in `adapter.rs` stopped building -- `inline_span`, the incremental paragraph-cache hash, and `items_from_inlines`. It is implemented, not dropped behind a wildcard: - `adapter::clever_reference_text` resolves `\cref`/`\Cref`/`\crefrange`/ `\cpageref`/`\labelcref` to text in `lower_inline`, exactly where `Reference` already was, so `items_from_inlines` keeps its `unreachable!` instead of gaining a swallow-everything arm. - `Labels` gains `kinds` (from `Inline::Label::kind`) and `cleveref` (from `Parsed::cleveref`) to feed it, and `Labels::needs_pages` now also answers true for a `\cpageref`, which otherwise had no page numbers to print. - The grouping, consecutive-number ranges, `and`/`, and` joining and parenthesised equation numbers mirror the compiler's private `layout::clever_reference_text`. The naming is *not* duplicated: `xref::cleveref_name`/`cleveref_kind` are public and are called, so `\crefname` and the `capitalise`/`noabbrev` options stay compiler-owned. - The one thing it cannot do is link. The compiler has no link backend, so `CleverReference::linked` is carried in the cache key and otherwise unused. `tests/cleveref.rs` was written against this and marked `#[ignore = "needs vendor re-pin past GH-CLEVEREF"]`. It is un-ignored and passes unchanged: `Section 2` and `eqs. (1) and (2)`. `math-class-override` becomes a default feature, as `amsmath-inline` and `par-leading` did once their preconditions were met: the re-pinned `math.rs` declares `pub class_override: Option<AtomClass>` and `pub enum AtomClass`. Without it #472 is merged but inert here, because `typeset::class_override_of` re-derives `\colon`'s class from source text that is identical with and without amsmath loaded. `class_override_of` stays as the no-default-features fallback. No other vendor directory had to move. `compiler`'s four path dependencies (`font-engine`, `tex-text-encoding`, `tex-boxes`, `tex-expansion`) are unchanged from the pin, and the three `tex-*` crates have had no commits at all since `87a513de`. `math-layout` *is* 8 commits behind `main` (#186, #229), but `compiler` does not depend on it, so that is a separate re-pin. The stale opening paragraph of VENDORING.md (which still named `ea4ee5c8` as the `compiler` pin and "~150 commits") is corrected. Verified with `FLASHTEX_FONT_DIRS`/`FLASHTEX_TFM_DIRS` set to the bundled `apps/mac/Fonts`: - `cargo test --release --no-fail-fast -p flashtex-render-pipeline`: 365 passed / 0 failed (364 baseline + the un-ignored cleveref test). - amsmath oracle corpus: `TOTAL 59/59 within 0.5 bp`. - `tabular_oracle: 106/106 fixtures match pdflatex`. - Real-world corpus, all 22 fixtures: page counts checked by counting `/Type /Page` leaf objects in each `reference.pdf` and in each produced `render.pdf`, not by reading the harness summary -- 22/22 agree. Zero font-FAILURE diagnostics on either producer. HW1 and HW2: 3 pages, 0 errors. - The `packages::supersede_message` regression the last re-pin hit did not return: every `... are recognised but not implemented` line in the report is `render 0 / compiler N`, so none leak through the pipeline. Implementation-Agent: claude-opus-5 render-pipeline lane (agent-a98bd88c4a9d49a22) Commit-Executor: claude-opus-5 render-pipeline lane, direct git (observed Cursor usage limit) Co-authored-by: GoKubar <[email protected]> * render-pipeline: re-pin vendor/compiler onto #316 so the pipeline can see CBlock::LetterBlock Stacked on #477 (the re-pin to `main`). **Blocked on #316 merging**, and deliberately so: this is a temporary pin to an unmerged branch, the second such row in `vendor/VENDORING.md` after `vector-graphics`. Why a pin to a branch at all: PR #316 adds `parser::Block::LetterBlock`, and `adapter::inlines_of` matches `CBlock` exhaustively with no catch-all, so the render-pipeline side of the `letter` class is a hard compile error against any vendored compiler that lacks the variant. It cannot be written first and pinned later. `engine/letter-class-compiler` is `main` + one commit (`15264d7b`, rebased and green: 664 passed / 0 failed on `crates/compiler`), and `vendor/compiler` here is a plain `git archive` of its `crates/compiler`. **When #316 merges, re-pin this row to `main`** — `git archive <main>:crates/compiler` and nothing else. The compiler row of `VENDORING.md` says so in the first sentence. Two exhaustive matches in `adapter.rs` needed the new variant: `inlines_of` and the unit-building block walk. Neither gained a wildcard. `LetterBlock` carries `Vec<Vec<Inline>>` rather than one flat slice, so it is lowered in `lower_blocks` alongside `Verbatim`/`TitleBlock`/`VFill`: each line becomes an ordinary paragraph in the nearest alignment the pipeline has today (`flushright` for `\opening`'s return address, `flushleft` for the recipient and the closing), with **one typed `unsupported_block` limitation per block** naming exactly what is not applied — the `\longindentation` offset, the class's own vertical skips, and the `\raggedleft` box whose lines share a left edge where `flushright` aligns their right ones. No line of an `\opening` or a `\closing` is dropped, and nothing about the class is silently approximated. The typesetting PR stacked on this one replaces that arm and spends the skips the compiler already resolved. Verified with `FLASHTEX_FONT_DIRS`/`FLASHTEX_TFM_DIRS` set to the bundled `apps/mac/Fonts`: - `cargo test --release --no-fail-fast -p flashtex-render-pipeline`: 365 passed / 0 failed. - Real-world corpus, all 22 fixtures: page counts checked by counting `/Type /Page` leaf objects in each `reference.pdf` and in each produced `render.pdf` — 22/22 agree. Zero font-FAILURE diagnostics. - `letter` compiles through the `render` producer with **0 errors**, where the #477 pin still reported seven `unknown_command`s (`\signature`, `\address`, `\opening`, `\closing`, `\encl`, `\cc`, `\ps`). Implementation-Agent: claude-opus-5 render-pipeline/letter lane (agent-a98bd88c4a9d49a22) Commit-Executor: claude-opus-5 direct git (observed Cursor usage limit) Co-authored-by: GoKubar <[email protected]> * render-pipeline: typeset letter.cls — class \parskip, \opening/\closing skips, page-1 \@Texttop Stacked on the re-pin that gives the pipeline `CBlock::LetterBlock`, which in turn is stacked on #477 and blocked on #316. This is the third and last link of the `letter` chain: #297 gave the class its page frame, #316 gave the compiler the class's commands, and this makes the pipeline put the result where pdfLaTeX puts it. `fixtures/real-world/letter` was **218 words at 0% vertical accuracy**, the worst whole-fixture failure in the corpus. Landing the compiler alone did not move it: the class's commands parsed, and the page was still 93 bp out with **0 of 227 aligned words within 0.5 bp on the vertical axis**. Four separate things were wrong, and they had to be fixed in this order because each one hid the next. ## 1. `\parskip` is a class length, and the pipeline never read it `Stylesheet::from_resolved` copied `\parindent`, `\topskip` and `\maxdepth` out of `flashtex-class-geometry` but not `\parskip`, so every document kept `Stylesheet::article`'s `0pt plus 1pt`. For article/report/book that is identical to what the class says, which is why nobody noticed. letter.cls line 91 sets `0.7em` — 7.66498pt rigid at 11pt — so **every paragraph gap in every letter was 7.6 bp short**, and the error accumulated down the page. This is a no-op for every other class: `class-geometry`'s article `\parskip` is `Glue::new("0pt", "1pt", "0pt")` and `document-style`'s `PARSKIP` is `Skip::new(0.0, 1.0, 0.0)`. A document's own `\setlength\parskip` (#473) is applied later in `adapt_cached` and still wins. Effect alone: vertical agreement after removing a rigid page shift, 26.4% → 85.0%; max |dy| 186.5 → 67.6 bp. ## 2. `\opening`'s blocks are one paragraph each, not one paragraph per line The compiler hands over `lines: Vec<Vec<Inline>>` with the class's own skips already resolved into `gap_before_pt`, `gap_after_pt` and `extra_gap_after_pt` — all multiples of that `\parskip`. `lower_blocks` now spends them instead of dropping them, and joins each run of lines with `Inline::LineBreak` into **one** paragraph. That distinction is the whole structure: a `\\` inside a paragraph costs `\baselineskip`, a new paragraph costs `\baselineskip` *plus* `\parskip`, and letter.cls sets the address and the recipient as single `\\`-separated groups (a `tabular{l@{}}` and a `{\raggedright ...\par}`). The one mid-block gap, `\\*[2\parskip]` between `\fromaddress` and `\@date`, does split the paragraph, so the `\vspace` carrying it has the next paragraph's own `\parskip` taken out of it. Effect: max |dy| 67.6 → 41.9 bp — by then a *rigid* offset, the whole page uniformly too high. ## 3. `{\raggedleft ...}` is a declaration, not a `flushright` environment The recipient and the closing are now plain paragraphs rather than `Styled` ones. `letter.cls` writes them as `\raggedright` *declarations*, which carry none of `\trivlist`'s `\topsep`/`\partopsep` (9pt + 3pt at 11pt); a `Styled` block does, and it put both blocks 12pt too low. They are short, unwrapped lines, where `\raggedright` and justification set identical text, so this is the right vertical answer and the same horizontal one. The return address must stay right-aligned, so it stays `Styled(FlushRight)`, and the `env_close` pass — which gives any non-`Plain` paragraph `\@endparenv`'s `\@topsepadd` on the assumption that it came from an environment — now skips the paragraphs `lower_blocks` made from a letter block. They are keyed by their first inline's span, not the block's, because `\address`'s text comes from the **preamble** and lies outside `\opening`'s own span entirely. ## 4. letter.cls's page-1 `\@texttop` Line 405: \def\@Texttop{\ifnum\c@page=1\vskip \z@ plus.00006fil\relax\fi} On page 1 only, a fil glue sits at the top of the text block. Line 404's `\raggedbottom` — unguarded, unlike article's `\if@twoside\else\raggedbottom\fi`, so a `[twoside]` letter gets it too, which `Stylesheet::from_resolved` now also models — puts `\@textbottom`'s `\vskip \z@ \@plus.0001fil` at the bottom. The page's leftover space is shared in the ratio of their stretch, so the top takes 3/8 of it and the first baseline moves down by that much. `crates/class-geometry`'s `letter_oracle` documents this exactly and is why it checks its frame model on page 2 and only bounds page 1: the shift is page building, not a frame length, so it belongs here. Without it every letter's page 1 rode 41.95 bp too high on this fixture — a rigid offset that held *0%* of the page's words outside 0.5 bp however exactly the spacing between them was set. Effect: max |dy| 41.9 → 4.3 bp. ## Where `letter` now is | | dx ≤ 0.5 bp | dy ≤ 0.5 bp | dy ≤ 0.5 after a rigid shift | max \|dy\| | |---|---|---|---|---| | before #316 | — | — | — | the page had no letter structure at all | | #316 + re-pin only | 93.39% | **0.00%** | 26.43% | 186.46 bp | | this PR | 93.39% | 3.96% | **89.43%** | **4.29 bp** | Measured with `tools/visual-oracle/rank.py` against the pinned `fixtures/real-world/letter/reference.pdf`. Line by line the address block is within 0.39 bp, the whole body (17 of the 26 lines) within 1.37 bp, and nothing is worse than 4.29 bp. ## What is still wrong, measured rather than hidden Three residuals, each diagnosed and none of them silent: * **2.92 bp** at the boundary into `\closing`. Its argument goes in a `\parbox` whose first line is a `\strut` and whose height drives the interline glue TeX chooses; the pipeline has no `\parbox` box model to hang that on. * **0.98 bp** at the boundary out of `\opening`'s return address, which pdfLaTeX sets in a `tabular` whose last row carries `\@arstrut`'s `0.3\baselineskip` depth where a text line carries its glyphs'. * Those two make our content 2.91 bp taller than the reference's between the first and last baseline, which feeds back through the `\@texttop` share above and leaves the whole page a uniform ~1.4 bp low. That is why `dy ≤ 0.5` is 3.96% and not ~100%: the structure is right and the total height is not. Fix either box model and the axis should snap. Horizontally, the one remaining item is `\longindentation`: the closing and signature sit at the left margin instead of 180pt in (max |dx| 179.328 bp is exactly that length). `Block::Paragraph` has no per-paragraph left offset or measure, so it cannot be expressed yet; it keeps its typed `unsupported_block` limitation naming the exact offset, as does the `\raggedleft` box whose lines share a *left* edge where `flushright` aligns their right ones. One more difference this PR does not fix and the new test records: this page carries a folio and the reference does not, because `\opening` runs `\thispagestyle{empty}` whenever `\fromaddress` is non-empty (letter.cls 170-176). That is a page-style event the compiler does not emit yet. `crates/render-pipeline/tests/letter_class_geometry.rs` pins all four fixes against the reference's own baselines, with a per-boundary tolerance that is the measured residual rather than a margin chosen to pass — tightening those numbers is the next lane's gate. Verified with `FLASHTEX_FONT_DIRS`/`FLASHTEX_TFM_DIRS` set to the bundled `apps/mac/Fonts`: - `cargo test --release --no-fail-fast -p flashtex-render-pipeline`: **370 passed / 0 failed** (365 + the 5 new letter tests). - amsmath oracle corpus `TOTAL 59/59 within 0.5 bp`; `tabular_oracle: 106/106 fixtures match pdflatex`. - Real-world corpus, all 22 fixtures: page counts checked by counting `/Type /Page` leaf objects in each `reference.pdf` and in each produced `render.pdf` — **22/22** agree. Zero font-FAILURE diagnostics on either producer. HW1 and HW2: 3 pages, 0 errors. - Full `tools/visual-oracle/rank.py` sweep of the corpus in `docs/evidence/visual-oracle-letter-after/`: no fixture regressed, and the 21 non-letter fixtures are untouched by construction — the `\parskip` read is a no-op for their classes and the other two changes are gated on `ClassKind::Letter`. Implementation-Agent: claude-opus-5 render-pipeline/letter lane (agent-a98bd88c4a9d49a22) Commit-Executor: claude-opus-5 direct git (observed Cursor usage limit) Co-authored-by: GoKubar <[email protected]> * vendor: re-pin compiler to main c95977d (now that #316's letter class has landed)
…h-texGH-768) `run_in_heading_command` (`\paragraph`/`\subparagraph`) never called `flush_paragraph`, on the theory that "a run-in head does not start a new paragraph" — true, but it still ends whatever paragraph came before it, the same way real `\@startsection` calls `\par` before laying out the run-in title. Without the flush, text preceding a `\subparagraph` merged into the same paragraph as the heading and the text that runs into it. This matters beyond paragraph counting: `adapter::apply_run_in_heading` in `crates/render-pipeline` only applies the run-in bold/hskip styling to the *leading* items of whatever paragraph it is given. If the compiler doesn't start a fresh paragraph right before the heading, that leading-item scan can't find the title, so the styling silently fails to apply. Measuring a real `pdflatex` render of a `\subparagraph` that follows other body text confirmed this: the title landed on the wrong baseline entirely. `run_in_heading_command` now takes `blocks`/`para` and calls `self.flush_paragraph(blocks, para)`, mirroring `section_command`, but still creates no `Block::Heading` — the braced title still falls through as ordinary body text at the front of the new paragraph, which is what the render pipeline's byte-position matching depends on. Updated the two stale comments that described the old (incomplete) behavior as deliberate. This fix (the flush call, its call-site change, and both comment updates) is Muse lane `headings-oracle` slice 2's work, cherry-picked here unmodified. Added `run_in_heading_flushes_the_preceding_paragraph` (supervisor-authored: the Muse lane's own check for this slice was an uncommitted `/tmp` probe, not a regression test), asserting the compiler now produces two separate `Block::Paragraph`s for `Preceding text.\paragraph{Solution.} Body text.` (and the `\subparagraph` form) — confirmed this test fails against unmodified `main` (1 merged paragraph instead of 2) before the fix, and passes after. Deliberately out of scope here: a companion `render-pipeline` oracle test (`headings_run_in_oracle.rs`, real-pdflatex reference glyph positions for this exact fixture) exists in Muse lane `headings-oracle` but cannot be verified yet — `crates/render-pipeline/vendor/compiler` is a frozen, read-only snapshot pinned to `engine/letter-class-compiler` (PR flash-tex#316) per `vendor/VENDORING.md`, and this fix isn't in that pin. VENDORING.md already schedules a re-pin "the moment flash-tex#316 merges"; that test should be added once mac-render-pipeline (the pin's owner) does that re-pin, not before. Flagging to the Commander/mac-render-pipeline separately rather than touching `vendor/` myself. Tests: `cargo test --lib` in `crates/compiler` — 413 passed, 0 failed, including the 1 new test, re-run independently in a fresh worktree from this exact commit (not just the authoring lane's self-report). Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane headings-oracle, slice 2 — flush fix and comments only) Commit-Executor: daniel-muse-lead (Claude Sonnet — also authored the regression test in this commit) Reviewed-by: daniel-muse-lead (Claude Sonnet) Muse-Lane-Head: 86e4b3e0c644834c3aee21f8005e10b49e375607 Co-authored-by: d-q222 <[email protected]> Co-authored-by: muse-spark-1.3-contributor <[email protected]>
compiler: implement the letter document class
fixtures/real-world/letter/main.texis a correct LaTeX letter. It raisedseven
error[unknown_command]—\signature,\address,\opening,\closing,\encl,\cc,\ps— plus a warning that theletterenvironment was not implemented, and its body was typeset as
undifferentiated prose. Someone writing a perfectly ordinary letter was told
their LaTeX was a typo. It now compiles with zero diagnostics.
What is implemented
\address,\signature,\name,\location,\telephone— letter.cls'spreamble declarations (154-163).
\location/\telephonefeed only thefirstpagefooter, which is not rendered; they are captured so thatwriting them is not an unknown command.
letterenvironment, with its mandatory recipient argument. Eachletter after the first starts a new page (
\newpage, letter.cls 174);\end{letter}'s\pagebreakis deliberately NOT emitted, because\end{document}'s\clearpageabsorbs the last one in real LaTeX and aBlock::PageBreakhere would ship a blank trailing page.\opening— the return-address box, the date, the recipient and thesalutation, with letter.cls's own skips.
\closing— the closing and signature at\longindentation,6\medskipamountapart, with\signaturefalling back to\name.\cc/\encl— labelledcc:/encl:(\ccname/\enclname).\ps,\startbreaks,\stopbreaks,\stopletter,\makelabels.\parskip0.7em (6.99997/7.66498/8.22487ptat 10/11/12pt, as pdflatex prints it),
\parindent0.\pstakes no argument. letter.cls 245 is\newcommand*\ps{\par\startbreaks}, so\ps{P.S. ...}is a paragraph breakfollowed by the brace group typeset as ordinary text — which is exactly what
the committed reference PDF's last line is. Consuming the argument, which
the shape of the call invites, would have silently deleted the author's
sentence.
The two blocks that needed a new representation
Block::LetterBlockwithLetterPart::{ReturnAddress, Recipient, Closing}.No
ParagraphStyleexpresses either of the outer two, and the reference PDFsays why:
not a ragged-left column. All three of its lines start at x = 437.195bp
even though they are different lengths, because
\openingsets them in atabular{l@{}}inside\raggedleft, and\raggedleftmoves the box, notits lines. A
flushrightparagraph would align their right edges instead,which is a visibly different block.
\longindentationis 180pt — half the class's\textwidth(360pt at11pt), assigned when letter.cls loads and never updated by
geometry,which made the measure 469.75502pt here. 251.328bp − 72bp = 180pt exactly.
Half the measure would have put the closing 54.9pt too far right.
Verification against pdflatex
The oracle is the committed
fixtures/real-world/letter/reference.pdf;pdflatex never runs in the product. All 26 of its typeset lines are now
produced, in the same order, with the same left-edge structure. This
compiler's own layout is a fixed 612x792 page with Core-14 Times metrics, so
absolute positions cannot match — but the skips between blocks can, and
six of the nine are exact against pdflatex once the class's
\baselineskipis used:\\*[2\parskip])6\medskipamount)All three misses are the same kind of thing and are reported, not papered
over: TeX sets interline glue from the box above, and two of these blocks
are boxes. The date sits in a
tabularwhose depth is not a text line's(−0.98pt, and again −1.00pt after the closing
\parbox), and\closing's\parboxhas the default[c]position, so it is centred on its baselineand its first line sits 2.93pt higher than an ordinary paragraph's. A flat
line model has no representation for either; naming the exact residuals is
the honest result.
Gates
crates/compilercargo test --release --no-fail-fast: 500 passed, 0failed, against the same-directory control's 489 passed, 0 failed.
11 new tests in
tests/letter_class.rs.built in this same directory from the same base (
5baa9e6e): the onlychange is
letter, 8 diagnostics (7 errors + 1 warning) -> 0, statusrecovered->
ok. Every other fixture is byte-identical.supported_latexdrift gate keeps passing, and its probe was madenon-vacuous first: a letter.cls command is refused by its own message
("defined by the letter document class"), which sailed past the probe's
"is not supported" prefix match, so every new row could have claimed
renders: trueunchallenged. The probe now builds a realletterdocument per command and matches both messages.
The Mac editor learns them too
apps/mac/Sources/FlashTeXMac/Resources/supported-latex.jsonis abyte-identical copy of the compiler's inventory, compared by sha256 in
CompletionTests.testBundledInventoryMatchesTheCompilerand byapps/mac/scripts/sync-supported-latex.sh --checkinmake-app.sh, so thisPR carries the re-synced copy (produced by that script) or it turns that gate
red. The editor therefore starts completing
\opening,\closing,\address,\signature,\cc,\encland theletterenvironment,with the argument shapes listed above.
Worth saying for the inventory as API: every row this adds is one the
compiler really does implement, which the
supported_latexprobe now checksfor real. The inverse -- a row claiming
renders: truefor something thatnever happens -- is a live bug class, not a one-off.
\sgn(a separate PRfrom this lane) is advertised and rendered although no package defines it;
another lane found
\rotatebox,\scalebox,\resizeboxand\reflectboxadvertised although the pipeline never applies them. Sameshape in all three: the inventory is what the editor offers, so a wrong row
is a promise the engine does not keep.
Known gap, deliberately not hidden
\cc/\enclare\@hangfromparboxes; this compiler has no hanging indentoutside
\item, so a wrapped annotation loses the hang. A short one — thecommon case, and the fixture's — is exact. That is a placement difference
within the block, not dropped content, so it does not earn a diagnostic on
every
\cc.Implementation-Agent: claude-opus-5 (engine lane, linux-primary/NixOS).
Commit-Executor: claude-opus-5 direct git (Cursor usage-limit fallback).
Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu