Compare commits
3
Commits
2c8d5e12d8
...
a798221817
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a798221817 | ||
|
|
6d4aa37189 | ||
|
|
1b0ce27ed3 |
No files matched your search
@@ -298,10 +298,11 @@ block.
|
|||||||
The `center` environment is a block: its content wraps at the text width and
|
The `center` environment is a block: its content wraps at the text width and
|
||||||
every line is centered without justification (natural spaces), so
|
every line is centered without justification (natural spaces), so
|
||||||
`\begin{center}\url{...}\end{center}` and centered short text match LaTeX.
|
`\begin{center}\url{...}\end{center}` and centered short text match LaTeX.
|
||||||
`\centering` inside a paragraph is still a no-op. `\raggedright` and
|
`\centering`, `\raggedright`, and `\raggedleft` are paragraph-level
|
||||||
`\raggedleft` are paragraph-level declarations: the affected runs use natural
|
declarations: the affected runs use natural space widths, the declaration is
|
||||||
space widths, the declaration is scoped by groups and the `raggedright`/
|
scoped by groups and the matching environments, centered lines are offset by
|
||||||
`raggedleft` environments, and the final line is not stretched to the margin.
|
half the leftover width, and ragged-left/right lines are not stretched to the
|
||||||
|
margin.
|
||||||
|
|
||||||
`\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
|
||||||
@@ -485,11 +486,11 @@ 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, `\raggedright`/`\raggedleft`, `\parindent` (17pt default), `\hfill`/`\hfil` | `\centering` in running text |
|
| 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/table `[htbp]` placement (top/bottom/page/here approximations) | deferred float queue, `\textfraction` |
|
| Notes/floats | footnotes with page-bottom insertion area, title/author `\thanks`, figure/table `[htbp]` placement (top/bottom/page/here approximations) | deferred float queue, `\textfraction` |
|
||||||
| Contents | `\tableofcontents`, `\listoffigures`, `\listoftables` generated from numbered headings and captions, page numbers resolved after pagination | dotted leaders, 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 | class-specific section formatting |
|
| Classes/packages | built-in + local classes, option protocol, local package options, base font sizes 10/11/12pt, chapter headings and numbering | class-specific formatting (automatic chapter page 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
|
||||||
|
|||||||
@@ -167,6 +167,9 @@ pub struct PageStyleOverride {
|
|||||||
|
|
||||||
/// Marker character used by `\thepage` inside header/footer runs; the page
|
/// Marker character used by `\thepage` inside header/footer runs; the page
|
||||||
/// renderer substitutes the concrete page number before measuring and painting.
|
/// renderer substitutes the concrete page number before measuring and painting.
|
||||||
|
/// Private-use marker for a dotted leader in generated contents lines.
|
||||||
|
pub const CONTENTS_LEADER_MARKER: char = '\u{F6000}';
|
||||||
|
|
||||||
pub const PAGE_NUMBER_MARKER: char = '\u{F5000}';
|
pub const PAGE_NUMBER_MARKER: char = '\u{F5000}';
|
||||||
|
|
||||||
pub fn page_number_marker_text() -> String {
|
pub fn page_number_marker_text() -> String {
|
||||||
@@ -321,6 +324,7 @@ pub enum ParagraphAlignment {
|
|||||||
Justified,
|
Justified,
|
||||||
RaggedRight,
|
RaggedRight,
|
||||||
RaggedLeft,
|
RaggedLeft,
|
||||||
|
Centered,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||||
|
|||||||
@@ -427,6 +427,9 @@ fn contents_kind(block: &Block) -> Option<ContentsKind> {
|
|||||||
fn contents_line_runs(title: &[Run], target: usize) -> Vec<Run> {
|
fn contents_line_runs(title: &[Run], target: usize) -> Vec<Run> {
|
||||||
let mut runs = title.to_vec();
|
let mut runs = title.to_vec();
|
||||||
trim_run_end(&mut runs);
|
trim_run_end(&mut runs);
|
||||||
|
runs.push(Run::plain(
|
||||||
|
crate::document::CONTENTS_LEADER_MARKER.to_string(),
|
||||||
|
));
|
||||||
let mut filler = Run::plain(String::new());
|
let mut filler = Run::plain(String::new());
|
||||||
filler.glue = Some(TeXGlue {
|
filler.glue = Some(TeXGlue {
|
||||||
width: common::Scaled::ZERO,
|
width: common::Scaled::ZERO,
|
||||||
@@ -457,7 +460,8 @@ struct Parser {
|
|||||||
text_style_stack: Vec<(expanded::TextStyle, bool, bool, bool, bool, bool)>,
|
text_style_stack: Vec<(expanded::TextStyle, bool, bool, bool, bool, bool)>,
|
||||||
style_declarations: Vec<(usize, expanded::TextStyle)>,
|
style_declarations: Vec<(usize, expanded::TextStyle)>,
|
||||||
group_depth: usize,
|
group_depth: usize,
|
||||||
section_numbers: [u32; 3],
|
section_numbers: [u32; 4],
|
||||||
|
has_chapters: bool,
|
||||||
equation_number: u32,
|
equation_number: u32,
|
||||||
figure_number: u32,
|
figure_number: u32,
|
||||||
table_number: u32,
|
table_number: u32,
|
||||||
@@ -515,7 +519,8 @@ impl Parser {
|
|||||||
text_style_stack: Vec::new(),
|
text_style_stack: Vec::new(),
|
||||||
style_declarations: Vec::new(),
|
style_declarations: Vec::new(),
|
||||||
group_depth: 0,
|
group_depth: 0,
|
||||||
section_numbers: [0; 3],
|
section_numbers: [0; 4],
|
||||||
|
has_chapters: false,
|
||||||
equation_number: 0,
|
equation_number: 0,
|
||||||
figure_number: 0,
|
figure_number: 0,
|
||||||
table_number: 0,
|
table_number: 0,
|
||||||
@@ -1254,7 +1259,10 @@ impl Parser {
|
|||||||
fn start_heading(&mut self, level: u8, numbered: bool) {
|
fn start_heading(&mut self, level: u8, numbered: bool) {
|
||||||
self.flush_paragraph();
|
self.flush_paragraph();
|
||||||
self.finish_heading();
|
self.finish_heading();
|
||||||
let level = level.clamp(1, 3);
|
let level = level.min(3);
|
||||||
|
if level == 0 {
|
||||||
|
self.has_chapters = true;
|
||||||
|
}
|
||||||
let runs = if numbered {
|
let runs = if numbered {
|
||||||
let number = self.next_section_number(level);
|
let number = self.next_section_number(level);
|
||||||
self.current_reference = number.clone();
|
self.current_reference = number.clone();
|
||||||
@@ -1938,10 +1946,19 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn next_section_number(&mut self, level: u8) -> String {
|
fn next_section_number(&mut self, level: u8) -> String {
|
||||||
let index = usize::from(level.saturating_sub(1).min(2));
|
let index = usize::from(level.min(3));
|
||||||
self.section_numbers[index] += 1;
|
self.section_numbers[index] += 1;
|
||||||
self.section_numbers[index + 1..].fill(0);
|
self.section_numbers[index + 1..].fill(0);
|
||||||
self.section_numbers[..=index]
|
if level == 0 {
|
||||||
|
self.has_chapters = true;
|
||||||
|
return self.section_numbers[0].to_string();
|
||||||
|
}
|
||||||
|
let start = if self.has_chapters && self.section_numbers[0] > 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
};
|
||||||
|
self.section_numbers[start..=index]
|
||||||
.iter()
|
.iter()
|
||||||
.map(u32::to_string)
|
.map(u32::to_string)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
|||||||
+4
-8
@@ -9,8 +9,9 @@ family and true scaled small caps; inline box geometry (`\fbox`, `\makebox`,
|
|||||||
footnotes/`\thanks`; figure/table `[htbp]` placement approximations; page
|
footnotes/`\thanks`; figure/table `[htbp]` placement approximations; page
|
||||||
styles (plain/fancy, `\thispagestyle`, fancyhdr headers/footers, `\thepage`);
|
styles (plain/fancy, `\thispagestyle`, fancyhdr headers/footers, `\thepage`);
|
||||||
geometry-aware `\textwidth`/`\textheight` named length registers; table of
|
geometry-aware `\textwidth`/`\textheight` named length registers; table of
|
||||||
contents and figure/table lists; native PDF rectangles; unified pagination;
|
contents and figure/table lists with dotted leaders; native PDF rectangles; unified pagination;
|
||||||
`\raggedright`/`\raggedleft` declarations and environments
|
`\centering`/`\raggedright`/`\raggedleft` declarations and environments;
|
||||||
|
chapter headings with chapter-prefixed section numbering
|
||||||
(`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).
|
||||||
|
|
||||||
@@ -26,12 +27,7 @@ planner remains).
|
|||||||
needs a vertical-material capture with its own natural width, baseline, and
|
needs a vertical-material capture with its own natural width, baseline, and
|
||||||
nested line/box children in the positioned renderer.
|
nested line/box children in the positioned renderer.
|
||||||
|
|
||||||
## 3. Contents leaders (remaining)
|
## 3. Custom title blocks (remaining)
|
||||||
|
|
||||||
- TOC/list entries use infinite glue for right-aligned page numbers. Dotted
|
|
||||||
leaders require a glue item that repeats a character across its stretch.
|
|
||||||
|
|
||||||
## 4. Custom title blocks (remaining)
|
|
||||||
|
|
||||||
- Let a document-level `\renewcommand{\maketitle}` contribute a real title
|
- Let a document-level `\renewcommand{\maketitle}` contribute a real title
|
||||||
block once the engine's title model can run box material.
|
block once the engine's title model can run box material.
|
||||||
+10
-7
@@ -20,7 +20,7 @@ the source changes; the SVG preview is refreshed per page.
|
|||||||
declarations with group scoping, grouped text-style commands, true small caps
|
declarations with group scoping, grouped text-style commands, true small caps
|
||||||
(lowercase uppercase glyphs at 80% size), and sans/serif/mono small caps.
|
(lowercase uppercase glyphs at 80% size), and sans/serif/mono small caps.
|
||||||
- Paragraphs: Knuth-Plass breaking, TeX hyphenation patterns, justification,
|
- Paragraphs: Knuth-Plass breaking, TeX hyphenation patterns, justification,
|
||||||
centering, `\raggedright`/`\raggedleft` declarations and environments,
|
`\centering`/`\raggedright`/`\raggedleft` declarations and environments,
|
||||||
first-line `\parindent` (17pt default, group-scoped, `\setlength`/
|
first-line `\parindent` (17pt default, group-scoped, `\setlength`/
|
||||||
`\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
|
||||||
@@ -34,8 +34,11 @@ the source changes; the SVG preview is refreshed per page.
|
|||||||
- Notes: `\footnote{...}` page-bottom insertion area with separator rule,
|
- Notes: `\footnote{...}` page-bottom insertion area with separator rule,
|
||||||
superscript markers, and title/author `\thanks`.
|
superscript markers, and title/author `\thanks`.
|
||||||
- Contents: `\tableofcontents`, `\listoffigures`, and `\listoftables`
|
- Contents: `\tableofcontents`, `\listoffigures`, and `\listoftables`
|
||||||
generate headings plus entries from numbered sections and captioned
|
generate headings plus entries from numbered chapters/sections and captioned
|
||||||
figures/tables; page numbers are resolved after pagination.
|
figures/tables, with dotted leaders and page numbers resolved after
|
||||||
|
pagination.
|
||||||
|
- Chapters: `\chapter` is a level-0 heading; chapter numbers prefix section
|
||||||
|
numbers (`1.1`, `1.1.1`) and reset lower counters.
|
||||||
- Class sizes: 10pt/11pt/12pt set the body size and propagate through
|
- Class sizes: 10pt/11pt/12pt set the body size and propagate through
|
||||||
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).
|
||||||
@@ -62,9 +65,9 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
|||||||
- Notes: footnotes inside captions, floats, or arbitrary boxes are not
|
- Notes: footnotes inside captions, floats, or arbitrary boxes are not
|
||||||
collected; the insertion area currently follows the page where the paragraph
|
collected; the insertion area currently follows the page where the paragraph
|
||||||
ends rather than the exact reference line.
|
ends rather than the exact reference line.
|
||||||
- Contents: entries use infinite glue instead of dotted leaders and only
|
- Contents: chapter headings are listed with chapter-prefixed section
|
||||||
numbered headings plus captions are listed; per-chapter contents in
|
numbers, but contents are not split per chapter and `\chapter` does not
|
||||||
book/report are not distinguished.
|
force a page break.
|
||||||
- Miscellaneous: a document-level `\renewcommand{\maketitle}` is ignored in
|
- Miscellaneous: a document-level `\renewcommand{\maketitle}` is ignored in
|
||||||
favor of the engine title block.
|
favor of the engine title block.
|
||||||
|
|
||||||
@@ -72,7 +75,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` (35 tests: 31 compiler
|
- `cargo fmt --check` passes; `cargo test --offline` (37 tests: 33 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
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ const PRELUDE: &str = r#"
|
|||||||
\def\hfil{\hskip0pt plus 1fil\relax}
|
\def\hfil{\hskip0pt plus 1fil\relax}
|
||||||
\def\allowbreak{\penalty0}
|
\def\allowbreak{\penalty0}
|
||||||
\def\nobreak{\penalty10000}
|
\def\nobreak{\penalty10000}
|
||||||
\def\centering{}
|
|
||||||
\def\bibliographystyle#1{}
|
\def\bibliographystyle#1{}
|
||||||
\def\textbf#1{\texrrastylestart{bold}#1\texrrastyleend{bold}}
|
\def\textbf#1{\texrrastylestart{bold}#1\texrrastyleend{bold}}
|
||||||
\def\emph#1{\texrrastylestart{italic}#1\texrrastyleend{italic}}
|
\def\emph#1{\texrrastylestart{italic}#1\texrrastyleend{italic}}
|
||||||
|
|||||||
+26
-5
@@ -37,6 +37,8 @@ use self::layout::{
|
|||||||
// from the article class's 14.4pt setting to 14pt.
|
// from the article class's 14.4pt setting to 14pt.
|
||||||
fn article_heading_font_size(level: u8, base: u8) -> u8 {
|
fn article_heading_font_size(level: u8, base: u8) -> u8 {
|
||||||
match (base, level) {
|
match (base, level) {
|
||||||
|
(12, 0) => 24,
|
||||||
|
(_, 0) => 20,
|
||||||
(12, 1) => 17,
|
(12, 1) => 17,
|
||||||
(_, 1) => 14,
|
(_, 1) => 14,
|
||||||
(12, 2) => 14,
|
(12, 2) => 14,
|
||||||
@@ -1228,6 +1230,18 @@ fn boxworks_line_break(
|
|||||||
previous_font_id = None;
|
previous_font_id = None;
|
||||||
}
|
}
|
||||||
for character in run.text.chars() {
|
for character in run.text.chars() {
|
||||||
|
if character == texrra_core::document::CONTENTS_LEADER_MARKER {
|
||||||
|
horizontal.push(
|
||||||
|
ds::Char {
|
||||||
|
char: character,
|
||||||
|
font: null_font_id,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
previous_character = None;
|
||||||
|
previous_font_id = None;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if inline_markers.contains_key(&character) {
|
if inline_markers.contains_key(&character) {
|
||||||
horizontal.push(
|
horizontal.push(
|
||||||
ds::Char {
|
ds::Char {
|
||||||
@@ -1423,9 +1437,14 @@ fn boxworks_line_break(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut line_items = Vec::new();
|
let mut line_items = Vec::new();
|
||||||
|
let mut leader_pending = false;
|
||||||
for item in &line_box.list {
|
for item in &line_box.list {
|
||||||
match item {
|
match item {
|
||||||
ds::Horizontal::Char(character) => {
|
ds::Horizontal::Char(character) => {
|
||||||
|
if character.char == texrra_core::document::CONTENTS_LEADER_MARKER {
|
||||||
|
leader_pending = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if let Some(marker) = inline_markers.get(&character.char) {
|
if let Some(marker) = inline_markers.get(&character.char) {
|
||||||
match marker {
|
match marker {
|
||||||
InlineMarker::RaiseStart(raise) => {
|
InlineMarker::RaiseStart(raise) => {
|
||||||
@@ -1472,11 +1491,13 @@ fn boxworks_line_break(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ds::Horizontal::Glue(glue) => {
|
ds::Horizontal::Glue(glue) => {
|
||||||
line_items.push(text_layout::LineItem::Glue(paragraph_glue_width(
|
let width = paragraph_glue_width(&glue.value, line_box.glue_order, ratio);
|
||||||
&glue.value,
|
if leader_pending {
|
||||||
line_box.glue_order,
|
leader_pending = false;
|
||||||
ratio,
|
line_items.push(text_layout::LineItem::Leader(width));
|
||||||
)));
|
} else {
|
||||||
|
line_items.push(text_layout::LineItem::Glue(width));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ds::Horizontal::Kern(kern) => {
|
ds::Horizontal::Kern(kern) => {
|
||||||
line_items.push(text_layout::LineItem::Kern(kern.width));
|
line_items.push(text_layout::LineItem::Kern(kern.width));
|
||||||
|
|||||||
@@ -1392,6 +1392,7 @@ pub(super) fn build_positioned_pages(
|
|||||||
|
|
||||||
let paragraph_alignment = runs.iter().find_map(|run| run.alignment);
|
let paragraph_alignment = runs.iter().find_map(|run| run.alignment);
|
||||||
let ragged = paragraph_alignment.is_some();
|
let ragged = paragraph_alignment.is_some();
|
||||||
|
let centered = paragraph_alignment == Some(ParagraphAlignment::Centered);
|
||||||
let x = match (paragraph_alignment, &line.content) {
|
let x = match (paragraph_alignment, &line.content) {
|
||||||
(
|
(
|
||||||
Some(ParagraphAlignment::RaggedLeft),
|
Some(ParagraphAlignment::RaggedLeft),
|
||||||
@@ -1420,7 +1421,7 @@ pub(super) fn build_positioned_pages(
|
|||||||
content: line.content,
|
content: line.content,
|
||||||
y: cursor,
|
y: cursor,
|
||||||
x,
|
x,
|
||||||
centered: false,
|
centered,
|
||||||
ragged,
|
ragged,
|
||||||
}));
|
}));
|
||||||
cursor = cursor.saturating_add(line_height);
|
cursor = cursor.saturating_add(line_height);
|
||||||
|
|||||||
@@ -1738,6 +1738,18 @@ fn ragged_left_primitive(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn centering_primitive(
|
||||||
|
token: token::Token,
|
||||||
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
|
) -> texlang::prelude::Result<()> {
|
||||||
|
write_event(
|
||||||
|
input,
|
||||||
|
token,
|
||||||
|
FrontendEventKind::ParagraphAlignment(texrra_core::document::ParagraphAlignment::Centered),
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn table_of_contents_primitive(
|
fn table_of_contents_primitive(
|
||||||
token: token::Token,
|
token: token::Token,
|
||||||
input: &mut vm::ExecutionInput<CompilerState>,
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
@@ -5820,6 +5832,13 @@ fn heading_start_primitive(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn chapter_primitive(
|
||||||
|
token: token::Token,
|
||||||
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
|
) -> texlang::prelude::Result<()> {
|
||||||
|
heading_primitive(token, input, 0)
|
||||||
|
}
|
||||||
|
|
||||||
fn section_primitive(
|
fn section_primitive(
|
||||||
token: token::Token,
|
token: token::Token,
|
||||||
input: &mut vm::ExecutionInput<CompilerState>,
|
input: &mut vm::ExecutionInput<CompilerState>,
|
||||||
@@ -6801,6 +6820,10 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn<Compil
|
|||||||
"raggedleft",
|
"raggedleft",
|
||||||
texlang::command::BuiltIn::new_execution(ragged_left_primitive),
|
texlang::command::BuiltIn::new_execution(ragged_left_primitive),
|
||||||
);
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"centering",
|
||||||
|
texlang::command::BuiltIn::new_execution(centering_primitive),
|
||||||
|
);
|
||||||
built_ins.insert(
|
built_ins.insert(
|
||||||
"pagestyle",
|
"pagestyle",
|
||||||
texlang::command::BuiltIn::new_execution(page_style_primitive),
|
texlang::command::BuiltIn::new_execution(page_style_primitive),
|
||||||
@@ -7187,6 +7210,10 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn<Compil
|
|||||||
"texrraend",
|
"texrraend",
|
||||||
texlang::command::BuiltIn::new_execution(end_environment_primitive),
|
texlang::command::BuiltIn::new_execution(end_environment_primitive),
|
||||||
);
|
);
|
||||||
|
built_ins.insert(
|
||||||
|
"chapter",
|
||||||
|
texlang::command::BuiltIn::new_execution(chapter_primitive),
|
||||||
|
);
|
||||||
built_ins.insert(
|
built_ins.insert(
|
||||||
"section",
|
"section",
|
||||||
texlang::command::BuiltIn::new_execution(section_primitive),
|
texlang::command::BuiltIn::new_execution(section_primitive),
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ pub(super) enum LineItem {
|
|||||||
},
|
},
|
||||||
Kern(Scaled),
|
Kern(Scaled),
|
||||||
Glue(Scaled),
|
Glue(Scaled),
|
||||||
|
Leader(Scaled),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TextSpan {
|
struct TextSpan {
|
||||||
@@ -105,6 +106,7 @@ enum TextLineItem {
|
|||||||
},
|
},
|
||||||
Kern(Mm),
|
Kern(Mm),
|
||||||
Glue(Mm),
|
Glue(Mm),
|
||||||
|
Leader(Mm),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct PositionedRule {
|
pub(super) struct PositionedRule {
|
||||||
@@ -245,6 +247,18 @@ impl TextLine {
|
|||||||
);
|
);
|
||||||
items.push(TextLineItem::Glue(scaled_to_mm(*width)));
|
items.push(TextLineItem::Glue(scaled_to_mm(*width)));
|
||||||
}
|
}
|
||||||
|
LineItem::Leader(width) => {
|
||||||
|
flush_text(
|
||||||
|
&mut items,
|
||||||
|
&mut text,
|
||||||
|
&mut text_style,
|
||||||
|
cjk_family,
|
||||||
|
monospace_family,
|
||||||
|
sans_family,
|
||||||
|
font_size,
|
||||||
|
);
|
||||||
|
items.push(TextLineItem::Leader(scaled_to_mm(*width)));
|
||||||
|
}
|
||||||
LineItem::Kern(width) => {
|
LineItem::Kern(width) => {
|
||||||
flush_text(
|
flush_text(
|
||||||
&mut items,
|
&mut items,
|
||||||
@@ -311,6 +325,7 @@ impl TextLine {
|
|||||||
}
|
}
|
||||||
TextLineItem::Glue(_) if index < last_content => x += natural_space,
|
TextLineItem::Glue(_) if index < last_content => x += natural_space,
|
||||||
TextLineItem::Glue(_) => {}
|
TextLineItem::Glue(_) => {}
|
||||||
|
TextLineItem::Leader(width) => x += *width,
|
||||||
TextLineItem::Kern(width) => x += *width,
|
TextLineItem::Kern(width) => x += *width,
|
||||||
TextLineItem::Rule { width, .. } => x += *width,
|
TextLineItem::Rule { width, .. } => x += *width,
|
||||||
TextLineItem::Frame { width, .. } => x += *width,
|
TextLineItem::Frame { width, .. } => x += *width,
|
||||||
@@ -393,6 +408,32 @@ impl TextLine {
|
|||||||
natural_space
|
natural_space
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
TextLineItem::Leader(width) => {
|
||||||
|
let style = Style::new().with_font_size(self.font_size);
|
||||||
|
let dot = style.str_width(fonts, ".");
|
||||||
|
let space = style.str_width(fonts, " ");
|
||||||
|
let unit = f64::from(dot + space);
|
||||||
|
let width_mm = f64::from(*width);
|
||||||
|
let count = ((width_mm / unit).floor() as usize).max(1);
|
||||||
|
let mut leader = String::new();
|
||||||
|
for index in 0..count {
|
||||||
|
if index > 0 {
|
||||||
|
leader.push(' ');
|
||||||
|
}
|
||||||
|
leader.push('.');
|
||||||
|
}
|
||||||
|
let text_width = style.str_width(fonts, &leader);
|
||||||
|
spans.push(PositionedSpan {
|
||||||
|
text: leader,
|
||||||
|
style,
|
||||||
|
x,
|
||||||
|
y_offset: Mm::from(0.0),
|
||||||
|
});
|
||||||
|
x += text_width;
|
||||||
|
if text_width < *width {
|
||||||
|
x += *width - text_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
TextLineItem::Kern(width) => x += *width,
|
TextLineItem::Kern(width) => x += *width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-1
@@ -804,12 +804,12 @@ Beta paragraph.
|
|||||||
assert_eq!(value["status"], "ok", "{value}");
|
assert_eq!(value["status"], "ok", "{value}");
|
||||||
assert_eq!(pages(&value).len(), 2, "{value}");
|
assert_eq!(pages(&value).len(), 2, "{value}");
|
||||||
let svg = page_svg(&value, 0);
|
let svg = page_svg(&value, 0);
|
||||||
eprintln!("{svg}");
|
|
||||||
assert!(svg.contains(">Contents</text>"), "missing contents heading");
|
assert!(svg.contains(">Contents</text>"), "missing contents heading");
|
||||||
assert!(svg.contains(">Alpha</text>"), "missing first entry");
|
assert!(svg.contains(">Alpha</text>"), "missing first entry");
|
||||||
assert!(svg.contains(">Beta</text>"), "missing second entry");
|
assert!(svg.contains(">Beta</text>"), "missing second entry");
|
||||||
assert!(svg.contains(">1</text>"), "missing first page number");
|
assert!(svg.contains(">1</text>"), "missing first page number");
|
||||||
assert!(svg.contains(">2</text>"), "missing second page number");
|
assert!(svg.contains(">2</text>"), "missing second page number");
|
||||||
|
assert!(svg.contains(". . ."), "missing dotted leader: {svg}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -924,3 +924,56 @@ fn ragged_alignment_declarations_are_honoured() {
|
|||||||
"raggedright still justified the line: ragged={ragged_beta}, justified={justified_beta}\nRAGGED={ragged_svg}\nJUSTIFIED={justified_svg}"
|
"raggedright still justified the line: ragged={ragged_beta}, justified={justified_beta}\nRAGGED={ragged_svg}\nJUSTIFIED={justified_svg}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn centering_declaration_centers_a_paragraph() {
|
||||||
|
let prefix = r"\documentclass{article}
|
||||||
|
\usepackage[margin=6.5cm]{geometry}
|
||||||
|
\begin{document}
|
||||||
|
";
|
||||||
|
let centered_source =
|
||||||
|
format!("{prefix}{{\\centering alpha beta}}\n\nplain paragraph\n\\end{{document}}");
|
||||||
|
let left_source = format!("{prefix}alpha beta\n\nplain paragraph\n\\end{{document}}");
|
||||||
|
let centered = fresh_preview(¢ered_source, "centered.tex");
|
||||||
|
let left = fresh_preview(&left_source, "left.tex");
|
||||||
|
let centered_svg = page_svg(¢ered, 0);
|
||||||
|
let left_svg = page_svg(&left, 0);
|
||||||
|
let centered_alpha = text_x(¢ered_svg, "alpha");
|
||||||
|
let left_alpha = text_x(&left_svg, "alpha");
|
||||||
|
assert!(
|
||||||
|
centered_alpha > left_alpha + 10.0,
|
||||||
|
"centering did not move the line: centered={centered_alpha}, left={left_alpha}\n{centered_svg}"
|
||||||
|
);
|
||||||
|
let plain_alpha = text_x(¢ered_svg, "plain");
|
||||||
|
let left_plain = text_x(&left_svg, "plain");
|
||||||
|
assert!(
|
||||||
|
(plain_alpha - left_plain).abs() < 0.5,
|
||||||
|
"centering leaked into the following paragraph: centered={plain_alpha}, left={left_plain}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn chapter_headings_number_sections_and_enter_contents() {
|
||||||
|
let source = r#"\documentclass{book}
|
||||||
|
\begin{document}
|
||||||
|
\tableofcontents
|
||||||
|
\chapter{First Chapter}
|
||||||
|
\section{Alpha}
|
||||||
|
\subsection{Beta}
|
||||||
|
\chapter{Second Chapter}
|
||||||
|
\section{Gamma}
|
||||||
|
\end{document}
|
||||||
|
"#;
|
||||||
|
let value = fresh_preview(source, "chapters.tex");
|
||||||
|
assert_eq!(value["status"], "ok", "{}", value["message"]);
|
||||||
|
let svg = page_svg(&value, 0);
|
||||||
|
for needle in [
|
||||||
|
"Contents", "First", "Chapter", "Alpha", "Beta", "Gamma", "1.1", "1.1.1", "2.1",
|
||||||
|
] {
|
||||||
|
assert!(svg.contains(needle), "chapter numbering is missing : {svg}");
|
||||||
|
}
|
||||||
|
assert!(
|
||||||
|
!svg.contains("0.1"),
|
||||||
|
"section was numbered under chapter zero: {svg}"
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user