diff --git a/README.md b/README.md index 04e7661..d9bd346 100644 --- a/README.md +++ b/README.md @@ -315,10 +315,12 @@ a 0.4pt frame, and painted in both the PDF and the SVG preview. Base font-size class options `10pt`, `11pt`, and `12pt` now set the body size and propagate through headings, title material, lists, tables, block boxes, footnotes, and the default paragraph indent. -Known gaps for full document classes: custom `\maketitle` implementations -are ignored (the engine title layout is used), `\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. +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. `\footnote{...}` captures its content, emits a superscript marker, reserves space on the page where the paragraph ends, and paints the notes with a @@ -490,7 +492,7 @@ advisory breaks, starred `\vspace`/`\hspace`, `center`, `\hrule`, `\fbox`, | 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` | | 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 | 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 | | Live preview | incremental paragraph cache, page-hash diffing, SVG refresh | — | The compatibility layer also covers spacing macros, text symbols/letters, style diff --git a/crates/texrra-core/src/document_parser.rs b/crates/texrra-core/src/document_parser.rs index 8d0c26a..c013803 100644 --- a/crates/texrra-core/src/document_parser.rs +++ b/crates/texrra-core/src/document_parser.rs @@ -910,6 +910,14 @@ impl Parser { self.push_block(Block::FramedBox { runs, frame, width }); } } + expanded::FrontendEventKind::MetadataValue(field) => { + let value = match field { + expanded::MetadataField::Title => self.document.title.clone(), + expanded::MetadataField::Author => self.document.author.clone(), + expanded::MetadataField::Date => self.document.date.clone(), + }; + self.append_text(&value); + } expanded::FrontendEventKind::MetadataStart(field) => { self.metadata_capture = Some((*field, Vec::new())); } diff --git a/crates/texrra-core/src/expanded.rs b/crates/texrra-core/src/expanded.rs index 712c798..414c47c 100644 --- a/crates/texrra-core/src/expanded.rs +++ b/crates/texrra-core/src/expanded.rs @@ -108,6 +108,7 @@ pub enum FrontendEventKind { FootnoteStart, FootnoteEnd, MetadataStart(MetadataField), + MetadataValue(MetadataField), MetadataEnd(MetadataField), DisplayMathStart, DisplayMathEnd(MathDelimiterSettings), diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 99129ab..05c7815 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -12,7 +12,7 @@ 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 +deferred top-float queue for figures; document-level custom `\maketitle` (`build_positioned_pages` is the only page builder and no separate break planner remains). @@ -28,8 +28,3 @@ planner remains). - `\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. - -## 3. Custom title blocks (remaining) - -- Let a document-level `\renewcommand{\maketitle}` contribute a real title - block once the engine's title model can run box material. diff --git a/docs/STATUS.md b/docs/STATUS.md index 52643cc..f4f6d9d 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -46,6 +46,10 @@ the source changes; the SVG preview is refreshed per page. - Class sizes: 10pt/11pt/12pt set the body size and propagate through headings, title material, lists, tables, block boxes, footnotes, and the default paragraph indent (10/12pt use 15pt; 11pt uses 17pt). +- Title blocks: a document-level `\renewcommand{\maketitle}` replaces the + engine title layout and can use `\@title`/`\@author`/`\@date`; class and + package replacements are ignored so template title code keeps using the + native layout. - Classes/packages: built-in classes, local `.cls`/`.sty`, paper options, `\DeclareOption`/`\ProcessOptions`/`\ExecuteOptions`/option passing. - Compatibility: spacing macros (quad/qquad/thin/en/med/thick, `\vspace*`, @@ -70,14 +74,12 @@ See `docs/ROADMAP.md` for concrete implementation plans. ends rather than the exact reference line. - Contents: chapter headings are listed with chapter-prefixed section numbers, but contents are not split per chapter. -- Miscellaneous: a document-level `\renewcommand{\maketitle}` is ignored in - favor of the engine title block. ## Verification - `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` (37 tests: 33 compiler +- `cargo fmt --check` passes; `cargo test --offline` (38 tests: 34 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 a447e94..cb31120 100644 --- a/src/rust_typeset/frontend.rs +++ b/src/rust_typeset/frontend.rs @@ -22,6 +22,9 @@ const PRELUDE: &str = r#" \def\title#1{\texrrametadatastart{title}#1\texrrametadataend{title}} \def\author#1{\texrrametadatastart{author}#1\texrrametadataend{author}} \def\date#1{\texrrametadatastart{date}#1\texrrametadataend{date}} +\def\@title{\texrrametadatatitle} +\def\@author{\texrrametadataauthor} +\def\@date{\texrrametadatadate} \def\today{__TEXRRA_TODAY__} \def\maketitle{\texrramaketitle} \def\noindent{\texrranoindent} @@ -361,9 +364,6 @@ const PRELUDE: &str = r#" \def\thefootnote{*} \def\footnoterule{} \def\thanks#1{\footnote{#1}} -\def\@title{} -\def\@author{} -\def\@date{} \def\@thanks{} \def\@makefntext#1{} \def\@makefnmark{} diff --git a/src/rust_typeset/texlang_adapter.rs b/src/rust_typeset/texlang_adapter.rs index ec07cd5..3c29237 100644 --- a/src/rust_typeset/texlang_adapter.rs +++ b/src/rust_typeset/texlang_adapter.rs @@ -2121,6 +2121,15 @@ fn metadata_field_argument( } } +fn metadata_value_primitive( + field: MetadataField, + token: token::Token, + input: &mut vm::ExecutionInput, +) -> texlang::prelude::Result<()> { + write_event(input, token, FrontendEventKind::MetadataValue(field)); + Ok(()) +} + fn metadata_start_primitive( token: token::Token, input: &mut vm::ExecutionInput, @@ -4751,7 +4760,21 @@ fn define_latex_command( // parser. Style files routinely replace them with box-level LaTeX // implementations the engine cannot execute, so keep the native // meaning instead of failing or replacing it with an unusable macro. - return Ok(()); + // A document may still replace its own title block in the main source. + let from_style_file = match input.vm().trace(token).origin { + trace::Origin::File(path) => matches!( + path.extension().and_then(|extension| extension.to_str()), + Some("sty" | "cls") + ), + trace::Origin::Terminal => false, + }; + let document_title_block = matches!( + ¯o_name, + EngineCommandName::ControlSequence(name) if name == "maketitle" + ); + if !document_title_block || from_style_file { + return Ok(()); + } } let already_defined = input.state().engine.macros.get(¯o_name).is_some() || input.vm().commands_map.get_command(&name_ref).is_some(); @@ -6904,6 +6927,24 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn