Add float placement and page headers/footers

This commit is contained in:
gloamxun committed 2026-10-19 13:41:29 +08:00
1 parent 1da46c61d6
commit ed1da06685
16 files changed
+974 -90

No files matched your search

+26 -18
View File
@@ -5,26 +5,34 @@ are still missing. Each item names the files/functions to touch.
Completed: paragraph indentation (`\parindent`) and `\hfill`/`\hfil`; sans
family and true scaled small caps; inline box geometry (`\fbox`, `\makebox`,
`\raisebox`), `\minipage`, `\vbox`/`\vtop` block approximations, and
footnotes/`\thanks` (see `docs/STATUS.md`).
`\raisebox`), `\minipage`, `\vbox`/`\vtop` block approximations;
footnotes/`\thanks`; figure/table `[htbp]` placement approximations; and page
styles (plain/fancy, `\thispagestyle`, fancyhdr headers/footers, `\thepage`).
## 1. Floats
- Classify figure/table blocks as floats with `[htbp]` placement hints.
- Planner: maintain pending floats and try top/bottom/page placements; keep
reading order for text and defer floats when they do not fit.
- Renderer: place deferred floats at the saved slots; page keys must include
float placement decisions.
## 2. Page styles / headers-footers
- `DocumentModel` fields for header/footer runs and `\pagestyle`/`\thispagestyle`.
- Paint headers/footers in the page margins in both PDF and SVG; page numbers
need a page index placeholder resolved at paint time.
## 3. Unified pagination
## 1. Unified pagination
- Extract the current duplicated planner (`build_page_break_plan`) and renderer
(`build_positioned_pages`) vertical logic into one page builder returning an
ordered list of placed items, then use it for both page-break decisions and
final painting.
final painting. This is the prerequisite for a true deferred float queue.
## 2. Lengths and base font size
- Emit geometry changes into named length registers so `\textwidth`,
`\textheight`, `\linewidth`, and `\columnwidth` track `\geometry` and
paper-size options instead of fixed A4 defaults.
- Thread the `10pt`/`11pt`/`12pt` class option through the parser, line metrics,
headings, and the PDF so the base size changes consistently.
## 3. Table of contents and lists
- Record section/figure/table entries while parsing, then generate
`\tableofcontents`, `\listoffigures`, and `\listoftables` blocks with
resolved page numbers after pagination.
## 4. PDF painting and title blocks
- Paint rules and frames as native PDF rectangles (`printpdf` operators)
instead of 1x1 image XObjects.
- Let a document-level `\renewcommand{\maketitle}` contribute a real title
block once the engine's title model can run box material.
+16 -8
View File
@@ -23,7 +23,12 @@ the source changes; the SVG preview is refreshed per page.
centering, first-line `\parindent` (17pt default, group-scoped, `\setlength`/
`\addtolength`/`\noindent` aware), and `\hfill`/`\hfil` infinite glue.
- Pages: A4/A5/B5/Letter/Legal/Executive, landscape, geometry margins and
text block, automatic pagination, `\newpage`/`\pagebreak`.
text block, automatic pagination, `\newpage`/`\pagebreak`; figures/tables
honor `[htbp]` hints with top/bottom/page/here approximations. Page styles:
default `plain` page numbers, `\pagestyle{empty|plain|fancy}`,
`\thispagestyle`, fancyhdr `\fancyhead`/`\fancyfoot` (L/C/R) and
`\lhead`/`\chead`/`\rhead`/`\lfoot`/`\cfoot`/`\rfoot`, with `\thepage`
resolved at paint time.
- Notes: `\footnote{...}` page-bottom insertion area with separator rule,
superscript markers, and title/author `\thanks`.
- Classes/packages: built-in classes, local `.cls`/`.sty`, paper options,
@@ -42,8 +47,9 @@ See `docs/ROADMAP.md` for concrete implementation plans.
- Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` map to a
full-width block rather than true nested VBox material.
- Pages: no floats, no headers/footers (fancyhdr commands are accepted as
no-ops), planner and renderer are separate.
- Pages: float placement is immediate rather than a deferred float queue
(no `\textfraction` tuning, no reordering around later text); planner and
renderer are still separate.
- Notes: footnotes inside captions, floats, or arbitrary boxes are not
collected; the insertion area currently follows the page where the paragraph
ends rather than the exact reference line.
@@ -51,14 +57,16 @@ See `docs/ROADMAP.md` for concrete implementation plans.
A4-content defaults, not geometry-aware.
- Miscellaneous: `\tableofcontents`/list commands are no-ops; base font-size
class options (10/11/12pt) are parsed but unused; rules are painted with 1x1
images in PDF.
images in PDF; a document-level `\renewcommand{\maketitle}` is ignored in
favor of the engine title block.
## Verification
- `examples/hello.tex`, `examples/boxes.tex`, `examples/compat.tex` compile to
one A4 page each; the arXiv template project compiles to 3 Letter pages.
- `cargo fmt --check` passes; `cargo test --workspace` (23 tests) covers the three
examples, the arXiv fixture, SVG/PDF output, project API, static frontend
assets, path traversal, the legacy `/texrra` endpoint, and page-hash cache
stability.
- `cargo fmt --check` passes; `cargo test --offline` (26 tests: 22 compiler
integration tests + 4 server tests) covers the three examples, the arXiv
fixture, floats/newpage, page styles and `\thispagestyle`, SVG/PDF output,
project API, static frontend assets, path traversal, the legacy
`/texrra` endpoint, and page-hash cache stability.
- Warm preview: hello ~0.6ms, arXiv ~13ms (release server, page layout cached).