Place bottom tables at the page bottom
This commit is contained in:
1 parent
6658a155fc
commit
e7bcdf6c53
5 files changed
+117
-12
No files matched your search
@@ -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]`
|
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
|
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
|
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
|
`[t]` by deferring the caption and rows to the next page, `[b]` at the page
|
||||||
float page. `\label`, `\ref`, and `\cite`
|
bottom, and `[p]` with a float page. `\label`, `\ref`, and `\cite`
|
||||||
resolve section, figure, table, and bibliography numbers. `\bibliography{file}`
|
resolve section, figure, table, and bibliography numbers. `\bibliography{file}`
|
||||||
reads a local `.bib` file (the `.bib` extension is optional) and formats common
|
reads a local `.bib` file (the `.bib` extension is optional) and formats common
|
||||||
author/editor, title, journal, booktitle, volume, number, pages, publisher,
|
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 |
|
| 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 | — |
|
| 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` | — |
|
| 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 |
|
| 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 | — |
|
| 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 |
|
| 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 |
|
||||||
|
|||||||
+3
-3
@@ -21,9 +21,9 @@ planner remains).
|
|||||||
|
|
||||||
- Figures with `[t]` are queued and placed at the top of the next page while
|
- 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
|
following text fills the current page. Tables with `[t]` queue their caption
|
||||||
and rows the same way. Remaining work: queue table `[b]`/float-page
|
and rows the same way, and `[b]` pushes them to the page bottom. Remaining
|
||||||
placements, tune `\textfraction`/`\topfraction`, and support more than a
|
work: queue table float-page placements, tune
|
||||||
one-page lookahead.
|
`\textfraction`/`\topfraction`, and support more than a one-page lookahead.
|
||||||
|
|
||||||
## 2. True vertical boxes (partial)
|
## 2. True vertical boxes (partial)
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -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
|
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
|
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
|
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
|
queue `[t]` captions and rows at the top of the next page, sit at the page
|
||||||
page for `[p]`; table `[b]`/`[h]` stay in the text flow. Page styles:
|
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}`,
|
default `plain` page numbers, `\pagestyle{empty|plain|fancy}`,
|
||||||
`\thispagestyle`, fancyhdr `\fancyhead`/`\fancyfoot` (L/C/R) and
|
`\thispagestyle`, fancyhdr `\fancyhead`/`\fancyfoot` (L/C/R) and
|
||||||
`\lhead`/`\chead`/`\rhead`/`\lfoot`/`\cfoot`/`\rfoot`, with `\thepage`
|
`\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
|
- Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` capture
|
||||||
and splice vertical material but do not expose an independent natural width
|
and splice vertical material but do not expose an independent natural width
|
||||||
or box baseline.
|
or box baseline.
|
||||||
- Pages: the figure/table queues only look one page ahead; table `[b]` and
|
- Pages: the figure/table queues only look one page ahead; table float-page
|
||||||
float-page queues are not implemented and there is no
|
queues are not implemented and there is no
|
||||||
`\textfraction`/`\topfraction` tuning. Pagination is performed by the
|
`\textfraction`/`\topfraction` tuning. Pagination is performed by the
|
||||||
positioned renderer; the separate page-break planner was removed.
|
positioned renderer; the separate page-break planner was removed.
|
||||||
- Notes: footnotes inside captions, floats, or arbitrary boxes are not
|
- 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
|
- `examples/hello.tex`, `examples/boxes.tex`, `examples/compat.tex` compile to
|
||||||
one A4 page each; the arXiv template project compiles to 3 Letter pages.
|
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
|
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
|
project API, static frontend assets, path traversal, the legacy
|
||||||
`/texrra` endpoint, and page-hash cache stability.
|
`/texrra` endpoint, and page-hash cache stability.
|
||||||
- Warm preview: hello ~0.6ms, arXiv ~13ms (release server, page layout cached).
|
- Warm preview: hello ~0.6ms, arXiv ~13ms (release server, page layout cached).
|
||||||
@@ -1927,6 +1927,77 @@ pub(super) fn build_positioned_pages(
|
|||||||
let total_height = caption_height
|
let total_height = caption_height
|
||||||
.saturating_add(caption_gap)
|
.saturating_add(caption_gap)
|
||||||
.saturating_add(table_height);
|
.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')
|
let table_top = placement.contains('t')
|
||||||
&& !placement.contains('h')
|
&& !placement.contains('h')
|
||||||
&& !placement.contains('p')
|
&& !placement.contains('p')
|
||||||
|
|||||||
@@ -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</text>"), "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]
|
#[test]
|
||||||
fn table_of_contents_lists_numbered_sections_and_pages() {
|
fn table_of_contents_lists_numbered_sections_and_pages() {
|
||||||
let source = r"\documentclass{article}
|
let source = r"\documentclass{article}
|
||||||
|
|||||||
Reference in new issue
Block a user