Capture vertical material in vbox and vtop
This commit is contained in:
1 parent
5e9552d785
commit
7ad3c327ec
8 files changed
+99
-14
No files matched your search
@@ -319,8 +319,8 @@ A document-level `\renewcommand{\maketitle}` replaces the engine title block;
|
|||||||
class and package files that replace `\maketitle` are ignored so template
|
class and package files that replace `\maketitle` are ignored so template
|
||||||
title code cannot break the native layout. Known gaps for full document
|
title code cannot break the native layout. Known gaps for full document
|
||||||
classes: `\parbox`/`\minipage` are block-level rather than inline, and
|
classes: `\parbox`/`\minipage` are block-level rather than inline, and
|
||||||
`\vbox` and `\vtop` map to a full-width block box rather than true nested
|
`\vbox`/`\vtop` capture vertical material but do not form an independent
|
||||||
VBox material.
|
natural-width box with its own baseline.
|
||||||
|
|
||||||
`\footnote{...}` captures its content, emits a superscript marker, reserves
|
`\footnote{...}` captures its content, emits a superscript marker, reserves
|
||||||
space on the page where the paragraph ends, and paints the notes with a
|
space on the page where the paragraph ends, and paints the notes with a
|
||||||
@@ -486,7 +486,7 @@ advisory breaks, starred `\vspace`/`\hspace`, `center`, `\hrule`, `\fbox`,
|
|||||||
|
|
||||||
| Area | Implemented | Remaining |
|
| Area | Implemented | Remaining |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| 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` (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 page breaks | table float queue, `\textfraction` |
|
| Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure `[htbp]` placement (deferred top floats, bottom/page/here), table page breaks | table float queue, `\textfraction` |
|
||||||
|
|||||||
@@ -479,6 +479,7 @@ struct Parser {
|
|||||||
inline_boxes: Vec<InlineBoxSpec>,
|
inline_boxes: Vec<InlineBoxSpec>,
|
||||||
minipage: Option<MinipageBuilder>,
|
minipage: Option<MinipageBuilder>,
|
||||||
footnote_capture: Option<Vec<Run>>,
|
footnote_capture: Option<Vec<Run>>,
|
||||||
|
vbox_stack: Vec<(Vec<Block>, Vec<Option<SourceLocation>>)>,
|
||||||
footnote_counter: u32,
|
footnote_counter: u32,
|
||||||
page_decoration_capture: Option<(
|
page_decoration_capture: Option<(
|
||||||
bool,
|
bool,
|
||||||
@@ -538,6 +539,7 @@ impl Parser {
|
|||||||
inline_boxes: Vec::new(),
|
inline_boxes: Vec::new(),
|
||||||
minipage: None,
|
minipage: None,
|
||||||
footnote_capture: None,
|
footnote_capture: None,
|
||||||
|
vbox_stack: Vec::new(),
|
||||||
footnote_counter: 0,
|
footnote_counter: 0,
|
||||||
page_decoration_capture: None,
|
page_decoration_capture: None,
|
||||||
float_placement: String::new(),
|
float_placement: String::new(),
|
||||||
@@ -887,6 +889,22 @@ impl Parser {
|
|||||||
self.framed_box = Some(Vec::new());
|
self.framed_box = Some(Vec::new());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expanded::FrontendEventKind::VBoxStart => {
|
||||||
|
self.flush_paragraph();
|
||||||
|
let blocks = std::mem::take(&mut self.document.blocks);
|
||||||
|
let sources = std::mem::take(&mut self.document.block_sources);
|
||||||
|
self.vbox_stack.push((blocks, sources));
|
||||||
|
}
|
||||||
|
expanded::FrontendEventKind::VBoxEnd => {
|
||||||
|
self.flush_paragraph();
|
||||||
|
let Some((blocks, sources)) = self.vbox_stack.pop() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let inner_blocks = std::mem::replace(&mut self.document.blocks, blocks);
|
||||||
|
let inner_sources = std::mem::replace(&mut self.document.block_sources, sources);
|
||||||
|
self.document.blocks.extend(inner_blocks);
|
||||||
|
self.document.block_sources.extend(inner_sources);
|
||||||
|
}
|
||||||
expanded::FrontendEventKind::ParboxStart { width } => {
|
expanded::FrontendEventKind::ParboxStart { width } => {
|
||||||
self.flush_paragraph();
|
self.flush_paragraph();
|
||||||
self.box_frame = false;
|
self.box_frame = false;
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ pub enum FrontendEventKind {
|
|||||||
ParboxStart {
|
ParboxStart {
|
||||||
width: common::Scaled,
|
width: common::Scaled,
|
||||||
},
|
},
|
||||||
|
VBoxStart,
|
||||||
|
VBoxEnd,
|
||||||
HorizontalRule {
|
HorizontalRule {
|
||||||
height: common::Scaled,
|
height: common::Scaled,
|
||||||
width: Option<common::Scaled>,
|
width: Option<common::Scaled>,
|
||||||
|
|||||||
+7
-5
@@ -12,7 +12,8 @@ geometry-aware `\textwidth`/`\textheight` named length registers; table of
|
|||||||
contents and figure/table lists with dotted leaders; native PDF rectangles; unified pagination;
|
contents and figure/table lists with dotted leaders; native PDF rectangles; unified pagination;
|
||||||
`\centering`/`\raggedright`/`\raggedleft` declarations and environments;
|
`\centering`/`\raggedright`/`\raggedleft` declarations and environments;
|
||||||
chapter headings with chapter-prefixed section numbering and page breaks;
|
chapter headings with chapter-prefixed section numbering and page breaks;
|
||||||
deferred top-float queue for figures; document-level custom `\maketitle`
|
deferred top-float queue for figures; document-level custom `\maketitle`;
|
||||||
|
`\vbox`/`\vtop` vertical-material capture with inline splicing
|
||||||
(`build_positioned_pages` is the only page builder and no separate break
|
(`build_positioned_pages` is the only page builder and no separate break
|
||||||
planner remains).
|
planner remains).
|
||||||
|
|
||||||
@@ -23,8 +24,9 @@ planner remains).
|
|||||||
tune `\textfraction`/`\topfraction`, and support more than a one-page
|
tune `\textfraction`/`\topfraction`, and support more than a one-page
|
||||||
lookahead.
|
lookahead.
|
||||||
|
|
||||||
## 2. True vertical boxes (remaining)
|
## 2. True vertical boxes (partial)
|
||||||
|
|
||||||
- `\vbox`/`\vtop` currently map to a full-width block `\parbox`. A real VBox
|
- `\vbox`/`\vtop` now capture nested vertical material (rules, skips,
|
||||||
needs a vertical-material capture with its own natural width, baseline, and
|
paragraphs) and splice it into the surrounding column. A fully independent
|
||||||
nested line/box children in the positioned renderer.
|
VBox still needs its own natural width, baseline, and nested line/box
|
||||||
|
children in the positioned renderer.
|
||||||
+5
-4
@@ -13,7 +13,7 @@ the source changes; the SVG preview is refreshed per page.
|
|||||||
- Headings: numbered `\section`/`\subsection`/`\subsubsection` and starred
|
- Headings: numbered `\section`/`\subsection`/`\subsubsection` and starred
|
||||||
`\section*` variants (starred headings do not advance the counter).
|
`\section*` variants (starred headings do not advance the counter).
|
||||||
- Box material: `\rule` (raise/width/height), inline framed `\fbox`, block
|
- Box material: `\rule` (raise/width/height), inline framed `\fbox`, block
|
||||||
`\parbox`/`\minipage`, `\vbox`/`\vtop` (full-width block approximation),
|
`\parbox`/`\minipage`, `\vbox`/`\vtop` (vertical material capture),
|
||||||
inline `\mbox`, `\makebox[width][align]`, `\raisebox`, `center`, `\hrule`
|
inline `\mbox`, `\makebox[width][align]`, `\raisebox`, `center`, `\hrule`
|
||||||
with `width`/`height`.
|
with `width`/`height`.
|
||||||
- Fonts: Liberation Serif/Sans/Mono faces, bold/italic/monospace/sans
|
- Fonts: Liberation Serif/Sans/Mono faces, bold/italic/monospace/sans
|
||||||
@@ -64,8 +64,9 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
|||||||
|
|
||||||
## Known approximations / gaps
|
## Known approximations / gaps
|
||||||
|
|
||||||
- Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` map to a
|
- Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` capture
|
||||||
full-width block rather than true nested VBox material.
|
and splice vertical material but do not expose an independent natural width
|
||||||
|
or box baseline.
|
||||||
- Pages: the figure queue only looks one page ahead; tables are not queued and
|
- Pages: the figure queue only looks one page ahead; tables are not queued and
|
||||||
there is no `\textfraction`/`\topfraction` tuning. Pagination is performed by
|
there is no `\textfraction`/`\topfraction` tuning. Pagination is performed by
|
||||||
the positioned renderer; the separate page-break planner was removed.
|
the positioned renderer; the separate page-break planner was removed.
|
||||||
@@ -79,7 +80,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 --offline` (38 tests: 34 compiler
|
- `cargo fmt --check` passes; `cargo test --offline` (39 tests: 35 compiler
|
||||||
integration tests + 4 server tests) covers the three examples, the arXiv
|
integration tests + 4 server tests) covers the three examples, the arXiv
|
||||||
fixture, floats/newpage, page styles and `\thispagestyle`, SVG/PDF output,
|
fixture, floats/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
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ const PRELUDE: &str = r#"
|
|||||||
\def\today{__TEXRRA_TODAY__}
|
\def\today{__TEXRRA_TODAY__}
|
||||||
\def\maketitle{\texrramaketitle}
|
\def\maketitle{\texrramaketitle}
|
||||||
\def\noindent{\texrranoindent}
|
\def\noindent{\texrranoindent}
|
||||||
\def\vbox#1{\parbox{\textwidth}{#1}}
|
|
||||||
\def\vtop#1{\parbox{\textwidth}{#1}}
|
|
||||||
\def\hfill{\hskip0pt plus 1fil\relax}
|
\def\hfill{\hskip0pt plus 1fil\relax}
|
||||||
\def\hfil{\hskip0pt plus 1fil\relax}
|
\def\hfil{\hskip0pt plus 1fil\relax}
|
||||||
\def\allowbreak{\penalty0}
|
\def\allowbreak{\penalty0}
|
||||||
|
|||||||
@@ -3442,6 +3442,31 @@ fn parbox_primitive(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn vbox_primitive(
|
||||||
|
token: token::Token,
|
||||||
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
|
) -> texlang::prelude::Result<()> {
|
||||||
|
let content = read_unexpanded_argument(input, token, "expects box content")?;
|
||||||
|
let inner = strip_braced_tokens(&content).to_vec();
|
||||||
|
write_event(input, token, FrontendEventKind::VBoxStart);
|
||||||
|
let trace_key = token.trace_key();
|
||||||
|
let mut expansion = inner;
|
||||||
|
expansion.push(control_sequence_token(input, "texrravboxend", trace_key));
|
||||||
|
input
|
||||||
|
.as_mut()
|
||||||
|
.expansions_mut()
|
||||||
|
.extend(expansion.into_iter().rev());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vbox_end_primitive(
|
||||||
|
token: token::Token,
|
||||||
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
|
) -> texlang::prelude::Result<()> {
|
||||||
|
write_event(input, token, FrontendEventKind::VBoxEnd);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn fbox_primitive(
|
fn fbox_primitive(
|
||||||
token: token::Token,
|
token: token::Token,
|
||||||
input: &mut vm::ExecutionInput<CompilerState>,
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
@@ -6728,6 +6753,18 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn<Compil
|
|||||||
"texrraframedboxend",
|
"texrraframedboxend",
|
||||||
texlang::command::BuiltIn::new_execution(framed_box_end_primitive),
|
texlang::command::BuiltIn::new_execution(framed_box_end_primitive),
|
||||||
);
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"vbox",
|
||||||
|
texlang::command::BuiltIn::new_execution(vbox_primitive),
|
||||||
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"vtop",
|
||||||
|
texlang::command::BuiltIn::new_execution(vbox_primitive),
|
||||||
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"texrravboxend",
|
||||||
|
texlang::command::BuiltIn::new_execution(vbox_end_primitive),
|
||||||
|
);
|
||||||
built_ins.insert(
|
built_ins.insert(
|
||||||
"texrrarule",
|
"texrrarule",
|
||||||
texlang::command::BuiltIn::new_execution(rule_primitive),
|
texlang::command::BuiltIn::new_execution(rule_primitive),
|
||||||
|
|||||||
@@ -1022,3 +1022,30 @@ Body text.
|
|||||||
);
|
);
|
||||||
assert!(svg.contains("Body"), "body text missing: {svg}");
|
assert!(svg.contains("Body"), "body text missing: {svg}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn vbox_captures_vertical_material() {
|
||||||
|
let source = r#"\documentclass{article}
|
||||||
|
\begin{document}
|
||||||
|
Before.
|
||||||
|
\vbox{%
|
||||||
|
\hrule width 40mm height 2pt
|
||||||
|
\vskip 4pt
|
||||||
|
\hrule width 20mm height 2pt
|
||||||
|
}
|
||||||
|
After.
|
||||||
|
\end{document}
|
||||||
|
"#;
|
||||||
|
let value = fresh_preview(source, "vbox.tex");
|
||||||
|
assert_eq!(value["status"], "ok", "{}", value["message"]);
|
||||||
|
let svg = page_svg(&value, 0);
|
||||||
|
assert_eq!(
|
||||||
|
svg.matches("fill=\"#000000\"/>").count(),
|
||||||
|
2,
|
||||||
|
"expected two rules in vbox: {svg}"
|
||||||
|
);
|
||||||
|
assert!(svg.contains("width=\"40.15"), "wide rule missing: {svg}");
|
||||||
|
assert!(svg.contains("width=\"20.07"), "narrow rule missing: {svg}");
|
||||||
|
assert!(svg.contains(">Before.</text>"), "text before vbox missing");
|
||||||
|
assert!(svg.contains(">After</text>"), "text after vbox missing");
|
||||||
|
}
|
||||||
Reference in new issue
Block a user