Skip to content

compiler: \thanks as symbol footnotes, report/book \chapter counters, minipage footnote marks (reconstruction of #153 on the current expansion code) - #281

Merged
GoKubar merged 2 commits into
mainfrom
rebase/153-footnotes-2-compiler
Sep 14, 2026
Merged

GoKubar merged 2 commits into
mainfrom
rebase/153-footnotes-2-compiler

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Reconstruction of #153 on current main. Supersedes #153 — its branch is untouched. Stacked on #259 (the port of #142, which #153 included).

\thanks as symbol footnotes, report/book \chapter counters, minipage footnote marks. Construct list unchanged from #153.

Why this is a reconstruction and not a rebase

#153's branch predates main's crate::expansion refactor. Cherry-picking it produces eight conflicts, and one of them is a 297-line block whose HEAD side is empty — it drags declare_math_operator, define_macro, expand_macro and expand_macro_word back in, none of which exist on main any more. That is what the integration lane hit when it marked #153 "aborted as non-trivial". Only chapter() from that hunk is kept.

Where the chapter prefix lives now

#153 carried its own equation_counter/figure_counter fields and a within_chapter(value) helper that formatted "{chapter}.{value}" by hand. main has replaced those fields with crate::xref::Counters, which already models \@addtoreset and \the<name> — and whose define_body_counters doc already anticipated this ("report/book register equation/figure/table within chapter on top of this").

So: Counters::report() registers them, chapter() stops zeroing them one at a time (step resets every descendant), and within_chapter is gone — each of its four call sites is now just counters.step(...).

The one thing the counter table could not express

report.cls prints

\renewcommand\thefigure{\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@figure}

and the guard is load-bearing: a figure in the front matter, before any \chapter, is 1, not 0.1. \counterwithin (Counters::counter_within) writes the prefix unconditionally — correct for \numberwithin, wrong here — while \thesection in report.cls genuinely is unconditional, so the two cases differ.

Piece therefore gains IfPositive(counter, then) (\ifnum \c@<counter>>\z@ <then>\fi) and format grows a format_pieces arm to recurse into it. The new report_prefixes_body_counters_with_the_chapter_only_once_one_exists covers the front-matter case, the reset, the unconditional \thesection, and \setcounter{chapter}{0} putting the guard back (book.cls's front matter).

footnote is not in the counter table yet, so \@addtoreset{footnote}{chapter} stays an explicit assignment in chapter(), as in #153.

Gates, measured on this tree

gate main @ 5e6c65be #259 (base) this branch
crates/compiler cargo test --release --no-fail-fast 485 passed, 0 failed 487, 0 failed 494 passed, 0 failed

The delta over #259 is this PR's own 6 footnote_counters tests plus the new xref one. #153's own six tests pass unmodified against the reconstruction, which is the real check that the intent survived: symbol order and counter restart, the tenth \thanks, report chapter resets with section/equation labels and \chapter*, book figure numbers, article without chapters, and minipage \alph marks.

The supported inventory is unchanged (the \chapter arm is class-guarded), and tests/supported_latex.rs's drift gate passes without regeneration.

Independently validated downstream

The footnotes oracle in #282 probes the vendored compiler (compiler_has_footnote_counters()) and gates seven fixtures only when it has this change. With vendor/compiler re-pinned to this branch the probe passes and all seven are asserted against pdflatex — including 14-multipar-note, which on main is 116 of 438 words. That is a stronger check on this PR than its own unit tests.


Rebased and re-measured against main 5e6c65be. main moved 53 commits during this work, including changes to parser.rs, typeset.rs and mathtex.rs; every number in this PR is from the final tree, not the earlier base.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

… minipage footnote marks

- **`\thanks`** in `\title`/`\author`/`\date` is no longer stripped with a
  warning. It becomes an `Inline::Footnote` at its place in the title block,
  numbered `\@fnsymbol\c@footnote` in title -> authors -> date order:
  * † ‡ § ¶ ‖ ** †† ‡‡. A tenth is diagnosed (`\@ctrerr`) and printed in
  arabic. `\maketitle` ends with `\setcounter{footnote}{0}`.
- **`\chapter[*][short]{title}`** is parsed when the class is report or book.
  The numbered form steps `chapter`, which resets `section` (and below),
  `figure`, `table` and `equation`; `\thesection`, `Figure N:` captions and
  equation numbers then print `<chapter>.<n>`. The title is kept as a bold
  paragraph, because the renderer owns the head's layout. article still
  diagnoses `\chapter`; the arm is class-guarded, so the supported inventory
  is unchanged.
- **minipage**: `\footnote`/`\footnotetext` inside use `mpfootnote`, zeroed at
  each `\begin{minipage}`, with `\alph` marks. `\footnotemark` keeps
  `footnote`. The environment itself is still unimplemented.

`Inline::Footnote`/`Block` shapes are unchanged, so no renderer match changes.

Reconstructed from PR #153 rather than rebased: that branch predates main's
`crate::expansion` refactor, and its `parser.rs` hunks drag four functions
main has since deleted or moved (`declare_math_operator`, `define_macro`,
`expand_macro`, `expand_macro_word`) back in behind one 297-line conflict
whose other side is empty. Only `chapter()` from that hunk is kept.

The substantive change is where the chapter prefix lives. #153 carried its own
`equation_counter`/`figure_counter` fields and a `within_chapter(value)` helper
that formatted `"{chapter}.{value}"` by hand; main has replaced those fields
with `crate::xref::Counters`, which already models `\@addtoreset` and
`\the<name>`. So `report()` registers `equation`/`figure`/`table` as reset by
`chapter`, `chapter()` stops zeroing them one by one (`step` resets every
descendant), and `within_chapter` is gone -- each of its four call sites is
just `counters.step(...)` now.

That needed one thing the counter table could not express. report.cls prints

    \renewcommand\thefigure{\ifnum \c@chapter>\z@ \thechapter.\fi \@Arabic\c@figure}

and the guard is load-bearing: a figure in the front matter, before any
`\chapter`, is "1", not "0.1". `\counterwithin` (`Counters::counter_within`)
writes the prefix unconditionally, which is right for `\numberwithin` and
wrong here, and `\thesection` in report.cls is indeed unconditional. So `Piece`
gains `IfPositive(counter, then)` -- `\ifnum \c@<counter>>\z@ <then>\fi` -- and
`format` grows a `format_pieces` arm to recurse into it. New
`report_prefixes_body_counters_with_the_chapter_only_once_one_exists` covers
the front-matter case, the reset, the unconditional `\thesection`, and
`\setcounter{chapter}{0}` putting the guard back (book.cls's front matter).

`footnote` is not in the counter table yet, so `\@addtoreset{footnote}{chapter}`
stays an explicit assignment in `chapter()`, as in #153.

crates/compiler `cargo test --release --no-fail-fast`: 478 passed, 0 failed.
main (eea975c) on the same tree is 469 and this branch's base (the #142 port)
is 471, so the delta is this PR's own 6 `footnote_counters` tests plus the new
`xref` one. #153's own six pass unmodified against the reconstruction.

Rebase-Agent: Claude Opus 5 (engine lane, linux-primary)
Implementation-Agent: Claude Opus 5 (subagent kabir-claude footnotes, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar
GoKubar force-pushed the rebase/142-footnote-long-argument branch from f99c8a8 to 13da5d9 Compare September 14, 2026 02:22
@GoKubar
GoKubar force-pushed the rebase/153-footnotes-2-compiler branch from 0024942 to b50d84b Compare September 14, 2026 02:22
@GoKubar
GoKubar changed the base branch from rebase/142-footnote-long-argument to main September 14, 2026 06:12
… into integ/281-test

# Conflicts:
#	crates/compiler/src/parser.rs
@GoKubar
GoKubar merged commit 2ad5b9b into main Sep 14, 2026
17 of 20 checks passed
GoKubar added a commit that referenced this pull request Sep 14, 2026
… regions (#343)

Closes the second silent-content-loss bug: every \footnote on a page containing a float was dropped. floatpage::paginate now charges the longtable region's reserve alongside the insertion state, so a continuation foot and a note compete for one page as in TeX, and settle_inserts is shared rather than duplicated. Measured end to end: hyperref-toc, lab-report and lmodern-report were silently dropping footnote text on main and now set it; 17 of 23 documents byte-identical. Footnotes oracle 19/24 -> 35/39, float-notes 10/10, tabular still 106/106, amsmath 59/59, HW1/HW2 unchanged. Carries the vendor re-pin, which un-inerts #259, #281, the ~/\nobreakspace fix, text-mode spacing in macro bodies and the amsmath limit operators.
@GoKubar
GoKubar deleted the rebase/153-footnotes-2-compiler branch September 16, 2026 04:17
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