diff --git a/README.md b/README.md index d9bd346..3d23485 100644 --- a/README.md +++ b/README.md @@ -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 title code cannot break the native layout. Known gaps for full document 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 material. +`\vbox`/`\vtop` capture vertical material but do not form an independent +natural-width box with its own baseline. `\footnote{...}` captures its content, emits a superscript marker, reserves 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 | | --- | --- | --- | -| 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 | — | | 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` | diff --git a/crates/texrra-core/src/document_parser.rs b/crates/texrra-core/src/document_parser.rs index c013803..7c72bb1 100644 --- a/crates/texrra-core/src/document_parser.rs +++ b/crates/texrra-core/src/document_parser.rs @@ -479,6 +479,7 @@ struct Parser { inline_boxes: Vec, minipage: Option, footnote_capture: Option>, + vbox_stack: Vec<(Vec, Vec>)>, footnote_counter: u32, page_decoration_capture: Option<( bool, @@ -538,6 +539,7 @@ impl Parser { inline_boxes: Vec::new(), minipage: None, footnote_capture: None, + vbox_stack: Vec::new(), footnote_counter: 0, page_decoration_capture: None, float_placement: String::new(), @@ -887,6 +889,22 @@ impl Parser { 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 } => { self.flush_paragraph(); self.box_frame = false; diff --git a/crates/texrra-core/src/expanded.rs b/crates/texrra-core/src/expanded.rs index 414c47c..d58b94b 100644 --- a/crates/texrra-core/src/expanded.rs +++ b/crates/texrra-core/src/expanded.rs @@ -93,6 +93,8 @@ pub enum FrontendEventKind { ParboxStart { width: common::Scaled, }, + VBoxStart, + VBoxEnd, HorizontalRule { height: common::Scaled, width: Option, diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 05c7815..bef53ec 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -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; `\centering`/`\raggedright`/`\raggedleft` declarations and environments; 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 planner remains). @@ -23,8 +24,9 @@ planner remains). tune `\textfraction`/`\topfraction`, and support more than a one-page lookahead. -## 2. True vertical boxes (remaining) +## 2. True vertical boxes (partial) -- `\vbox`/`\vtop` currently map to a full-width block `\parbox`. A real VBox - needs a vertical-material capture with its own natural width, baseline, and - nested line/box children in the positioned renderer. +- `\vbox`/`\vtop` now capture nested vertical material (rules, skips, + paragraphs) and splice it into the surrounding column. A fully independent + VBox still needs its own natural width, baseline, and nested line/box + children in the positioned renderer. diff --git a/docs/STATUS.md b/docs/STATUS.md index f4f6d9d..7df1168 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -13,7 +13,7 @@ the source changes; the SVG preview is refreshed per page. - Headings: numbered `\section`/`\subsection`/`\subsubsection` and starred `\section*` variants (starred headings do not advance the counter). - 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` with `width`/`height`. - 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 -- Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` map to a - full-width block rather than true nested VBox material. +- 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 queue only looks one page ahead; tables are not queued and there is no `\textfraction`/`\topfraction` tuning. Pagination is performed by 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 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 fixture, floats/newpage, page styles and `\thispagestyle`, SVG/PDF output, project API, static frontend assets, path traversal, the legacy diff --git a/src/rust_typeset/frontend.rs b/src/rust_typeset/frontend.rs index cb31120..61299bb 100644 --- a/src/rust_typeset/frontend.rs +++ b/src/rust_typeset/frontend.rs @@ -28,8 +28,6 @@ const PRELUDE: &str = r#" \def\today{__TEXRRA_TODAY__} \def\maketitle{\texrramaketitle} \def\noindent{\texrranoindent} -\def\vbox#1{\parbox{\textwidth}{#1}} -\def\vtop#1{\parbox{\textwidth}{#1}} \def\hfill{\hskip0pt plus 1fil\relax} \def\hfil{\hskip0pt plus 1fil\relax} \def\allowbreak{\penalty0} diff --git a/src/rust_typeset/texlang_adapter.rs b/src/rust_typeset/texlang_adapter.rs index 3c29237..4779fea 100644 --- a/src/rust_typeset/texlang_adapter.rs +++ b/src/rust_typeset/texlang_adapter.rs @@ -3442,6 +3442,31 @@ fn parbox_primitive( Ok(()) } +fn vbox_primitive( + token: token::Token, + input: &mut vm::ExecutionInput, +) -> 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, +) -> texlang::prelude::Result<()> { + write_event(input, token, FrontendEventKind::VBoxEnd); + Ok(()) +} + fn fbox_primitive( token: token::Token, input: &mut vm::ExecutionInput, @@ -6728,6 +6753,18 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn").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 before vbox missing"); + assert!(svg.contains(">After"), "text after vbox missing"); +}