Render arxiv-style preprint title blocks
This commit is contained in:
1 parent
8d5cbc69ba
commit
4991bdfcfc
12 files changed
+559
-77
No files matched your search
@@ -316,15 +316,19 @@ Base font-size class options `10pt`, `11pt`, and `12pt` now set the body
|
|||||||
size and propagate through headings, title material, lists, tables, block
|
size and propagate through headings, title material, lists, tables, block
|
||||||
boxes, footnotes, and the default paragraph indent. The article default is
|
boxes, footnotes, and the default paragraph indent. The article default is
|
||||||
`10pt`, matching LaTeX.
|
`10pt`, matching LaTeX.
|
||||||
A document-level `\renewcommand{\maketitle}` replaces the engine title block;
|
A document-level `\renewcommand{\maketitle}` replaces the engine title block.
|
||||||
class and package files that replace `\maketitle` are ignored so template
|
When a document loads `arxiv.sty`, the engine switches to a native preprint
|
||||||
title code cannot break the native layout. In particular, the arXiv style
|
title style: top/bottom title rules, small-caps title and `\undertitle`,
|
||||||
file defines its own box-level `\maketitle`/`\@maketitle` (title rules,
|
two-column author blocks with affiliations and monospaced e-mail addresses,
|
||||||
`\undertitle`, author tabular); that block is not executed, so arXiv PDFs use
|
a long date, and `\thispagestyle{empty}` on the first page. Class and package
|
||||||
the native title layout without those pieces. Known gaps for full document
|
files that replace `\maketitle` itself are still ignored, so box-level
|
||||||
classes: `\parbox`/`\minipage` are block-level rather than inline, and
|
template code cannot break the native layout. Ordinary text is now placed on
|
||||||
`\vbox`/`\vtop` capture vertical material but do not form an independent
|
a TeX baseline grid (1.2em line height, 0.8em ascent) instead of the fallback
|
||||||
natural-width box with its own baseline.
|
TrueType font's larger ascent/descent, which matches LaTeX line spacing and
|
||||||
|
page breaks. Known gaps for full document classes: `\parbox`/`\minipage` are
|
||||||
|
block-level rather than inline, and `\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
|
`\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
|
||||||
@@ -502,7 +506,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 `[t]`/`[b]`/`[p]` placement | table 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`, native arxiv-style preprint title blocks (rules, `\undertitle`, author columns, long date) | class-specific formatting beyond chapter breaks |
|
||||||
| Live preview | incremental paragraph cache, page-hash diffing, SVG refresh | — |
|
| Live preview | incremental paragraph cache, page-hash diffing, SVG refresh | — |
|
||||||
|
|
||||||
The compatibility layer also covers spacing macros, text symbols/letters, style
|
The compatibility layer also covers spacing macros, text symbols/letters, style
|
||||||
|
|||||||
@@ -55,6 +55,16 @@ impl Default for PageSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Layout style for the document title block.
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
|
pub enum TitleStyle {
|
||||||
|
/// The generic article title: title, author, date, no rules.
|
||||||
|
#[default]
|
||||||
|
Article,
|
||||||
|
/// Preprint-style title block with rules, an undertitle, and author columns.
|
||||||
|
Preprint,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Footnote {
|
pub struct Footnote {
|
||||||
pub number: u32,
|
pub number: u32,
|
||||||
@@ -66,6 +76,10 @@ pub struct DocumentModel {
|
|||||||
pub title: String,
|
pub title: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
pub date: String,
|
pub date: String,
|
||||||
|
/// Style selected by the document's class/package layer.
|
||||||
|
pub title_style: TitleStyle,
|
||||||
|
/// Optional line printed under the title rules, e.g. "A Preprint".
|
||||||
|
pub undertitle: Option<String>,
|
||||||
pub page: PageSize,
|
pub page: PageSize,
|
||||||
pub parindent: common::Scaled,
|
pub parindent: common::Scaled,
|
||||||
/// Base font size selected by the document class (10, 11, or 12pt).
|
/// Base font size selected by the document class (10, 11, or 12pt).
|
||||||
@@ -87,6 +101,8 @@ impl Default for DocumentModel {
|
|||||||
title: String::new(),
|
title: String::new(),
|
||||||
author: String::new(),
|
author: String::new(),
|
||||||
date: String::new(),
|
date: String::new(),
|
||||||
|
title_style: TitleStyle::default(),
|
||||||
|
undertitle: None,
|
||||||
page: PageSize::default(),
|
page: PageSize::default(),
|
||||||
// article's default \parindent for 10/11pt text.
|
// article's default \parindent for 10/11pt text.
|
||||||
parindent: common::Scaled(17 * 65_536),
|
parindent: common::Scaled(17 * 65_536),
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use crate::{
|
|||||||
TeXGlue, TeXGlueOrder,
|
TeXGlue, TeXGlueOrder,
|
||||||
document::{
|
document::{
|
||||||
Block, ColumnAlignment, DocumentModel, EquationNumber, InlineBox, InlineBoxAlign,
|
Block, ColumnAlignment, DocumentModel, EquationNumber, InlineBox, InlineBoxAlign,
|
||||||
ListBlock, ListItem, PageMargins, PageSize, PageStyleOverride, ParagraphAlignment,
|
ListBlock, ListItem, PageMargins, PageSize, PageStyleKind, PageStyleOverride,
|
||||||
ParsedDocument, RuleBox, Run, UnresolvedReference,
|
ParagraphAlignment, ParsedDocument, RuleBox, Run, TitleStyle, UnresolvedReference,
|
||||||
},
|
},
|
||||||
expanded,
|
expanded,
|
||||||
math_expr::*,
|
math_expr::*,
|
||||||
@@ -942,6 +942,30 @@ impl Parser {
|
|||||||
expanded::FrontendEventKind::MetadataEnd(field) => {
|
expanded::FrontendEventKind::MetadataEnd(field) => {
|
||||||
self.finish_metadata(*field);
|
self.finish_metadata(*field);
|
||||||
}
|
}
|
||||||
|
expanded::FrontendEventKind::PackageLoaded(package) => {
|
||||||
|
if package == "arxiv" {
|
||||||
|
self.document.title_style = TitleStyle::Preprint;
|
||||||
|
if self.document.undertitle.is_none() {
|
||||||
|
self.document.undertitle = Some("A Preprint".to_string());
|
||||||
|
}
|
||||||
|
if !self
|
||||||
|
.document
|
||||||
|
.page_style_overrides
|
||||||
|
.iter()
|
||||||
|
.any(|override_| override_.anchor == 0)
|
||||||
|
{
|
||||||
|
self.document.page_style_overrides.push(PageStyleOverride {
|
||||||
|
anchor: 0,
|
||||||
|
kind: PageStyleKind::Empty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expanded::FrontendEventKind::MetadataSeparator => {
|
||||||
|
if self.metadata_capture.is_some() {
|
||||||
|
self.append_text("\u{F7001}");
|
||||||
|
}
|
||||||
|
}
|
||||||
expanded::FrontendEventKind::Geometry(settings) => {
|
expanded::FrontendEventKind::Geometry(settings) => {
|
||||||
apply_class_font_size(&mut self.document, settings);
|
apply_class_font_size(&mut self.document, settings);
|
||||||
apply_geometry(&mut self.document, settings);
|
apply_geometry(&mut self.document, settings);
|
||||||
@@ -1067,10 +1091,18 @@ impl Parser {
|
|||||||
expanded::FrontendEventKind::LiteralCharacter(character) => {
|
expanded::FrontendEventKind::LiteralCharacter(character) => {
|
||||||
self.append_text(&character.to_string())
|
self.append_text(&character.to_string())
|
||||||
}
|
}
|
||||||
expanded::FrontendEventKind::LineBreak => self.append_text(" "),
|
expanded::FrontendEventKind::LineBreak => {
|
||||||
|
if self.metadata_capture.is_some() {
|
||||||
|
self.append_metadata_line_break();
|
||||||
|
} else {
|
||||||
|
self.append_text(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
expanded::FrontendEventKind::RowBreak => {
|
expanded::FrontendEventKind::RowBreak => {
|
||||||
if self.table.is_some() {
|
if self.table.is_some() {
|
||||||
self.finish_table_row();
|
self.finish_table_row();
|
||||||
|
} else if self.metadata_capture.is_some() {
|
||||||
|
self.append_metadata_line_break();
|
||||||
} else {
|
} else {
|
||||||
self.append_text(" ");
|
self.append_text(" ");
|
||||||
}
|
}
|
||||||
@@ -1339,6 +1371,17 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn append_metadata_line_break(&mut self) {
|
||||||
|
let Some((_, runs)) = &mut self.metadata_capture else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if let Some(last) = runs.last_mut() {
|
||||||
|
last.text.push('\n');
|
||||||
|
} else {
|
||||||
|
runs.push(Run::plain("\n".to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn append_text(&mut self, text: &str) {
|
fn append_text(&mut self, text: &str) {
|
||||||
if normalize_whitespace(text).is_empty() {
|
if normalize_whitespace(text).is_empty() {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -248,6 +248,10 @@ pub enum FrontendEventKind {
|
|||||||
header: bool,
|
header: bool,
|
||||||
},
|
},
|
||||||
PageNumber,
|
PageNumber,
|
||||||
|
/// A package or class was loaded from a local file.
|
||||||
|
PackageLoaded(String),
|
||||||
|
/// A separator between author blocks (LaTeX's \And).
|
||||||
|
MetadataSeparator,
|
||||||
ParagraphAlignment(crate::document::ParagraphAlignment),
|
ParagraphAlignment(crate::document::ParagraphAlignment),
|
||||||
TableOfContents,
|
TableOfContents,
|
||||||
ListOfFigures,
|
ListOfFigures,
|
||||||
|
|||||||
+6
-9
@@ -25,16 +25,13 @@ planner remains).
|
|||||||
work: queue table float-page placements, tune
|
work: queue table float-page placements, tune
|
||||||
`\textfraction`/`\topfraction`, and support more than a one-page lookahead.
|
`\textfraction`/`\topfraction`, and support more than a one-page lookahead.
|
||||||
|
|
||||||
## 2. Class title blocks
|
## 2. Class title blocks (implemented for arXiv-style preprints)
|
||||||
|
|
||||||
- A document-level `\renewcommand{\maketitle}` already works. Class/package
|
- A document-level `\renewcommand{\maketitle}` works, and loading `arxiv.sty`
|
||||||
title code is still ignored; the arXiv style replaces both `\maketitle` and
|
switches to a native preprint title block: title rules, small-caps title,
|
||||||
`\@maketitle` with box-level TeX (title rules, `\undertitle`, author
|
`\undertitle`, two-column author/affiliation blocks, long date, and an empty
|
||||||
tabular, `\thispagestyle{empty}`). Supporting it generally requires running
|
first page style. Remaining work is class-specific variation beyond this
|
||||||
style-origin layout commands or modelling their semantic pieces (title,
|
style (for example other journal templates with different author grids).
|
||||||
subtitle, author blocks, affiliations, date, abstract heading) as data.
|
|
||||||
- Until then, arXiv PDFs use the native title block and page 1 uses `plain`
|
|
||||||
(no fancy header) but still shows the page number.
|
|
||||||
|
|
||||||
## 3. True vertical boxes (partial)
|
## 3. True vertical boxes (partial)
|
||||||
|
|
||||||
|
|||||||
+8
-5
@@ -50,10 +50,13 @@ the source changes; the SVG preview is refreshed per page.
|
|||||||
headings, title material, lists, tables, block boxes, footnotes, and the
|
headings, title material, lists, tables, block boxes, footnotes, and the
|
||||||
default paragraph indent (10/12pt use 15pt; 11pt uses 17pt).
|
default paragraph indent (10/12pt use 15pt; 11pt uses 17pt).
|
||||||
- Title blocks: a document-level `\renewcommand{\maketitle}` replaces the
|
- Title blocks: a document-level `\renewcommand{\maketitle}` replaces the
|
||||||
engine title layout and can use `\@title`/`\@author`/`\@date`; class and
|
engine title layout and can use `\@title`/`\@author`/`\@date`. Loading
|
||||||
package replacements are ignored so template title code keeps using the
|
`arxiv.sty` selects a native preprint title style (rules, small-caps title,
|
||||||
native layout. The arXiv style's box-level `\maketitle`/`\@maketitle`
|
`\undertitle`, two-column author/affiliation blocks, long date, empty first
|
||||||
(title rules, `\undertitle`, author tabular) is therefore not applied.
|
page style), so arXiv PDFs no longer fall back to the plain article title.
|
||||||
|
Class/package replacements of `\maketitle` itself remain ignored.
|
||||||
|
- Line spacing: ordinary text lines use a TeX baseline grid (1.2em height,
|
||||||
|
0.8em ascent); boxes/rules keep their measured vertical metrics.
|
||||||
- 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*`,
|
||||||
@@ -87,7 +90,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` (41 tests: 37 compiler
|
- `cargo fmt --check` passes; `cargo test --offline` (42 tests: 38 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 (top and bottom), 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
|
||||||
|
|||||||
@@ -450,8 +450,8 @@ const PRELUDE: &str = r#"
|
|||||||
\def\dots{...}
|
\def\dots{...}
|
||||||
\def\textellipsis{...}
|
\def\textellipsis{...}
|
||||||
\def\and{ }
|
\def\and{ }
|
||||||
\def\And{ }
|
\def\And{\texrraauthorseparator}
|
||||||
\def\AND{ }
|
\def\AND{\texrraauthorseparator}
|
||||||
\def\ifhmode{\iftrue}
|
\def\ifhmode{\iftrue}
|
||||||
\def\paragraph#1{\par\texrraheadingstart{3}#1\texrraheadingend\par}
|
\def\paragraph#1{\par\texrraheadingstart{3}#1\texrraheadingend\par}
|
||||||
\def\subparagraph#1{\par\texrraheadingstart{3}#1\texrraheadingend\par}
|
\def\subparagraph#1{\par\texrraheadingstart{3}#1\texrraheadingend\par}
|
||||||
@@ -645,7 +645,7 @@ fn preprocess_latex(source: &str, source_path: &Path) -> Result<PreprocessOutput
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_date_utc() -> String {
|
pub(crate) fn current_date_utc() -> String {
|
||||||
let days = SystemTime::now()
|
let days = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -666,7 +666,22 @@ fn current_date_utc() -> String {
|
|||||||
let day = day_of_year - (153 * month_part + 2) / 5 + 1;
|
let day = day_of_year - (153 * month_part + 2) / 5 + 1;
|
||||||
let month = month_part + if month_part < 10 { 3 } else { -9 };
|
let month = month_part + if month_part < 10 { 3 } else { -9 };
|
||||||
year += i64::from(month <= 2);
|
year += i64::from(month <= 2);
|
||||||
format!("{year:04}-{month:02}-{day:02}")
|
const MONTHS: [&str; 12] = [
|
||||||
|
"January",
|
||||||
|
"February",
|
||||||
|
"March",
|
||||||
|
"April",
|
||||||
|
"May",
|
||||||
|
"June",
|
||||||
|
"July",
|
||||||
|
"August",
|
||||||
|
"September",
|
||||||
|
"October",
|
||||||
|
"November",
|
||||||
|
"December",
|
||||||
|
];
|
||||||
|
let month_name = MONTHS[(month.clamp(1, 12) - 1) as usize];
|
||||||
|
format!("{month_name} {day}, {year}")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn can_cache_frontend_snapshot(source: &str) -> bool {
|
pub(super) fn can_cache_frontend_snapshot(source: &str) -> bool {
|
||||||
|
|||||||
@@ -913,6 +913,7 @@ struct InlineMathLine {
|
|||||||
pre_display_size: Option<Mm>,
|
pre_display_size: Option<Mm>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub(super) struct InlineMathLineElement {
|
pub(super) struct InlineMathLineElement {
|
||||||
line: InlineMathLine,
|
line: InlineMathLine,
|
||||||
alignment: Alignment,
|
alignment: Alignment,
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ struct PageBreakPlan {
|
|||||||
breaks: HashSet<PageAnchor>,
|
breaks: HashSet<PageAnchor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum PositionedLineContent {
|
enum PositionedLineContent {
|
||||||
Text {
|
Text {
|
||||||
line: text_layout::LineBox,
|
line: text_layout::LineBox,
|
||||||
|
|||||||
+400
-46
@@ -1,5 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use texrra_core::document::{ParagraphAlignment, UnresolvedReference};
|
use texrra_core::document::{ParagraphAlignment, TitleStyle, UnresolvedReference};
|
||||||
|
|
||||||
const ARTICLE_11PT_LIST_TOPSEP_PT: f64 = 9.0;
|
const ARTICLE_11PT_LIST_TOPSEP_PT: f64 = 9.0;
|
||||||
const ARTICLE_11PT_LIST_TOPSEP_STRETCH_PT: f64 = 3.0;
|
const ARTICLE_11PT_LIST_TOPSEP_STRETCH_PT: f64 = 3.0;
|
||||||
@@ -1331,6 +1331,125 @@ fn resolve_toc_page_numbers(
|
|||||||
changed.then_some(resolved)
|
changed.then_some(resolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn push_title_line(
|
||||||
|
pages: &mut Vec<PositionedPage>,
|
||||||
|
deferred: &mut Vec<DeferredFloat>,
|
||||||
|
cursor: &mut i64,
|
||||||
|
page_breaks: &HashSet<PageAnchor>,
|
||||||
|
page_goal: i64,
|
||||||
|
top_skip: i64,
|
||||||
|
max_depth: i64,
|
||||||
|
line: MeasuredLine,
|
||||||
|
x: i64,
|
||||||
|
centered: bool,
|
||||||
|
) {
|
||||||
|
let anchor = PageAnchor {
|
||||||
|
block: usize::MAX,
|
||||||
|
line: line.line_index,
|
||||||
|
};
|
||||||
|
position_box(
|
||||||
|
pages,
|
||||||
|
deferred,
|
||||||
|
cursor,
|
||||||
|
page_breaks,
|
||||||
|
anchor,
|
||||||
|
line.height,
|
||||||
|
line.ascent,
|
||||||
|
line.leading_before,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
);
|
||||||
|
let y = *cursor;
|
||||||
|
pages
|
||||||
|
.last_mut()
|
||||||
|
.expect("the page list starts with one page")
|
||||||
|
.items
|
||||||
|
.push(PositionedPageItem::Line(PositionedLine {
|
||||||
|
anchor,
|
||||||
|
content: line.content,
|
||||||
|
y,
|
||||||
|
x,
|
||||||
|
centered,
|
||||||
|
ragged: false,
|
||||||
|
}));
|
||||||
|
*cursor = cursor.saturating_add(line.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn push_title_rule(
|
||||||
|
pages: &mut Vec<PositionedPage>,
|
||||||
|
deferred: &mut Vec<DeferredFloat>,
|
||||||
|
cursor: &mut i64,
|
||||||
|
page_breaks: &HashSet<PageAnchor>,
|
||||||
|
page_goal: i64,
|
||||||
|
top_skip: i64,
|
||||||
|
max_depth: i64,
|
||||||
|
width: i64,
|
||||||
|
height: i64,
|
||||||
|
) {
|
||||||
|
let anchor = PageAnchor {
|
||||||
|
block: usize::MAX,
|
||||||
|
line: 0,
|
||||||
|
};
|
||||||
|
position_box(
|
||||||
|
pages,
|
||||||
|
deferred,
|
||||||
|
cursor,
|
||||||
|
page_breaks,
|
||||||
|
anchor,
|
||||||
|
height,
|
||||||
|
height,
|
||||||
|
0,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
);
|
||||||
|
let line = text_layout::LineBox {
|
||||||
|
width: common::Scaled(width as i32),
|
||||||
|
items: vec![text_layout::LineItem::Rule {
|
||||||
|
width: common::Scaled(width as i32),
|
||||||
|
raise: common::Scaled::ZERO,
|
||||||
|
height: common::Scaled(height as i32),
|
||||||
|
y_offset: common::Scaled::ZERO,
|
||||||
|
}],
|
||||||
|
pre_display_size: None,
|
||||||
|
};
|
||||||
|
pages
|
||||||
|
.last_mut()
|
||||||
|
.expect("the page list starts with one page")
|
||||||
|
.items
|
||||||
|
.push(PositionedPageItem::Line(PositionedLine {
|
||||||
|
anchor,
|
||||||
|
content: PositionedLineContent::Text {
|
||||||
|
line,
|
||||||
|
font_size: 10,
|
||||||
|
},
|
||||||
|
y: *cursor,
|
||||||
|
x: 0,
|
||||||
|
centered: false,
|
||||||
|
ragged: false,
|
||||||
|
}));
|
||||||
|
*cursor = cursor.saturating_add(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title_line_natural_width(
|
||||||
|
content: &PositionedLineContent,
|
||||||
|
font_cache: &fonts::FontCache,
|
||||||
|
cjk_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
mono_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
sans_family: Option<FontFamily<fonts::Font>>,
|
||||||
|
) -> f64 {
|
||||||
|
match content {
|
||||||
|
PositionedLineContent::Text { line, font_size } => {
|
||||||
|
text_layout::TextLine::new(line, cjk_family, mono_family, sans_family, *font_size)
|
||||||
|
.natural_width_mm(font_cache)
|
||||||
|
}
|
||||||
|
PositionedLineContent::InlineMath(_) => 0.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn build_positioned_pages(
|
pub(super) fn build_positioned_pages(
|
||||||
model: &DocumentModel,
|
model: &DocumentModel,
|
||||||
source_dir: &Path,
|
source_dir: &Path,
|
||||||
@@ -1369,59 +1488,279 @@ pub(super) fn build_positioned_pages(
|
|||||||
let mut pre_display_size = None;
|
let mut pre_display_size = None;
|
||||||
|
|
||||||
if model.show_title {
|
if model.show_title {
|
||||||
for (text, font_size, bold) in [
|
match model.title_style {
|
||||||
(&model.title, base_font_size + 9, true),
|
TitleStyle::Article => {
|
||||||
(&model.author, base_font_size + 1, false),
|
for (text, font_size, bold) in [
|
||||||
(&model.date, base_font_size, false),
|
(&model.title, base_font_size + 9, true),
|
||||||
] {
|
(&model.author, base_font_size + 1, false),
|
||||||
if text.is_empty() {
|
(&model.date, base_font_size, false),
|
||||||
continue;
|
] {
|
||||||
|
if text.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let mut run = Run::plain(text.clone());
|
||||||
|
run.bold = bold;
|
||||||
|
for line in measure_positioned_lines(
|
||||||
|
&[run],
|
||||||
|
font_size,
|
||||||
|
content_width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
) {
|
||||||
|
push_title_line(
|
||||||
|
&mut pages,
|
||||||
|
&mut deferred,
|
||||||
|
&mut cursor,
|
||||||
|
page_breaks,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
line,
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let mut run = Run::plain(text.clone());
|
TitleStyle::Preprint => {
|
||||||
run.bold = bold;
|
let rule_width = millimeters_to_scaled(content_width_mm);
|
||||||
for line in measure_positioned_lines(
|
let rule_height = i64::from(scaled_points(2.0).0).max(1);
|
||||||
&[run],
|
let mut title_run = Run::plain(model.title.clone());
|
||||||
font_size,
|
title_run.bold = true;
|
||||||
content_width_mm,
|
title_run.small_caps = true;
|
||||||
metrics,
|
push_title_rule(
|
||||||
font_cache,
|
|
||||||
cjk_family,
|
|
||||||
mono_family,
|
|
||||||
sans_family,
|
|
||||||
math_metrics,
|
|
||||||
math_layout,
|
|
||||||
cache,
|
|
||||||
) {
|
|
||||||
let anchor = PageAnchor {
|
|
||||||
block: usize::MAX,
|
|
||||||
line: line.line_index,
|
|
||||||
};
|
|
||||||
position_box(
|
|
||||||
&mut pages,
|
&mut pages,
|
||||||
&mut deferred,
|
&mut deferred,
|
||||||
&mut cursor,
|
&mut cursor,
|
||||||
page_breaks,
|
page_breaks,
|
||||||
anchor,
|
|
||||||
line.height,
|
|
||||||
line.ascent,
|
|
||||||
line.leading_before,
|
|
||||||
page_goal,
|
page_goal,
|
||||||
top_skip,
|
top_skip,
|
||||||
max_depth,
|
max_depth,
|
||||||
|
rule_width,
|
||||||
|
rule_height,
|
||||||
);
|
);
|
||||||
pages
|
cursor = cursor.saturating_add(millimeters_to_scaled(6.35));
|
||||||
.last_mut()
|
for line in measure_positioned_lines(
|
||||||
.expect("the page list starts with one page")
|
&[title_run],
|
||||||
.items
|
base_font_size + 7,
|
||||||
.push(PositionedPageItem::Line(PositionedLine {
|
content_width_mm,
|
||||||
anchor,
|
metrics,
|
||||||
content: line.content,
|
font_cache,
|
||||||
y: cursor,
|
cjk_family,
|
||||||
x: 0,
|
mono_family,
|
||||||
centered: true,
|
sans_family,
|
||||||
ragged: false,
|
math_metrics,
|
||||||
}));
|
math_layout,
|
||||||
cursor = cursor.saturating_add(line.height);
|
cache,
|
||||||
|
) {
|
||||||
|
push_title_line(
|
||||||
|
&mut pages,
|
||||||
|
&mut deferred,
|
||||||
|
&mut cursor,
|
||||||
|
page_breaks,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
line,
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
cursor = cursor.saturating_add(millimeters_to_scaled(1.0));
|
||||||
|
push_title_rule(
|
||||||
|
&mut pages,
|
||||||
|
&mut deferred,
|
||||||
|
&mut cursor,
|
||||||
|
page_breaks,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
rule_width,
|
||||||
|
rule_height,
|
||||||
|
);
|
||||||
|
cursor = cursor.saturating_add(millimeters_to_scaled(2.29));
|
||||||
|
let undertitle = model.undertitle.clone().unwrap_or_default();
|
||||||
|
if !undertitle.is_empty() {
|
||||||
|
let mut run = Run::plain(undertitle);
|
||||||
|
run.small_caps = true;
|
||||||
|
for line in measure_positioned_lines(
|
||||||
|
&[run],
|
||||||
|
base_font_size + 2,
|
||||||
|
content_width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
) {
|
||||||
|
push_title_line(
|
||||||
|
&mut pages,
|
||||||
|
&mut deferred,
|
||||||
|
&mut cursor,
|
||||||
|
page_breaks,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
line,
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor = cursor.saturating_add(millimeters_to_scaled(2.54));
|
||||||
|
let blocks = model
|
||||||
|
.author
|
||||||
|
.split('\u{F7001}')
|
||||||
|
.map(|block| {
|
||||||
|
block
|
||||||
|
.split('\n')
|
||||||
|
.map(str::trim)
|
||||||
|
.filter(|line| !line.is_empty())
|
||||||
|
.map(str::to_string)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.filter(|lines| !lines.is_empty())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
if !blocks.is_empty() {
|
||||||
|
let column_count = blocks.len();
|
||||||
|
let column_width = content_width_mm / column_count as f64;
|
||||||
|
let mut measured_blocks = Vec::with_capacity(column_count);
|
||||||
|
for lines in &blocks {
|
||||||
|
let mut measured_lines = Vec::with_capacity(lines.len());
|
||||||
|
for (index, text) in lines.iter().enumerate() {
|
||||||
|
let mut run = Run::plain(text.clone());
|
||||||
|
if index == 0 {
|
||||||
|
run.bold = true;
|
||||||
|
}
|
||||||
|
if text.contains('@') && !text.contains(' ') {
|
||||||
|
run.monospace = true;
|
||||||
|
}
|
||||||
|
if let Some(line) = measure_positioned_lines(
|
||||||
|
&[run],
|
||||||
|
base_font_size,
|
||||||
|
column_width - 2.0,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
)
|
||||||
|
.into_iter()
|
||||||
|
.next()
|
||||||
|
{
|
||||||
|
measured_lines.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
measured_blocks.push(measured_lines);
|
||||||
|
}
|
||||||
|
let row_count = measured_blocks.iter().map(Vec::len).max().unwrap_or(0);
|
||||||
|
for row in 0..row_count {
|
||||||
|
let mut row_height = 0;
|
||||||
|
let mut row_ascent = 0;
|
||||||
|
for block in &measured_blocks {
|
||||||
|
if let Some(line) = block.get(row) {
|
||||||
|
row_height = row_height.max(line.height);
|
||||||
|
row_ascent = row_ascent.max(line.ascent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if row_height == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let anchor = PageAnchor {
|
||||||
|
block: usize::MAX,
|
||||||
|
line: 0,
|
||||||
|
};
|
||||||
|
position_box(
|
||||||
|
&mut pages,
|
||||||
|
&mut deferred,
|
||||||
|
&mut cursor,
|
||||||
|
page_breaks,
|
||||||
|
anchor,
|
||||||
|
row_height,
|
||||||
|
row_ascent,
|
||||||
|
0,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
);
|
||||||
|
let y = cursor;
|
||||||
|
for (column, block) in measured_blocks.iter().enumerate() {
|
||||||
|
let Some(line) = block.get(row) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let natural_width = title_line_natural_width(
|
||||||
|
&line.content,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
);
|
||||||
|
let column_start = column as f64 * column_width;
|
||||||
|
let x = millimeters_to_scaled(
|
||||||
|
column_start + (column_width - natural_width).max(0.0) / 2.0,
|
||||||
|
);
|
||||||
|
pages
|
||||||
|
.last_mut()
|
||||||
|
.expect("the page list starts with one page")
|
||||||
|
.items
|
||||||
|
.push(PositionedPageItem::Line(PositionedLine {
|
||||||
|
anchor,
|
||||||
|
content: line.content.clone(),
|
||||||
|
y,
|
||||||
|
x,
|
||||||
|
centered: false,
|
||||||
|
ragged: false,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
cursor = cursor.saturating_add(row_height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor = cursor.saturating_add(millimeters_to_scaled(6.0));
|
||||||
|
let date = if model.date.is_empty() {
|
||||||
|
crate::rust_typeset::frontend::current_date_utc()
|
||||||
|
} else {
|
||||||
|
model.date.clone()
|
||||||
|
};
|
||||||
|
if !date.is_empty() {
|
||||||
|
for line in measure_positioned_lines(
|
||||||
|
&[Run::plain(date)],
|
||||||
|
base_font_size,
|
||||||
|
content_width_mm,
|
||||||
|
metrics,
|
||||||
|
font_cache,
|
||||||
|
cjk_family,
|
||||||
|
mono_family,
|
||||||
|
sans_family,
|
||||||
|
math_metrics,
|
||||||
|
math_layout,
|
||||||
|
cache,
|
||||||
|
) {
|
||||||
|
push_title_line(
|
||||||
|
&mut pages,
|
||||||
|
&mut deferred,
|
||||||
|
&mut cursor,
|
||||||
|
page_breaks,
|
||||||
|
page_goal,
|
||||||
|
top_skip,
|
||||||
|
max_depth,
|
||||||
|
line,
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor = cursor.saturating_add(normal_line_height);
|
cursor = cursor.saturating_add(normal_line_height);
|
||||||
@@ -2654,11 +2993,18 @@ pub(super) fn text_line_metrics_scaled(
|
|||||||
cjk_family: Option<FontFamily<fonts::Font>>,
|
cjk_family: Option<FontFamily<fonts::Font>>,
|
||||||
mono_family: Option<FontFamily<fonts::Font>>,
|
mono_family: Option<FontFamily<fonts::Font>>,
|
||||||
sans_family: Option<FontFamily<fonts::Font>>,
|
sans_family: Option<FontFamily<fonts::Font>>,
|
||||||
_font_size: u8,
|
font_size: u8,
|
||||||
) -> (i64, i64) {
|
) -> (i64, i64) {
|
||||||
let mut ascent_mm = Mm::from(0.0);
|
let mut ascent_mm = Mm::from(0.0);
|
||||||
let mut descent_mm = Mm::from(0.0);
|
let mut descent_mm = Mm::from(0.0);
|
||||||
|
let mut has_box_material = false;
|
||||||
for item in &line.items {
|
for item in &line.items {
|
||||||
|
if matches!(
|
||||||
|
item,
|
||||||
|
text_layout::LineItem::Frame { .. } | text_layout::LineItem::Rule { .. }
|
||||||
|
) {
|
||||||
|
has_box_material = true;
|
||||||
|
}
|
||||||
if let text_layout::LineItem::Frame {
|
if let text_layout::LineItem::Frame {
|
||||||
ascent,
|
ascent,
|
||||||
depth,
|
depth,
|
||||||
@@ -2737,6 +3083,14 @@ pub(super) fn text_line_metrics_scaled(
|
|||||||
descent_mm = descent_mm
|
descent_mm = descent_mm
|
||||||
.max((style.line_height(font_cache) - glyph_height - y_offset).max(Mm::from(0.0)));
|
.max((style.line_height(font_cache) - glyph_height - y_offset).max(Mm::from(0.0)));
|
||||||
}
|
}
|
||||||
|
if !has_box_material {
|
||||||
|
// TeX places ordinary text on a baseline grid: 10pt text uses 12pt
|
||||||
|
// baseline distance, rather than the much larger line box advertised
|
||||||
|
// by the fallback TrueType font's ascent/descent.
|
||||||
|
let grid_height = i64::from(scaled_points(f64::from(font_size) * 1.2).0);
|
||||||
|
let grid_ascent = i64::from(scaled_points(f64::from(font_size) * 0.8).0);
|
||||||
|
return (grid_ascent, grid_height.saturating_sub(grid_ascent));
|
||||||
|
}
|
||||||
let ascent = i64::from(scaled_points(f64::from(ascent_mm) * PDF_POINTS_PER_INCH / 25.4).0);
|
let ascent = i64::from(scaled_points(f64::from(ascent_mm) * PDF_POINTS_PER_INCH / 25.4).0);
|
||||||
let height =
|
let height =
|
||||||
i64::from(scaled_points(f64::from(ascent_mm + descent_mm) * PDF_POINTS_PER_INCH / 25.4).0)
|
i64::from(scaled_points(f64::from(ascent_mm + descent_mm) * PDF_POINTS_PER_INCH / 25.4).0)
|
||||||
|
|||||||
@@ -2130,6 +2130,14 @@ fn metadata_value_primitive(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn metadata_separator_primitive(
|
||||||
|
token: token::Token,
|
||||||
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
|
) -> texlang::prelude::Result<()> {
|
||||||
|
write_event(input, token, FrontendEventKind::MetadataSeparator);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn metadata_start_primitive(
|
fn metadata_start_primitive(
|
||||||
token: token::Token,
|
token: token::Token,
|
||||||
input: &mut vm::ExecutionInput<CompilerState>,
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
@@ -4275,6 +4283,11 @@ fn load_document_class(
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
input.state_mut().loaded_styles.insert(path.clone());
|
input.state_mut().loaded_styles.insert(path.clone());
|
||||||
|
write_event(
|
||||||
|
input,
|
||||||
|
token,
|
||||||
|
FrontendEventKind::PackageLoaded(class.clone()),
|
||||||
|
);
|
||||||
SourceDependency::record(
|
SourceDependency::record(
|
||||||
&mut input.state_mut().dependencies.borrow_mut(),
|
&mut input.state_mut().dependencies.borrow_mut(),
|
||||||
&path,
|
&path,
|
||||||
@@ -4565,6 +4578,11 @@ fn use_package(
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
input.state_mut().loaded_styles.insert(path.clone());
|
input.state_mut().loaded_styles.insert(path.clone());
|
||||||
|
write_event(
|
||||||
|
input,
|
||||||
|
token,
|
||||||
|
FrontendEventKind::PackageLoaded(package.clone()),
|
||||||
|
);
|
||||||
SourceDependency::record(
|
SourceDependency::record(
|
||||||
&mut input.state_mut().dependencies.borrow_mut(),
|
&mut input.state_mut().dependencies.borrow_mut(),
|
||||||
&path,
|
&path,
|
||||||
@@ -6985,6 +7003,10 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn<Compil
|
|||||||
metadata_value_primitive(MetadataField::Date, token, input)
|
metadata_value_primitive(MetadataField::Date, token, input)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"texrraauthorseparator",
|
||||||
|
texlang::command::BuiltIn::new_execution(metadata_separator_primitive),
|
||||||
|
);
|
||||||
built_ins.insert(
|
built_ins.insert(
|
||||||
"texrrametadatastart",
|
"texrrametadatastart",
|
||||||
texlang::command::BuiltIn::new_execution(metadata_start_primitive),
|
texlang::command::BuiltIn::new_execution(metadata_start_primitive),
|
||||||
|
|||||||
@@ -94,6 +94,28 @@ fn arxiv_fixture_is_three_letter_pages() {
|
|||||||
(number(&value, "pageHeightMm") - 279.4).abs() < 0.1,
|
(number(&value, "pageHeightMm") - 279.4).abs() < 0.1,
|
||||||
"Letter height"
|
"Letter height"
|
||||||
);
|
);
|
||||||
|
let first_page = page_svg(&value, 0);
|
||||||
|
assert!(first_page.contains("REPRINT"), "missing undertitle");
|
||||||
|
assert!(first_page.contains("Hippocampus"), "missing author column");
|
||||||
|
assert!(first_page.contains("October"), "missing date");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn arxiv_title_block_uses_rules_and_small_caps() {
|
||||||
|
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("fixtures")
|
||||||
|
.join("arxiv-template")
|
||||||
|
.join("template.tex");
|
||||||
|
let source = std::fs::read_to_string(&path).expect("read arXiv fixture");
|
||||||
|
let value = fresh_preview(&source, &path.to_string_lossy());
|
||||||
|
assert_eq!(value["status"], "ok", "{}", value["message"]);
|
||||||
|
let first_page = page_svg(&value, 0);
|
||||||
|
let rule_count = first_page.matches("<rect").count();
|
||||||
|
assert!(rule_count >= 2, "title rules missing: {rule_count}");
|
||||||
|
assert!(
|
||||||
|
first_page.contains("font-size=\"4.9389\""),
|
||||||
|
"small-caps title glyphs missing"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user