Add footnote insertion area and thanks
This commit is contained in:
1 parent
5fa301fdcd
commit
1da46c61d6
11 files changed
+486
-28
No files matched your search
@@ -286,20 +286,23 @@ every line is centered without justification (natural spaces), so
|
|||||||
|
|
||||||
`\rule[raise]{width}{height}` is rendered as a filled rectangle in both the
|
`\rule[raise]{width}{height}` is rendered as a filled rectangle in both the
|
||||||
PDF and the SVG preview, including raised and dropped rules; a zero-thickness
|
PDF and the SVG preview, including raised and dropped rules; a zero-thickness
|
||||||
rule reserves space without painting ink. `\fbox{...}` is a block-level framed
|
rule reserves space without painting ink. `\fbox{...}` is an inline framed box:
|
||||||
box: the content is measured as a single line, wrapped in 3pt padding and a
|
the content is measured as a single unbreakable unit, wrapped in 3pt padding and
|
||||||
0.4pt frame, placed in the vertical flow, and painted in both the PDF and the
|
a 0.4pt frame, and painted in both the PDF and the SVG preview.
|
||||||
SVG preview. Inline `\fbox` in the middle of a paragraph starts a new block
|
|
||||||
(this is a stepping stone towards full inline boxes).
|
|
||||||
|
|
||||||
Known gaps for full document classes: base font-size class options
|
Known gaps for full document classes: base font-size class options
|
||||||
(`10pt`/`11pt`/`12pt`) are parsed but the engine still uses 11pt; footnotes and
|
(`10pt`/`11pt`/`12pt`) are parsed but the engine still uses 11pt;
|
||||||
`\thanks` are dropped,
|
|
||||||
custom `\maketitle` implementations are ignored (the engine title layout is
|
custom `\maketitle` implementations are ignored (the engine title layout is
|
||||||
used), `\parbox`/`\minipage` are block-level rather than inline, `\vbox` and
|
used), `\parbox`/`\minipage` are block-level rather than inline, `\vbox` and
|
||||||
`\vtop` map to a full-width block box rather than true nested VBox material, and
|
`\vtop` map to a full-width block box rather than true nested VBox material, and
|
||||||
the abstract prints as body text without an "Abstract" heading.
|
the abstract prints as body text without an "Abstract" heading.
|
||||||
|
|
||||||
|
`\footnote{...}` captures its content, emits a superscript marker, reserves
|
||||||
|
space on the page where the paragraph ends, and paints the notes with a
|
||||||
|
separator rule at the bottom of the page. `\thanks{...}` is a footnote in the
|
||||||
|
title or author block and is painted at the bottom of the first page. Footnotes
|
||||||
|
inside captions, floats, or arbitrary boxes are not collected yet.
|
||||||
|
|
||||||
Basic `\input{file}` imports are read relative to the main `.tex` file. Imported
|
Basic `\input{file}` imports are read relative to the main `.tex` file. Imported
|
||||||
files participate in source mapping and frontend cache invalidation. Local style
|
files participate in source mapping and frontend cache invalidation. Local style
|
||||||
files and `.bib` files are tracked the same way; editing any of them refreshes
|
files and `.bib` files are tracked the same way; editing any of them refreshes
|
||||||
@@ -461,7 +464,7 @@ advisory breaks, starred `\vspace`/`\hspace`, `center`, `\hrule`, `\fbox`,
|
|||||||
| Boxes | `\rule`, inline framed `\fbox`, block `\parbox`/`\minipage`, `\vbox`/`\vtop` (as full-width block), inline `\mbox`/`\makebox`, `\raisebox`, `center`, `\hrule` | true nested VBox material |
|
| Boxes | `\rule`, inline framed `\fbox`, block `\parbox`/`\minipage`, `\vbox`/`\vtop` (as full-width block), inline `\mbox`/`\makebox`, `\raisebox`, `center`, `\hrule` | true nested VBox material |
|
||||||
| 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, `\parindent` (17pt default), `\hfill`/`\hfil` | `\raggedright`/`\raggedleft` |
|
| Paragraphs | Knuth-Plass breaking, TeX hyphenation, justification, centering, `\parindent` (17pt default), `\hfill`/`\hfil` | `\raggedright`/`\raggedleft` |
|
||||||
| Notes/floats | — | footnote insertion area, figure/table floats |
|
| Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks` | figure/table floats |
|
||||||
| Pages | A4/Letter/... page sizes, margins/geometry, automatic pagination, `\newpage`, `\pagebreak` | headers/footers (`fancyhdr`), unified planner/renderer |
|
| Pages | A4/Letter/... page sizes, margins/geometry, automatic pagination, `\newpage`, `\pagebreak` | headers/footers (`fancyhdr`), unified planner/renderer |
|
||||||
| Classes/packages | built-in + local classes, option protocol, local package options | base font-size options (10/11/12pt) |
|
| Classes/packages | built-in + local classes, option protocol, local package options | base font-size options (10/11/12pt) |
|
||||||
| Live preview | incremental paragraph/page caches, page-hash diffing, SVG refresh | — |
|
| Live preview | incremental paragraph/page caches, page-hash diffing, SVG refresh | — |
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ impl Default for PageSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Footnote {
|
||||||
|
pub number: u32,
|
||||||
|
pub runs: Vec<Run>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DocumentModel {
|
pub struct DocumentModel {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
@@ -68,6 +74,7 @@ pub struct DocumentModel {
|
|||||||
pub block_sources: Vec<Option<SourceLocation>>,
|
pub block_sources: Vec<Option<SourceLocation>>,
|
||||||
pub labels: HashMap<String, String>,
|
pub labels: HashMap<String, String>,
|
||||||
pub citations: HashMap<String, usize>,
|
pub citations: HashMap<String, usize>,
|
||||||
|
pub footnotes: Vec<Footnote>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DocumentModel {
|
impl Default for DocumentModel {
|
||||||
@@ -85,6 +92,7 @@ impl Default for DocumentModel {
|
|||||||
block_sources: Vec::new(),
|
block_sources: Vec::new(),
|
||||||
labels: HashMap::new(),
|
labels: HashMap::new(),
|
||||||
citations: HashMap::new(),
|
citations: HashMap::new(),
|
||||||
|
footnotes: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,6 +241,7 @@ pub struct Run {
|
|||||||
pub rule: Option<RuleBox>,
|
pub rule: Option<RuleBox>,
|
||||||
pub box_run: Option<InlineBox>,
|
pub box_run: Option<InlineBox>,
|
||||||
pub y_offset: Option<common::Scaled>,
|
pub y_offset: Option<common::Scaled>,
|
||||||
|
pub footnote_number: Option<u32>,
|
||||||
pub unresolved_reference: Option<UnresolvedReference>,
|
pub unresolved_reference: Option<UnresolvedReference>,
|
||||||
pub bold: bool,
|
pub bold: bool,
|
||||||
pub italic: bool,
|
pub italic: bool,
|
||||||
@@ -254,6 +263,7 @@ impl Run {
|
|||||||
rule: None,
|
rule: None,
|
||||||
box_run: None,
|
box_run: None,
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
footnote_number: None,
|
||||||
unresolved_reference: None,
|
unresolved_reference: None,
|
||||||
bold: false,
|
bold: false,
|
||||||
italic: false,
|
italic: false,
|
||||||
|
|||||||
@@ -420,6 +420,8 @@ struct Parser {
|
|||||||
box_width: Option<common::Scaled>,
|
box_width: Option<common::Scaled>,
|
||||||
inline_boxes: Vec<InlineBoxSpec>,
|
inline_boxes: Vec<InlineBoxSpec>,
|
||||||
minipage: Option<MinipageBuilder>,
|
minipage: Option<MinipageBuilder>,
|
||||||
|
footnote_capture: Option<Vec<Run>>,
|
||||||
|
footnote_counter: u32,
|
||||||
centered: Option<Vec<Run>>,
|
centered: Option<Vec<Run>>,
|
||||||
current_source: Option<SourceLocation>,
|
current_source: Option<SourceLocation>,
|
||||||
paragraph_source: Option<SourceLocation>,
|
paragraph_source: Option<SourceLocation>,
|
||||||
@@ -461,6 +463,8 @@ impl Parser {
|
|||||||
box_width: None,
|
box_width: None,
|
||||||
inline_boxes: Vec::new(),
|
inline_boxes: Vec::new(),
|
||||||
minipage: None,
|
minipage: None,
|
||||||
|
footnote_capture: None,
|
||||||
|
footnote_counter: 0,
|
||||||
centered: None,
|
centered: None,
|
||||||
current_source: None,
|
current_source: None,
|
||||||
paragraph_source: None,
|
paragraph_source: None,
|
||||||
@@ -613,6 +617,7 @@ impl Parser {
|
|||||||
&& self.centered.is_none()
|
&& self.centered.is_none()
|
||||||
&& self.inline_boxes.is_empty()
|
&& self.inline_boxes.is_empty()
|
||||||
&& self.minipage.is_none()
|
&& self.minipage.is_none()
|
||||||
|
&& self.footnote_capture.is_none()
|
||||||
&& !self.bold
|
&& !self.bold
|
||||||
&& !self.italic
|
&& !self.italic
|
||||||
&& !self.monospace
|
&& !self.monospace
|
||||||
@@ -699,6 +704,43 @@ impl Parser {
|
|||||||
self.document.show_title = true;
|
self.document.show_title = true;
|
||||||
self.suppress_indent = true;
|
self.suppress_indent = true;
|
||||||
}
|
}
|
||||||
|
expanded::FrontendEventKind::FootnoteStart => {
|
||||||
|
self.footnote_capture = Some(Vec::new());
|
||||||
|
}
|
||||||
|
expanded::FrontendEventKind::FootnoteEnd => {
|
||||||
|
if let Some(mut runs) = self.footnote_capture.take() {
|
||||||
|
trim_run_end(&mut runs);
|
||||||
|
self.footnote_counter += 1;
|
||||||
|
let number = self.footnote_counter;
|
||||||
|
self.document
|
||||||
|
.footnotes
|
||||||
|
.push(crate::document::Footnote { number, runs });
|
||||||
|
let bold = self.bold;
|
||||||
|
let italic = self.italic;
|
||||||
|
let monospace = self.monospace;
|
||||||
|
let sans = self.sans;
|
||||||
|
let small_caps = self.small_caps;
|
||||||
|
let marker = Run {
|
||||||
|
text: superscript_number(number),
|
||||||
|
math: None,
|
||||||
|
kern: None,
|
||||||
|
glue: None,
|
||||||
|
penalty: None,
|
||||||
|
rule: None,
|
||||||
|
box_run: None,
|
||||||
|
y_offset: None,
|
||||||
|
footnote_number: Some(number),
|
||||||
|
unresolved_reference: None,
|
||||||
|
bold,
|
||||||
|
italic,
|
||||||
|
monospace,
|
||||||
|
sans,
|
||||||
|
small_caps,
|
||||||
|
paragraph_indent: false,
|
||||||
|
};
|
||||||
|
self.target_runs().push(marker);
|
||||||
|
}
|
||||||
|
}
|
||||||
expanded::FrontendEventKind::InlineBoxStart {
|
expanded::FrontendEventKind::InlineBoxStart {
|
||||||
width,
|
width,
|
||||||
align,
|
align,
|
||||||
@@ -741,6 +783,8 @@ impl Parser {
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
};
|
};
|
||||||
self.target_runs().push(run);
|
self.target_runs().push(run);
|
||||||
}
|
}
|
||||||
@@ -1019,6 +1063,8 @@ impl Parser {
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1159,6 +1205,8 @@ impl Parser {
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1194,6 +1242,8 @@ impl Parser {
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1234,6 +1284,8 @@ impl Parser {
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1284,10 +1336,22 @@ impl Parser {
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_runs(&mut self) -> &mut Vec<Run> {
|
fn target_runs(&mut self) -> &mut Vec<Run> {
|
||||||
|
if self.footnote_capture.is_some() {
|
||||||
|
return self
|
||||||
|
.footnote_capture
|
||||||
|
.as_mut()
|
||||||
|
.expect("footnote capture was checked");
|
||||||
|
}
|
||||||
|
self.target_runs_without_footnote()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn target_runs_without_footnote(&mut self) -> &mut Vec<Run> {
|
||||||
let paragraph_target = self.inline_boxes.is_empty()
|
let paragraph_target = self.inline_boxes.is_empty()
|
||||||
&& self.minipage.is_none()
|
&& self.minipage.is_none()
|
||||||
&& self.centered.is_none()
|
&& self.centered.is_none()
|
||||||
@@ -1403,11 +1467,13 @@ impl Parser {
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paragraph_break(&mut self) {
|
fn paragraph_break(&mut self) {
|
||||||
if self.minipage.is_some() {
|
if self.footnote_capture.is_some() || self.minipage.is_some() {
|
||||||
self.append_text(" ");
|
self.append_text(" ");
|
||||||
} else if !self.lists.is_empty() || self.table.is_some() {
|
} else if !self.lists.is_empty() || self.table.is_some() {
|
||||||
self.append_text(" ");
|
self.append_text(" ");
|
||||||
@@ -1740,6 +1806,7 @@ fn indent_run(indent: common::Scaled) -> Run {
|
|||||||
sans: false,
|
sans: false,
|
||||||
small_caps: false,
|
small_caps: false,
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
footnote_number: None,
|
||||||
paragraph_indent: true,
|
paragraph_indent: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1756,6 +1823,26 @@ fn strip_paragraph_indent(runs: &mut Vec<Run>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn superscript_number(number: u32) -> String {
|
||||||
|
number
|
||||||
|
.to_string()
|
||||||
|
.chars()
|
||||||
|
.map(|digit| match digit {
|
||||||
|
'0' => '⁰',
|
||||||
|
'1' => '¹',
|
||||||
|
'2' => '²',
|
||||||
|
'3' => '³',
|
||||||
|
'4' => '⁴',
|
||||||
|
'5' => '⁵',
|
||||||
|
'6' => '⁶',
|
||||||
|
'7' => '⁷',
|
||||||
|
'8' => '⁸',
|
||||||
|
'9' => '⁹',
|
||||||
|
other => other,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn append_run(
|
fn append_run(
|
||||||
runs: &mut Vec<Run>,
|
runs: &mut Vec<Run>,
|
||||||
mut text: String,
|
mut text: String,
|
||||||
@@ -1808,6 +1895,8 @@ fn append_run(
|
|||||||
paragraph_indent: false,
|
paragraph_indent: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ pub enum FrontendEventKind {
|
|||||||
frame: bool,
|
frame: bool,
|
||||||
},
|
},
|
||||||
InlineBoxEnd,
|
InlineBoxEnd,
|
||||||
|
FootnoteStart,
|
||||||
|
FootnoteEnd,
|
||||||
MetadataStart(MetadataField),
|
MetadataStart(MetadataField),
|
||||||
MetadataEnd(MetadataField),
|
MetadataEnd(MetadataField),
|
||||||
DisplayMathStart,
|
DisplayMathStart,
|
||||||
|
|||||||
+5
-14
@@ -5,19 +5,10 @@ are still missing. Each item names the files/functions to touch.
|
|||||||
|
|
||||||
Completed: paragraph indentation (`\parindent`) and `\hfill`/`\hfil`; sans
|
Completed: paragraph indentation (`\parindent`) and `\hfill`/`\hfil`; sans
|
||||||
family and true scaled small caps; inline box geometry (`\fbox`, `\makebox`,
|
family and true scaled small caps; inline box geometry (`\fbox`, `\makebox`,
|
||||||
`\raisebox`), `\minipage`, and `\vbox`/`\vtop` block approximations (see
|
`\raisebox`), `\minipage`, `\vbox`/`\vtop` block approximations, and
|
||||||
`docs/STATUS.md`).
|
footnotes/`\thanks` (see `docs/STATUS.md`).
|
||||||
|
|
||||||
## 1. Footnotes
|
## 1. Floats
|
||||||
|
|
||||||
- Parser: capture `\footnote{...}`/`\thanks{...}` into a per-paragraph list
|
|
||||||
with a number marker run (superscript approximation via smaller raised text
|
|
||||||
once y offsets exist).
|
|
||||||
- Page model: add a footnote area to the page goal; the planner must reduce the
|
|
||||||
text height and place footnotes with a separator rule at the bottom.
|
|
||||||
- Paint footnotes as normal positioned lines after the page's content.
|
|
||||||
|
|
||||||
## 2. Floats
|
|
||||||
|
|
||||||
- Classify figure/table blocks as floats with `[htbp]` placement hints.
|
- Classify figure/table blocks as floats with `[htbp]` placement hints.
|
||||||
- Planner: maintain pending floats and try top/bottom/page placements; keep
|
- Planner: maintain pending floats and try top/bottom/page placements; keep
|
||||||
@@ -25,13 +16,13 @@ family and true scaled small caps; inline box geometry (`\fbox`, `\makebox`,
|
|||||||
- Renderer: place deferred floats at the saved slots; page keys must include
|
- Renderer: place deferred floats at the saved slots; page keys must include
|
||||||
float placement decisions.
|
float placement decisions.
|
||||||
|
|
||||||
## 3. Page styles / headers-footers
|
## 2. Page styles / headers-footers
|
||||||
|
|
||||||
- `DocumentModel` fields for header/footer runs and `\pagestyle`/`\thispagestyle`.
|
- `DocumentModel` fields for header/footer runs and `\pagestyle`/`\thispagestyle`.
|
||||||
- Paint headers/footers in the page margins in both PDF and SVG; page numbers
|
- Paint headers/footers in the page margins in both PDF and SVG; page numbers
|
||||||
need a page index placeholder resolved at paint time.
|
need a page index placeholder resolved at paint time.
|
||||||
|
|
||||||
## 4. Unified pagination
|
## 3. Unified pagination
|
||||||
|
|
||||||
- Extract the current duplicated planner (`build_page_break_plan`) and renderer
|
- Extract the current duplicated planner (`build_page_break_plan`) and renderer
|
||||||
(`build_positioned_pages`) vertical logic into one page builder returning an
|
(`build_positioned_pages`) vertical logic into one page builder returning an
|
||||||
|
|||||||
+8
-3
@@ -24,6 +24,8 @@ the source changes; the SVG preview is refreshed per page.
|
|||||||
`\addtolength`/`\noindent` aware), and `\hfill`/`\hfil` infinite glue.
|
`\addtolength`/`\noindent` aware), and `\hfill`/`\hfil` infinite glue.
|
||||||
- Pages: A4/A5/B5/Letter/Legal/Executive, landscape, geometry margins and
|
- Pages: A4/A5/B5/Letter/Legal/Executive, landscape, geometry margins and
|
||||||
text block, automatic pagination, `\newpage`/`\pagebreak`.
|
text block, automatic pagination, `\newpage`/`\pagebreak`.
|
||||||
|
- 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,
|
- Classes/packages: built-in classes, local `.cls`/`.sty`, paper options,
|
||||||
`\DeclareOption`/`\ProcessOptions`/`\ExecuteOptions`/option passing.
|
`\DeclareOption`/`\ProcessOptions`/`\ExecuteOptions`/option passing.
|
||||||
- Compatibility: spacing macros (quad/qquad/thin/en/med/thick, `\vspace*`,
|
- Compatibility: spacing macros (quad/qquad/thin/en/med/thick, `\vspace*`,
|
||||||
@@ -40,8 +42,11 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
|||||||
|
|
||||||
- Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` map to a
|
- Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` map to a
|
||||||
full-width block rather than true nested VBox material.
|
full-width block rather than true nested VBox material.
|
||||||
- Pages: no footnote insertion area, no floats, no headers/footers (fancyhdr
|
- Pages: no floats, no headers/footers (fancyhdr commands are accepted as
|
||||||
commands are accepted as no-ops), planner and renderer are separate.
|
no-ops), planner and renderer are 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.
|
||||||
- Lengths: `\textwidth`/`\textheight`/`\linewidth`/`\columnwidth` are fixed
|
- Lengths: `\textwidth`/`\textheight`/`\linewidth`/`\columnwidth` are fixed
|
||||||
A4-content defaults, not geometry-aware.
|
A4-content defaults, not geometry-aware.
|
||||||
- Miscellaneous: `\tableofcontents`/list commands are no-ops; base font-size
|
- Miscellaneous: `\tableofcontents`/list commands are no-ops; base font-size
|
||||||
@@ -52,7 +57,7 @@ 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 --workspace` (21 tests) covers the three
|
- `cargo fmt --check` passes; `cargo test --workspace` (23 tests) covers the three
|
||||||
examples, the arXiv fixture, SVG/PDF output, project API, static frontend
|
examples, the arXiv fixture, SVG/PDF output, project API, static frontend
|
||||||
assets, path traversal, the legacy `/texrra` endpoint, and page-hash cache
|
assets, path traversal, the legacy `/texrra` endpoint, and page-hash cache
|
||||||
stability.
|
stability.
|
||||||
|
|||||||
@@ -371,8 +371,7 @@ const PRELUDE: &str = r#"
|
|||||||
\def\fnsymbol#1{*}
|
\def\fnsymbol#1{*}
|
||||||
\def\thefootnote{*}
|
\def\thefootnote{*}
|
||||||
\def\footnoterule{}
|
\def\footnoterule{}
|
||||||
\def\footnote#1{}
|
\def\thanks#1{\footnote{#1}}
|
||||||
\def\thanks#1{}
|
|
||||||
\def\@title{}
|
\def\@title{}
|
||||||
\def\@author{}
|
\def\@author{}
|
||||||
\def\@date{}
|
\def\@date{}
|
||||||
|
|||||||
@@ -2570,6 +2570,8 @@ pub(super) fn render_pdf(
|
|||||||
small_caps: false,
|
small_caps: false,
|
||||||
|
|
||||||
y_offset: None,
|
y_offset: None,
|
||||||
|
|
||||||
|
footnote_number: None,
|
||||||
}];
|
}];
|
||||||
document.push(paragraph(
|
document.push(paragraph(
|
||||||
&heading,
|
&heading,
|
||||||
|
|||||||
@@ -1075,6 +1075,22 @@ pub(super) fn build_page_break_plan(
|
|||||||
paragraph_cache,
|
paragraph_cache,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
let reserve = footnote_reserve(
|
||||||
|
model,
|
||||||
|
block_index,
|
||||||
|
content_width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
paragraph_cache,
|
||||||
|
);
|
||||||
|
if reserve > 0 {
|
||||||
|
nodes.push(VerticalNode::Kern(reserve));
|
||||||
|
}
|
||||||
nodes.push(VerticalNode::fixed_glue(
|
nodes.push(VerticalNode::fixed_glue(
|
||||||
(normal_line_height as f64 * 0.35).round() as i64,
|
(normal_line_height as f64 * 0.35).round() as i64,
|
||||||
));
|
));
|
||||||
@@ -1540,6 +1556,96 @@ pub(super) fn build_page_break_plan(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn footnote_marker(number: u32) -> String {
|
||||||
|
number
|
||||||
|
.to_string()
|
||||||
|
.chars()
|
||||||
|
.map(|digit| match digit {
|
||||||
|
'0' => '⁰',
|
||||||
|
'1' => '¹',
|
||||||
|
'2' => '²',
|
||||||
|
'3' => '³',
|
||||||
|
'4' => '⁴',
|
||||||
|
'5' => '⁵',
|
||||||
|
'6' => '⁶',
|
||||||
|
'7' => '⁷',
|
||||||
|
'8' => '⁸',
|
||||||
|
'9' => '⁹',
|
||||||
|
other => other,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn footnote_numbers_for_block(model: &DocumentModel, block_index: usize) -> Vec<u32> {
|
||||||
|
let Some(Block::Paragraph(runs)) = model.blocks.get(block_index) else {
|
||||||
|
return Vec::new();
|
||||||
|
};
|
||||||
|
let mut numbers = Vec::new();
|
||||||
|
for run in runs {
|
||||||
|
if let Some(number) = run.footnote_number
|
||||||
|
&& !numbers.contains(&number)
|
||||||
|
{
|
||||||
|
numbers.push(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
numbers
|
||||||
|
}
|
||||||
|
|
||||||
|
fn footnote_note_runs(model: &DocumentModel, number: u32) -> Option<Vec<Run>> {
|
||||||
|
let note = model.footnotes.iter().find(|note| note.number == number)?;
|
||||||
|
let mut runs = vec![Run::plain(format!("{} ", footnote_marker(number)))];
|
||||||
|
runs.extend(note.runs.iter().cloned());
|
||||||
|
Some(runs)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn footnote_reserve(
|
||||||
|
model: &DocumentModel,
|
||||||
|
block_index: usize,
|
||||||
|
content_width_mm: f64,
|
||||||
|
metrics: &BoxFontMetrics,
|
||||||
|
font_cache: &fonts::FontCache,
|
||||||
|
cjk_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
mono_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
sans_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
math_metrics: &math_font::MathFontMetrics,
|
||||||
|
math_layout: &MathLayoutEnvironment,
|
||||||
|
cache: &mut ParagraphLayoutCache,
|
||||||
|
) -> i64 {
|
||||||
|
let numbers = footnote_numbers_for_block(model, block_index);
|
||||||
|
if numbers.is_empty() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
let width_mm = (content_width_mm - 8.0).max(20.0);
|
||||||
|
let mut height = 0_i64;
|
||||||
|
for number in numbers {
|
||||||
|
let Some(runs) = footnote_note_runs(model, number) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
for line in measure_positioned_lines(
|
||||||
|
&runs,
|
||||||
|
9,
|
||||||
|
width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
) {
|
||||||
|
height = height.saturating_add(line.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if height == 0 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
height
|
||||||
|
.saturating_add(i64::from(scaled_points(2.0).0))
|
||||||
|
.saturating_add(i64::from(scaled_points(1.0).0))
|
||||||
|
}
|
||||||
|
|
||||||
fn measure_positioned_lines(
|
fn measure_positioned_lines(
|
||||||
runs: &[Run],
|
runs: &[Run],
|
||||||
font_size: u8,
|
font_size: u8,
|
||||||
@@ -1677,6 +1783,133 @@ fn push_vertical_line(
|
|||||||
nodes.push(VerticalNode::Penalty(penalty));
|
nodes.push(VerticalNode::Penalty(penalty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn append_page_footnotes(
|
||||||
|
model: &DocumentModel,
|
||||||
|
pages: &mut [PositionedPage],
|
||||||
|
block_end_pages: &HashMap<usize, usize>,
|
||||||
|
page_goal: i64,
|
||||||
|
content_width_mm: f64,
|
||||||
|
metrics: &BoxFontMetrics,
|
||||||
|
font_cache: &fonts::FontCache,
|
||||||
|
cjk_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
mono_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
sans_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
math_metrics: &math_font::MathFontMetrics,
|
||||||
|
math_layout: &MathLayoutEnvironment,
|
||||||
|
cache: &mut ParagraphLayoutCache,
|
||||||
|
) {
|
||||||
|
let mut referenced = Vec::new();
|
||||||
|
for block in block_end_pages.keys() {
|
||||||
|
for number in footnote_numbers_for_block(model, *block) {
|
||||||
|
if !referenced.contains(&number) {
|
||||||
|
referenced.push(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let title_numbers: Vec<u32> = model
|
||||||
|
.footnotes
|
||||||
|
.iter()
|
||||||
|
.map(|note| note.number)
|
||||||
|
.filter(|number| !referenced.contains(number))
|
||||||
|
.collect();
|
||||||
|
let mut page_blocks: HashMap<usize, Vec<usize>> = HashMap::new();
|
||||||
|
for (block, page) in block_end_pages {
|
||||||
|
page_blocks.entry(*page).or_default().push(*block);
|
||||||
|
}
|
||||||
|
if !title_numbers.is_empty() {
|
||||||
|
page_blocks.entry(0).or_default().push(usize::MAX);
|
||||||
|
}
|
||||||
|
for blocks in page_blocks.values_mut() {
|
||||||
|
blocks.sort_unstable();
|
||||||
|
}
|
||||||
|
let width_mm = (content_width_mm - 8.0).max(20.0);
|
||||||
|
let separator = i64::from(scaled_points(0.4).0);
|
||||||
|
for (page_index, blocks) in page_blocks {
|
||||||
|
let Some(page) = pages.get_mut(page_index) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let mut note_lines = Vec::new();
|
||||||
|
let mut seen = Vec::new();
|
||||||
|
for block in blocks {
|
||||||
|
let numbers = if block == usize::MAX {
|
||||||
|
title_numbers.clone()
|
||||||
|
} else {
|
||||||
|
footnote_numbers_for_block(model, block)
|
||||||
|
};
|
||||||
|
for number in numbers {
|
||||||
|
if seen.contains(&number) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen.push(number);
|
||||||
|
let Some(runs) = footnote_note_runs(model, number) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
note_lines.extend(measure_positioned_lines(
|
||||||
|
&runs,
|
||||||
|
9,
|
||||||
|
width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if note_lines.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let total: i64 = note_lines.iter().map(|line| line.height).sum();
|
||||||
|
let separator_gap = i64::from(scaled_points(2.0).0);
|
||||||
|
let mut y = page_goal
|
||||||
|
.saturating_sub(total)
|
||||||
|
.saturating_sub(separator_gap);
|
||||||
|
let separator_width = millimeters_to_scaled(content_width_mm * 0.35);
|
||||||
|
let rule_line = text_layout::LineBox {
|
||||||
|
width: common::Scaled(separator_width as i32),
|
||||||
|
items: vec![text_layout::LineItem::Rule {
|
||||||
|
width: common::Scaled(separator_width as i32),
|
||||||
|
raise: common::Scaled::ZERO,
|
||||||
|
height: common::Scaled(separator as i32),
|
||||||
|
y_offset: common::Scaled::ZERO,
|
||||||
|
}],
|
||||||
|
pre_display_size: None,
|
||||||
|
};
|
||||||
|
page.items.push(PositionedPageItem::Line(PositionedLine {
|
||||||
|
anchor: PageAnchor {
|
||||||
|
block: usize::MAX,
|
||||||
|
line: 0,
|
||||||
|
},
|
||||||
|
content: PositionedLineContent::Text {
|
||||||
|
line: rule_line,
|
||||||
|
font_size: 9,
|
||||||
|
},
|
||||||
|
y,
|
||||||
|
x: 0,
|
||||||
|
centered: false,
|
||||||
|
}));
|
||||||
|
y = y.saturating_add(separator_gap);
|
||||||
|
for line in note_lines {
|
||||||
|
let height = line.height;
|
||||||
|
page.items.push(PositionedPageItem::Line(PositionedLine {
|
||||||
|
anchor: PageAnchor {
|
||||||
|
block: usize::MAX,
|
||||||
|
line: line.line_index,
|
||||||
|
},
|
||||||
|
content: line.content,
|
||||||
|
y,
|
||||||
|
x: millimeters_to_scaled(8.0),
|
||||||
|
centered: false,
|
||||||
|
}));
|
||||||
|
y = y.saturating_add(height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn build_positioned_pages(
|
pub(super) fn build_positioned_pages(
|
||||||
model: &DocumentModel,
|
model: &DocumentModel,
|
||||||
source_dir: &Path,
|
source_dir: &Path,
|
||||||
@@ -1700,6 +1933,7 @@ pub(super) fn build_positioned_pages(
|
|||||||
let heading_gap = (normal_line_height as f64 * 0.65).round() as i64;
|
let heading_gap = (normal_line_height as f64 * 0.65).round() as i64;
|
||||||
let page_goal = scaled_points(content_height_mm * PDF_POINTS_PER_INCH / 25.4).0 as i64;
|
let page_goal = scaled_points(content_height_mm * PDF_POINTS_PER_INCH / 25.4).0 as i64;
|
||||||
let mut pages = vec![PositionedPage::default()];
|
let mut pages = vec![PositionedPage::default()];
|
||||||
|
let mut block_end_pages: HashMap<usize, usize> = HashMap::new();
|
||||||
let mut cursor = 0_i64;
|
let mut cursor = 0_i64;
|
||||||
let mut has_previous_block = false;
|
let mut has_previous_block = false;
|
||||||
let mut pending_gap = 0_i64;
|
let mut pending_gap = 0_i64;
|
||||||
@@ -1837,6 +2071,23 @@ pub(super) fn build_positioned_pages(
|
|||||||
}));
|
}));
|
||||||
cursor = cursor.saturating_add(line_height);
|
cursor = cursor.saturating_add(line_height);
|
||||||
}
|
}
|
||||||
|
let reserve = footnote_reserve(
|
||||||
|
model,
|
||||||
|
block_index,
|
||||||
|
content_width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
);
|
||||||
|
if reserve > 0 {
|
||||||
|
cursor = cursor.saturating_add(reserve);
|
||||||
|
block_end_pages.insert(block_index, pages.len().saturating_sub(1));
|
||||||
|
}
|
||||||
pending_gap = paragraph_gap;
|
pending_gap = paragraph_gap;
|
||||||
has_previous_block = true;
|
has_previous_block = true;
|
||||||
}
|
}
|
||||||
@@ -2506,6 +2757,21 @@ pub(super) fn build_positioned_pages(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append_page_footnotes(
|
||||||
|
model,
|
||||||
|
&mut pages,
|
||||||
|
&block_end_pages,
|
||||||
|
page_goal,
|
||||||
|
content_width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
);
|
||||||
pages.retain(|page| !page.items.is_empty());
|
pages.retain(|page| !page.items.is_empty());
|
||||||
Some(pages)
|
Some(pages)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3022,6 +3022,35 @@ fn raisebox_primitive(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn footnote_primitive(
|
||||||
|
token: token::Token,
|
||||||
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
|
) -> texlang::prelude::Result<()> {
|
||||||
|
let content = read_unexpanded_argument(input, token, "expects footnote content")?;
|
||||||
|
let inner = strip_braced_tokens(&content).to_vec();
|
||||||
|
write_event(input, token, FrontendEventKind::FootnoteStart);
|
||||||
|
let trace_key = token.trace_key();
|
||||||
|
let mut expansion = inner;
|
||||||
|
expansion.push(control_sequence_token(
|
||||||
|
input,
|
||||||
|
"texrrafootnoteend",
|
||||||
|
trace_key,
|
||||||
|
));
|
||||||
|
input
|
||||||
|
.as_mut()
|
||||||
|
.expansions_mut()
|
||||||
|
.extend(expansion.into_iter().rev());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn footnote_end_primitive(
|
||||||
|
token: token::Token,
|
||||||
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
|
) -> texlang::prelude::Result<()> {
|
||||||
|
write_event(input, token, FrontendEventKind::FootnoteEnd);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn inline_box_end_primitive(
|
fn inline_box_end_primitive(
|
||||||
token: token::Token,
|
token: token::Token,
|
||||||
input: &mut vm::ExecutionInput<CompilerState>,
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
@@ -6380,6 +6409,14 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn<Compil
|
|||||||
"texrrainlineboxend",
|
"texrrainlineboxend",
|
||||||
texlang::command::BuiltIn::new_execution(inline_box_end_primitive),
|
texlang::command::BuiltIn::new_execution(inline_box_end_primitive),
|
||||||
);
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"footnote",
|
||||||
|
texlang::command::BuiltIn::new_execution(footnote_primitive),
|
||||||
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"texrrafootnoteend",
|
||||||
|
texlang::command::BuiltIn::new_execution(footnote_end_primitive),
|
||||||
|
);
|
||||||
built_ins.insert(
|
built_ins.insert(
|
||||||
"fbox",
|
"fbox",
|
||||||
texlang::command::BuiltIn::new_execution(fbox_primitive),
|
texlang::command::BuiltIn::new_execution(fbox_primitive),
|
||||||
|
|||||||
@@ -461,3 +461,57 @@ This is a minipage with enough text to wrap across several lines and demonstrate
|
|||||||
assert!(svg.contains(">vbox</text>"), "vbox content missing");
|
assert!(svg.contains(">vbox</text>"), "vbox content missing");
|
||||||
assert!(svg.contains(">bold</text>"), "vbox styled content missing");
|
assert!(svg.contains(">bold</text>"), "vbox styled content missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn footnotes_are_placed_at_the_page_bottom() {
|
||||||
|
let source = r#"\documentclass{article}
|
||||||
|
\begin{document}
|
||||||
|
First paragraph.\footnote{This is a footnote.}
|
||||||
|
|
||||||
|
Second paragraph.\footnote{Another note.}
|
||||||
|
|
||||||
|
Third paragraph.
|
||||||
|
\end{document}
|
||||||
|
"#;
|
||||||
|
let value = fresh_preview(source, "footnotes.tex");
|
||||||
|
assert_eq!(value["status"], "ok", "{}", value["message"]);
|
||||||
|
let svg = page_svg(&value, 0);
|
||||||
|
assert!(svg.contains("¹"), "footnote marker missing");
|
||||||
|
assert!(svg.contains("²"), "second footnote marker missing");
|
||||||
|
let body = text_y(&svg, "First");
|
||||||
|
let note = text_y(&svg, "This");
|
||||||
|
assert!(
|
||||||
|
note > body + 150.0,
|
||||||
|
"footnote is not at the page bottom: {note}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
text_x(&svg, "This") > 7.5 && text_x(&svg, "This") < 11.0,
|
||||||
|
"footnote indent missing"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
svg.contains("fill=\"#000000\"/>"),
|
||||||
|
"footnote separator rule missing"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn thanks_creates_a_title_footnote() {
|
||||||
|
let source = r#"\documentclass{article}
|
||||||
|
\title{A Title\thanks{Thanks to the test suite.}}
|
||||||
|
\author{Author\thanks{Author affiliation.}}
|
||||||
|
\begin{document}
|
||||||
|
\maketitle
|
||||||
|
Body text.
|
||||||
|
\end{document}
|
||||||
|
"#;
|
||||||
|
let value = fresh_preview(source, "thanks.tex");
|
||||||
|
assert_eq!(value["status"], "ok", "{}", value["message"]);
|
||||||
|
let svg = page_svg(&value, 0);
|
||||||
|
assert!(svg.contains("¹"), "title thanks marker missing");
|
||||||
|
assert!(svg.contains("²"), "author thanks marker missing");
|
||||||
|
let note = text_y(&svg, "Thanks");
|
||||||
|
assert!(
|
||||||
|
note > 200.0,
|
||||||
|
"title footnote is not at the page bottom: {note}"
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user