diff --git a/README.md b/README.md index 5cdf829..c4b004b 100644 --- a/README.md +++ b/README.md @@ -354,8 +354,8 @@ full-width `\hline` and `booktabs` rules. Spanning cells, partial `\cline` rules and multi-page table headers are not implemented. Figures honor `[htbp]` placement hints (`[t]` is deferred to the top of the next page, `[b]` to the page bottom, `[p]` to a float page, `[h]` stays in the flow); tables honor -`[t]` by deferring the caption and rows to the next page and `[p]` with a -float page. `\label`, `\ref`, and `\cite` +`[t]` by deferring the caption and rows to the next page, `[b]` at the page +bottom, and `[p]` with a float page. `\label`, `\ref`, and `\cite` resolve section, figure, table, and bibliography numbers. `\bibliography{file}` reads a local `.bib` file (the `.bib` extension is optional) and formats common author/editor, title, journal, booktitle, volume, number, pages, publisher, @@ -493,7 +493,7 @@ advisory breaks, starred `\vspace`/`\hspace`, `center`, `\hrule`, `\fbox`, | Boxes | `\rule`, inline framed `\fbox`, block `\parbox`/`\minipage`, `\vbox`/`\vtop` (vertical material capture), inline `\mbox`/`\makebox`, `\raisebox`, `center`, `\hrule` | independent VBox natural width/baseline | | Fonts | serif/sans/mono faces, bold/italic/mono/sans declarations, group scoping, true scaled small caps | — | | Paragraphs | Knuth-Plass breaking, TeX hyphenation, justification, `\centering`/`\raggedright`/`\raggedleft`, `\parindent` (17pt default), `\hfill`/`\hfil` | — | -| Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure `[htbp]` placement (deferred top floats, bottom/page/here), table `[t]`/`[p]` queues | table bottom/float-page queues, `\textfraction` | +| Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure `[htbp]` placement (deferred top floats, bottom/page/here), table `[t]`/`[b]`/`[p]` placement | table float-page queues, `\textfraction` | | Contents | `\tableofcontents`, `\listoffigures`, `\listoftables` generated from numbered headings and captions, dotted leaders, page numbers resolved after pagination | per-chapter book/report contents | | Pages | A4/Letter/... page sizes, margins/geometry, automatic pagination, `\newpage`, `\pagebreak`, plain/fancy page styles, `\thispagestyle`, fancyhdr L/C/R headers and footers | — | | Classes/packages | built-in + local classes, option protocol, local package options, base font sizes 10/11/12pt, chapter headings and numbering, chapter page breaks, document-level custom `\maketitle` | class-specific formatting beyond chapter breaks | diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 55aeaf3..bd239ea 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -21,9 +21,9 @@ planner remains). - Figures with `[t]` are queued and placed at the top of the next page while following text fills the current page. Tables with `[t]` queue their caption - and rows the same way. Remaining work: queue table `[b]`/float-page - placements, tune `\textfraction`/`\topfraction`, and support more than a - one-page lookahead. + and rows the same way, and `[b]` pushes them to the page bottom. Remaining + work: queue table float-page placements, tune + `\textfraction`/`\topfraction`, and support more than a one-page lookahead. ## 2. True vertical boxes (partial) diff --git a/docs/STATUS.md b/docs/STATUS.md index 8168a9f..fa23e9e 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -29,8 +29,9 @@ the source changes; the SVG preview is refreshed per page. Figures honor `[htbp]` hints: `[t]` is queued and placed at the top of the next page while following text fills the current page, `[b]` sits at the page bottom, `[p]` takes a float page, and `[h]` stays in the text flow. Tables - queue `[t]` captions and rows at the top of the next page and take a float - page for `[p]`; table `[b]`/`[h]` stay in the text flow. Page styles: + queue `[t]` captions and rows at the top of the next page, sit at the page + bottom for `[b]`, take a float page for `[p]`, and stay in the text flow for + `[h]`. 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` @@ -68,8 +69,8 @@ See `docs/ROADMAP.md` for concrete implementation plans. - Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` capture and splice vertical material but do not expose an independent natural width or box baseline. -- Pages: the figure/table queues only look one page ahead; table `[b]` and - float-page queues are not implemented and there is no +- Pages: the figure/table queues only look one page ahead; table float-page + queues are not implemented and there is no `\textfraction`/`\topfraction` tuning. Pagination is performed by the positioned renderer; the separate page-break planner was removed. - Notes: footnotes inside captions, floats, or arbitrary boxes are not @@ -82,9 +83,9 @@ See `docs/ROADMAP.md` for concrete implementation plans. - `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 --offline` (40 tests: 36 compiler +- `cargo fmt --check` passes; `cargo test --offline` (41 tests: 37 compiler integration tests + 4 server tests) covers the three examples, the arXiv - fixture, figure/table floats, newpage, page styles and `\thispagestyle`, SVG/PDF output, + fixture, figure/table floats (top and bottom), 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). diff --git a/src/rust_typeset/pdf/layout.rs b/src/rust_typeset/pdf/layout.rs index 4f49864..6169887 100644 --- a/src/rust_typeset/pdf/layout.rs +++ b/src/rust_typeset/pdf/layout.rs @@ -1927,6 +1927,77 @@ pub(super) fn build_positioned_pages( let total_height = caption_height .saturating_add(caption_gap) .saturating_add(table_height); + let table_bottom = placement.contains('b') + && !placement.contains('h') + && !placement.contains('t') + && !placement.contains('p') + && pages.last().is_some_and(|page| !page.items.is_empty()) + && total_height <= page_goal; + if table_bottom { + let Some(table) = table else { + return None; + }; + let mut y = page_goal.saturating_sub(total_height); + for line in caption_lines { + pages + .last_mut() + .expect("the page list starts with one page") + .items + .push(PositionedPageItem::Line(PositionedLine { + anchor: PageAnchor { + block: block_index, + line: 0, + }, + content: line.content, + y, + x: 0, + centered: true, + ragged: false, + })); + y = y.saturating_add(line.height); + } + if caption_height > 0 { + y = y.saturating_add(caption_gap); + } + let PositionedTable { + rows: table_rows, + column_count, + rules: table_rules, + .. + } = table; + for (row_index, row) in table_rows.into_iter().enumerate() { + let row_height = row.height; + let mut row_rules = HashSet::new(); + if row_index == 0 && table_rules.contains(&0) { + row_rules.insert(0); + } + if table_rules.contains(&(row_index + 1)) { + row_rules.insert(1); + } + pages + .last_mut() + .expect("the page list starts with one page") + .items + .push(PositionedPageItem::Table { + anchor: PageAnchor { + block: block_index, + line: 0, + }, + element: PositionedTable { + rows: vec![row], + column_count, + rules: row_rules, + height: row_height, + }, + y, + }); + y = y.saturating_add(row_height); + } + cursor = page_goal; + pending_gap = paragraph_gap + (normal_line_height as f64 * 0.15).round() as i64; + has_previous_block = true; + continue; + } let table_top = placement.contains('t') && !placement.contains('h') && !placement.contains('p') diff --git a/tests/typeset.rs b/tests/typeset.rs index 817b824..ea59076 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -845,6 +845,39 @@ After table. ); } +#[test] +fn bottom_table_sits_at_the_page_bottom() { + let source = r#"\documentclass{article} +\begin{document} +Before table. + +\begin{table}[b] +\caption{Bottom table} +\begin{tabular}{ll} +Alpha & Beta \\ +Gamma & Delta \\ +\end{tabular} +\end{table} + +After table. +\end{document} +"#; + let value = fresh_preview(source, "table-bottom.tex"); + assert_eq!(value["status"], "ok", "{}", value["message"]); + assert_eq!(pages(&value).len(), 2, "bottom table should end page 1"); + let first = page_svg(&value, 0); + assert!(first.contains(">Alpha"), "bottom table missing"); + let alpha_y = text_y(&first, "Alpha"); + assert!( + alpha_y > 220.0, + "bottom table was not pushed to the page bottom: {alpha_y}" + ); + assert!( + page_svg(&value, 1).contains("After"), + "text after a bottom table should continue on the next page" + ); +} + #[test] fn table_of_contents_lists_numbered_sections_and_pages() { let source = r"\documentclass{article}