diff --git a/README.md b/README.md index 1104baf..ae4f1cf 100644 --- a/README.md +++ b/README.md @@ -467,7 +467,7 @@ from the font's MATH assembly parts. `\\left...\\right` target sizing follows the assignable TeX parameters `\\delimiterfactor` (default 901) and `\\delimitershortfall` (default 5pt), including local and global assignments. -In route-D, math uses Computer Modern metrics from the bundled `cmmi10`, `cmsy10`, `cmex10`, `msbm10` and `eufm10` TFMs and embeds their Type1 programs, so italic letters, relation symbols, big operators, `\mathcal` capitals, `\mathbb` capitals and `\mathfrak` Fraktur letters each paint with their own face. Fractions can be written as `\frac` or with TeX's infix forms (`\over`, `\atop`, `\choose`, `\brace`, `\brack`, `\overwithdelims`, `\atopwithdelims`); only `\over`-style fractions draw a bar and fractions never draw parentheses. `\left`/`\right` choose CMEX delimiter sizes from the body extent using TeX's delimiterfactor and shortfall, `\middle` delimiters are sized with their group, and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size. `align`/`align*` displays share column widths, right-align even columns at their relations, and number each row (with `\tag`/`\notag` per row); `gather`/`gather*` centre each row instead. Inter-atom spacing uses TeX's 3/4/5mu classes (`1mu` is `1/18em`), `\mid` is a relation and `\colon` punctuation, and `\mskip`/`\mkern`/`\mspace`/`\hskip`/`\kern`/`\hspace` scan TeX dimensions, taking the natural width of any `plus`/`minus` parts. +Route-D text faces follow the NFSS declarations and compose with the surrounding run: `\sffamily\bfseries` selects cmssbx10, `\sffamily\itshape` selects cmssi10, and bold italic sans substitutes cmssbx10 because Computer Modern has no sans bold italic. All eight text programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10, cmssbx10, cmssi10) are embedded as Type1 outlines. In route-D, math uses Computer Modern metrics from the bundled `cmmi10`, `cmsy10`, `cmex10`, `msbm10` and `eufm10` TFMs and embeds their Type1 programs, so italic letters, relation symbols, big operators, `\mathcal` capitals, `\mathbb` capitals and `\mathfrak` Fraktur letters each paint with their own face. Fractions can be written as `\frac` or with TeX's infix forms (`\over`, `\atop`, `\choose`, `\brace`, `\brack`, `\overwithdelims`, `\atopwithdelims`); only `\over`-style fractions draw a bar and fractions never draw parentheses. `\left`/`\right` choose CMEX delimiter sizes from the body extent using TeX's delimiterfactor and shortfall, `\middle` delimiters are sized with their group, and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size. `align`/`align*` displays share column widths, right-align even columns at their relations, and number each row (with `\tag`/`\notag` per row); `gather`/`gather*` centre each row instead. Inter-atom spacing uses TeX's 3/4/5mu classes (`1mu` is `1/18em`), `\mid` is a relation and `\colon` punctuation, and `\mskip`/`\mkern`/`\mspace`/`\hskip`/`\kern`/`\hspace` scan TeX dimensions, taking the natural width of any `plus`/`minus` parts. Route-D integration can also be checked against a real TeX page: `cargo test -p texrra-tex-core --test route_d` includes `route_d_page_matches_pdftex_raster_geometry`, which renders the route-D PDF and a pdfTeX Letter page at the same scaled-point geometry, rasterizes both with `pdftoppm`, and compares ink line count plus left, right, and bottom edges. It is skipped when `pdflatex`/`pdftoppm` are unavailable. `route_d_multiline_bands_track_pdftex` extends that check to a wrapped paragraph: the pixel rows that carry ink form one band per TeX line, and every band top, bottom, left edge and (except for the last line, whose width follows the break point) right edge must land within a couple of pixels of the pdfTeX page. diff --git a/assets/fonts/cmssbx10.pfb b/assets/fonts/cmssbx10.pfb new file mode 100644 index 0000000..e55d6c9 Binary files /dev/null and b/assets/fonts/cmssbx10.pfb differ diff --git a/assets/fonts/cmssi10.pfb b/assets/fonts/cmssi10.pfb new file mode 100644 index 0000000..63b30b9 Binary files /dev/null and b/assets/fonts/cmssi10.pfb differ diff --git a/crates/texrra-tex-core/assets/cmssbx10.tfm b/crates/texrra-tex-core/assets/cmssbx10.tfm new file mode 100644 index 0000000..ee81c2a Binary files /dev/null and b/crates/texrra-tex-core/assets/cmssbx10.tfm differ diff --git a/crates/texrra-tex-core/assets/cmssi10.tfm b/crates/texrra-tex-core/assets/cmssi10.tfm new file mode 100644 index 0000000..eef81c2 Binary files /dev/null and b/crates/texrra-tex-core/assets/cmssi10.tfm differ diff --git a/crates/texrra-tex-core/src/cmr10.rs b/crates/texrra-tex-core/src/cmr10.rs index 4cdd95c..12cad5e 100644 --- a/crates/texrra-tex-core/src/cmr10.rs +++ b/crates/texrra-tex-core/src/cmr10.rs @@ -15,6 +15,8 @@ pub enum Cmr10Metrics { BoldItalic, Mono, Sans, + SansBold, + SansItalic, /// Calligraphic capitals from cmsy10 (`\mathcal`). MathCalligraphic, /// Blackboard-bold capitals from msbm10 (`\mathbb`). @@ -31,6 +33,8 @@ static CMTI10_TFM: &[u8] = include_bytes!("../assets/cmti10.tfm"); static CMBXTI10_TFM: &[u8] = include_bytes!("../assets/cmbxti10.tfm"); static CMTT10_TFM: &[u8] = include_bytes!("../assets/cmtt10.tfm"); static CMSS10_TFM: &[u8] = include_bytes!("../assets/cmss10.tfm"); +static CMSSBX10_TFM: &[u8] = include_bytes!("../assets/cmssbx10.tfm"); +static CMSSI10_TFM: &[u8] = include_bytes!("../assets/cmssi10.tfm"); static CMMI10_TFM: &[u8] = include_bytes!("../assets/cmmi10.tfm"); static CMEX10_TFM: &[u8] = include_bytes!("../assets/cmex10.tfm"); static CMSY10_TFM: &[u8] = include_bytes!("../assets/cmsy10.tfm"); @@ -43,6 +47,8 @@ static CMTI10_METRICS: OnceLock = OnceLock::new(); static CMBXTI10_METRICS: OnceLock = OnceLock::new(); static CMTT10_METRICS: OnceLock = OnceLock::new(); static CMSS10_METRICS: OnceLock = OnceLock::new(); +static CMSSBX10_METRICS: OnceLock = OnceLock::new(); +static CMSSI10_METRICS: OnceLock = OnceLock::new(); static CMMI10_METRICS: OnceLock = OnceLock::new(); static CMEX10_METRICS: OnceLock = OnceLock::new(); static CMSY10_METRICS: OnceLock = OnceLock::new(); @@ -77,6 +83,14 @@ fn parse_sans() -> TfmMetrics { parse(CMSS10_TFM) } +fn parse_sans_bold() -> TfmMetrics { + parse(CMSSBX10_TFM) +} + +fn parse_sans_italic() -> TfmMetrics { + parse(CMSSI10_TFM) +} + fn parse_math_italic() -> TfmMetrics { parse(CMMI10_TFM) } @@ -125,6 +139,8 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics { Cmr10Metrics::BoldItalic => CMBXTI10_METRICS.get_or_init(parse_bold_italic), Cmr10Metrics::Mono => CMTT10_METRICS.get_or_init(parse_mono), Cmr10Metrics::Sans => CMSS10_METRICS.get_or_init(parse_sans), + Cmr10Metrics::SansBold => CMSSBX10_METRICS.get_or_init(parse_sans_bold), + Cmr10Metrics::SansItalic => CMSSI10_METRICS.get_or_init(parse_sans_italic), Cmr10Metrics::Math => CMR10_METRICS.get_or_init(parse_roman), Cmr10Metrics::MathCalligraphic => CMSY10_METRICS.get_or_init(parse_math_symbol), Cmr10Metrics::MathBlackboard => MSBM10_METRICS.get_or_init(parse_blackboard), @@ -146,6 +162,8 @@ impl Cmr10Metrics { ParagraphFont::BoldItalic => Self::BoldItalic, ParagraphFont::Mono => Self::Mono, ParagraphFont::Sans => Self::Sans, + ParagraphFont::SansBold => Self::SansBold, + ParagraphFont::SansItalic => Self::SansItalic, } } @@ -162,6 +180,8 @@ impl Cmr10Metrics { 8 => Self::Math, 9 => Self::MathBlackboard, 10 => Self::MathFraktur, + 11 => Self::SansBold, + 12 => Self::SansItalic, _ => Self::Roman, } } @@ -660,4 +680,18 @@ mod cmex_delimiter_tests { assert!(cmex_delimiter('.', 1).is_none()); assert!(cmex_delimiter('x', 1).is_none()); } + + #[test] + fn sans_bold_and_italic_use_their_own_metrics() { + let regular = Cmr10Metrics::Sans.width('A'); + let bold = Cmr10Metrics::SansBold.width('A'); + let italic = Cmr10Metrics::SansItalic.width('A'); + assert_eq!(bold, metrics_for(Cmr10Metrics::SansBold).width('A')); + assert_eq!(italic, metrics_for(Cmr10Metrics::SansItalic).width('A')); + assert_ne!(regular, bold); + assert_ne!(Cmr10Metrics::Sans.space(), Cmr10Metrics::SansBold.space()); + assert!(italic > 0); + assert_eq!(Cmr10Metrics::for_pdf_slot(11), Cmr10Metrics::SansBold); + assert_eq!(Cmr10Metrics::for_pdf_slot(12), Cmr10Metrics::SansItalic); + } } diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 939b821..b3b3564 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -6236,6 +6236,30 @@ mod tests { assert!(svg.contains("font-family=\"sans-serif\"")); } + #[test] + fn sans_bold_paragraph_paints_with_the_sans_bold_face() { + let unit = Unit::paragraph_with_face(1, "sans bold", ParagraphFont::SansBold); + let page = Page { + items: unit.items, + insertions: Vec::new(), + marks: Vec::new(), + floats: Vec::new(), + sources: Vec::new(), + hash: 0, + }; + let list = page.display_list(); + assert!(list.items.iter().any(|item| matches!( + item, + crate::render::DisplayItem::Text { + font: crate::render::FontFace::SansBold, + .. + } + ))); + let svg = list.to_svg(); + assert!(svg.contains("font-family=\"sans-serif\"")); + assert!(svg.contains("font-weight=\"bold\"")); + } + #[test] fn mono_paragraph_paints_with_a_mono_face() { let unit = Unit::paragraph_with_face(1, "code 123", ParagraphFont::Mono); diff --git a/crates/texrra-tex-core/src/paragraph.rs b/crates/texrra-tex-core/src/paragraph.rs index 171f43a..402b63e 100755 --- a/crates/texrra-tex-core/src/paragraph.rs +++ b/crates/texrra-tex-core/src/paragraph.rs @@ -293,6 +293,8 @@ pub enum ParagraphFont { BoldItalic, Mono, Sans, + SansBold, + SansItalic, } impl ParagraphFont { @@ -303,7 +305,10 @@ impl ParagraphFont { Self::Italic => Self::Roman, Self::Bold => Self::BoldItalic, Self::BoldItalic => Self::Bold, - Self::Mono | Self::Sans => self, + Self::Mono => self, + Self::Sans => Self::SansItalic, + Self::SansBold => Self::SansBold, + Self::SansItalic => Self::Sans, } } @@ -312,7 +317,8 @@ impl ParagraphFont { match self { Self::Roman | Self::Bold => Self::Bold, Self::Italic | Self::BoldItalic => Self::BoldItalic, - Self::Mono | Self::Sans => self, + Self::Mono => self, + Self::Sans | Self::SansBold | Self::SansItalic => Self::SansBold, } } @@ -321,7 +327,9 @@ impl ParagraphFont { match self { Self::Bold | Self::Roman => Self::Roman, Self::BoldItalic | Self::Italic => Self::Italic, - Self::Mono | Self::Sans => self, + Self::Mono => self, + Self::Sans | Self::SansItalic => self, + Self::SansBold => Self::Sans, } } @@ -330,7 +338,10 @@ impl ParagraphFont { match self { Self::Roman | Self::Italic => Self::Italic, Self::Bold | Self::BoldItalic => Self::BoldItalic, - Self::Mono | Self::Sans => self, + Self::Mono => self, + Self::Sans => Self::SansItalic, + Self::SansBold => Self::SansBold, + Self::SansItalic => Self::SansItalic, } } @@ -339,7 +350,9 @@ impl ParagraphFont { match self { Self::Roman | Self::Italic => Self::Roman, Self::Bold | Self::BoldItalic => Self::Bold, - Self::Mono | Self::Sans => self, + Self::Mono => self, + Self::Sans | Self::SansItalic => Self::Sans, + Self::SansBold => Self::SansBold, } } @@ -347,9 +360,20 @@ impl ParagraphFont { pub const fn roman_family(self) -> Self { match self { Self::Mono | Self::Sans => Self::Roman, + Self::SansBold => Self::Bold, + Self::SansItalic => Self::Italic, other => other, } } + + /// `\textsf`: change family, keeping the inherited weight and shape. + pub const fn sans_family(self) -> Self { + match self { + Self::Bold | Self::BoldItalic => Self::SansBold, + Self::Italic => Self::SansItalic, + _ => Self::Sans, + } + } } impl Default for ParagraphFont { @@ -2309,3 +2333,32 @@ mod tests { assert_eq!(measured(1), 6, "looser paragraph"); } } + +#[cfg(test)] +mod font_tests { + use super::ParagraphFont; + + #[test] + fn sans_faces_compose_with_weight_and_shape() { + assert_eq!(ParagraphFont::Sans.bolded(), ParagraphFont::SansBold); + assert_eq!(ParagraphFont::Sans.emphasized(), ParagraphFont::SansItalic); + assert_eq!(ParagraphFont::SansItalic.emphasized(), ParagraphFont::Sans); + assert_eq!( + ParagraphFont::SansBold.emphasized(), + ParagraphFont::SansBold + ); + assert_eq!(ParagraphFont::SansBold.medium(), ParagraphFont::Sans); + assert_eq!(ParagraphFont::SansItalic.upright(), ParagraphFont::Sans); + assert_eq!(ParagraphFont::SansBold.roman_family(), ParagraphFont::Bold); + assert_eq!( + ParagraphFont::SansItalic.roman_family(), + ParagraphFont::Italic + ); + assert_eq!(ParagraphFont::Bold.sans_family(), ParagraphFont::SansBold); + assert_eq!( + ParagraphFont::Italic.sans_family(), + ParagraphFont::SansItalic + ); + assert_eq!(ParagraphFont::Mono.sans_family(), ParagraphFont::Sans); + } +} diff --git a/crates/texrra-tex-core/src/pdf.rs b/crates/texrra-tex-core/src/pdf.rs index b709a9e..b86aaf9 100755 --- a/crates/texrra-tex-core/src/pdf.rs +++ b/crates/texrra-tex-core/src/pdf.rs @@ -16,7 +16,7 @@ use crate::cmr10::Cmr10Metrics; use crate::render::{DisplayItem, DisplayList, FontFace}; use crate::type1::Type1Font; -const FACE_COUNT: usize = 11; +const FACE_COUNT: usize = 13; fn deflate(bytes: &[u8]) -> Vec { let mut encoder = ZlibEncoder::new(Vec::new(), Compression::default()); @@ -98,6 +98,18 @@ static FULL_FACES: [PdfFace; FACE_COUNT] = [ italic_angle: 0, font: OnceLock::new(), }, + PdfFace { + bytes: include_bytes!("../../../assets/fonts-subset/LiberationSans-Bold.ttf"), + base: "LiberationSans-Bold", + italic_angle: 0, + font: OnceLock::new(), + }, + PdfFace { + bytes: include_bytes!("../../../assets/fonts-subset/LiberationSans-Italic.ttf"), + base: "LiberationSans-Italic", + italic_angle: -12, + font: OnceLock::new(), + }, ]; static MIN_FACES: [PdfFace; FACE_COUNT] = [ @@ -167,6 +179,18 @@ static MIN_FACES: [PdfFace; FACE_COUNT] = [ italic_angle: 0, font: OnceLock::new(), }, + PdfFace { + bytes: include_bytes!("../../../assets/fonts-subset-min/LiberationSans-Bold.ttf"), + base: "LiberationSans-Bold", + italic_angle: 0, + font: OnceLock::new(), + }, + PdfFace { + bytes: include_bytes!("../../../assets/fonts-subset-min/LiberationSans-Italic.ttf"), + base: "LiberationSans-Italic", + italic_angle: -12, + font: OnceLock::new(), + }, ]; fn minimal_text_char(ch: char) -> bool { @@ -300,6 +324,8 @@ fn font_resource(font: FontFace) -> &'static str { FontFace::MathExtension => "F9", FontFace::MathBlackboard => "F10", FontFace::MathFraktur => "F11", + FontFace::SansBold => "F12", + FontFace::SansItalic => "F13", } } @@ -326,6 +352,8 @@ fn type1_bytes(slot: usize) -> Option<&'static [u8]> { Some(include_bytes!("../../../assets/fonts/cmex10.pfb")), Some(include_bytes!("../../../assets/fonts/msbm10.pfb")), Some(include_bytes!("../../../assets/fonts/eufm10.pfb")), + Some(include_bytes!("../../../assets/fonts/cmssbx10.pfb")), + Some(include_bytes!("../../../assets/fonts/cmssi10.pfb")), ]; PFBS[slot] } @@ -931,6 +959,36 @@ mod type1_pdf_tests { assert!(!text.contains("/BaseFont /CMR10"), "{text}"); } + #[test] + fn sans_bold_text_embeds_cmssbx10() { + let mut list = hello_list(); + list.items[0] = DisplayItem::Text { + x: 0, + y: 800_000, + size: 655_360, + text: "Sans".to_string(), + font: FontFace::SansBold, + }; + let pdf = write(&[list]); + let text = String::from_utf8_lossy(&pdf); + assert!(text.contains("/BaseFont /CMSSBX10"), "{text}"); + } + + #[test] + fn sans_italic_text_embeds_cmssi10() { + let mut list = hello_list(); + list.items[0] = DisplayItem::Text { + x: 0, + y: 800_000, + size: 655_360, + text: "Sans".to_string(), + font: FontFace::SansItalic, + }; + let pdf = write(&[list]); + let text = String::from_utf8_lossy(&pdf); + assert!(text.contains("/BaseFont /CMSSI10"), "{text}"); + } + #[test] fn math_italic_text_embeds_cmmi10() { let mut list = hello_list(); diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index 922455b..6ed1f18 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -29,6 +29,10 @@ pub enum FontFace { MathBlackboard, /// Euler Fraktur (`eufm10`). MathFraktur, + /// Computer Modern sans-serif bold (`cmssbx10`). + SansBold, + /// Computer Modern sans-serif italic (`cmssi10`). + SansItalic, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -159,19 +163,28 @@ impl DisplayList { let size = *size as f64 / 65_536.0; let family = if matches!(font, FontFace::Mono) { "monospace" - } else if matches!(font, FontFace::Sans) { + } else if matches!( + font, + FontFace::Sans | FontFace::SansBold | FontFace::SansItalic + ) { "sans-serif" } else { "serif" }; - let weight = if matches!(font, FontFace::Bold | FontFace::BoldItalic) { + let weight = if matches!( + font, + FontFace::Bold | FontFace::BoldItalic | FontFace::SansBold + ) { " font-weight=\"bold\"" } else { "" }; let style = if matches!( font, - FontFace::Italic | FontFace::BoldItalic | FontFace::MathItalic + FontFace::Italic + | FontFace::BoldItalic + | FontFace::MathItalic + | FontFace::SansItalic ) { " font-style=\"italic\"" } else { @@ -271,6 +284,8 @@ fn paragraph_face(font: ParagraphFont) -> FontFace { ParagraphFont::BoldItalic => FontFace::BoldItalic, ParagraphFont::Mono => FontFace::Mono, ParagraphFont::Sans => FontFace::Sans, + ParagraphFont::SansBold => FontFace::SansBold, + ParagraphFont::SansItalic => FontFace::SansItalic, } } diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index 1aa7338..a650cca 100644 --- a/docs/ROUTE_D_PLAN.md +++ b/docs/ROUTE_D_PLAN.md @@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`, `\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and -PDF opt-in with `?engine=route-d`). 571 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 577 workspace tests are green and no oracle fixture is ignored. Status after G1 (P0-P2): the paragraph model reproduces TeX's passes, diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index e9e0edc..e80590a 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -132,7 +132,7 @@ and justification. | M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions, bottom floats or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset, and `\mark{...}`/`\marks{...}` writes inside the routine are carried to the following page's mark list with their class; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets the pages the routine has not seen yet, even when the document raises insertion material; only a document that defers bottom floats keeps its initial goal, because the carried queue cannot be rebuilt after a retarget), `\ht255`, `\dp255` and `\wd255` expose the page box height, depth and width to the routine, and `\hsize` is readable (and assignable for the rest of the run) while `\wd255` tracks it; route-D sets `\hsize` from its 480pt text measure, insertion class registers `\count`/`\dimen`/`\skip` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments that outlive the routine (the paged builder runs the routine after each page, so an assigned `\dimen` or `\count` changes the insertion capacity and reservation of later pages); the configured `\skip` also reserves space above its class once per page in the paged builder, and a `\skip` assignment rebuilds the pages the routine has not seen yet with the new reservation, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `\maxdeadcycles` (default 25, assignable) makes the page builder ship the page itself once that many dead cycles have accumulated, `PageFragment::penalty` carries the break penalty (`\outputpenalty`: the penalty value when the break landed on a penalty, otherwise 10000, as TeX reports for glue breaks, goal overflow and the final page), and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine; `\vbadness` reports the badness of the break that produced the page and `\insertpenalties` the number of insertion items held over from it | | M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; the paged builder splits a tall alignment into page-sized row chunks that keep the table's column widths, so long tables continue across pages; `p{width}` paragraph columns wrap cell text and grow row heights, wrapped rows participate in row-level splitting, explicit per-column `\tabskip` glue is honoured through layout, painting and page chunks, and booktabs rules carry their own weights and spans (`\toprule`/`\bottomrule` 0.8pt, `\midrule`/`\cmidrule` 0.5pt, with `\cmidrule(lr){a-b}` trimming and column ranges), `@{}` / `@{\hspace{...}}` column expressions override the inter-column glue, and row-boundary `\noalign{\vskip ...}` glue is honoured by layout, painting and page chunks; longtable head/foot sections (`\endfirsthead`/`\endhead`/`\endfoot`/`\endlastfoot`) are parsed, continuation chunks repeat the head rows and the foot block paints once at the end, LaTeX `tabular` environments are captured and laid out through the same `\halign` path (rules are stripped from the column spec, `p{...}`/`m{...}`/`b{...}` become wrapping columns, `@{}` expressions are ignored for spacing), though `\valign`, nested tables and full tabular parity remain open | | M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with Computer Modern metrics (italic letters from the bundled `cmmi10`, big operators from `cmex10`, symbols such as `\times`/`\leq`/`\infty` from `cmsy10`, with `cmmi10`, `cmsy10` and `cmex10` glyphs embedded as Type1 outlines), `\left...\right` delimiter selection through CMEX size variants using TeX's delimiterfactor and shortfall, accents and a display-list painter; display formulas wider than the measure are split at top-level binary/relation operators into multiple lines (an approximation of TeX's `\split` behaviour; `align`/`align*` displays share column widths and number each row, while `gather`/`gather*` centre every row); CMEX delimiter size variants back `\big`/`\Big`/`\bigg`/`\Bigg`; inter-atom spacing uses TeX's full atom-class table with binary-operator normalisation, with `1mu` = `1/18em` (a thin space is 3mu = 1.67pt at 10pt); `\mid` is a relation while `\colon` is punctuation; `\mskip`, `\mkern`, `\mspace`, `\hskip`, `\kern` and `\hspace` scan TeX dimensions (`mu`, `pt`, `em`, ...) and contribute their natural width, accepting `plus`/`minus` parts even though math boxes are not glue lists; route-D numbers `equation` environments and resolves `\eqref`/`\ref` through their labels; `\tag` overrides the number and `\notag`/`\nonumber` suppress it; math italic letters are embedded as Computer Modern Type1 outlines (`cmmi10`), and math alphabets map `\\mathbf`/`\\mathit`/`\\mathsf`/`\\mathtt` onto the bold, math-italic, sans and mono faces with their TFMs and `\\mathcal` onto the cmsy10 calligraphic capitals; `\mathfrak` maps onto the bundled eufm10 Fraktur letters (embedded as Type1 outlines); infix fractions `\over`, `\atop`, `\choose`, `\brace`, `\brack` and their `withdelims` forms build fractions from the current row, with the bar only for the `\over` forms; `\middle` delimiters are sized with their enclosing `\left`/`\right` group and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size | -| M5 | NFSS/TFM metrics, CM/Latin Modern | **partial**: paragraph-level NFSS declarations and inline run composition over the built-in Roman/Bold/Italic/BoldItalic/Mono/Sans faces, per-face Computer Modern TFM metrics, and Type1 (PFB) outline embedding for every built-in face plus `cmmi10` math italics, `cmsy10` math symbols and `cmex10` big operators, with Liberation subsets used only as a fallback for characters outside the Type1 encodings; full NFSS family/shape state and Type1 coverage for arbitrary Unicode remain open | +| M5 | NFSS/TFM metrics, CM/Latin Modern | **partial**: paragraph-level NFSS declarations and inline run composition over the built-in Roman/Bold/Italic/BoldItalic/Mono/Sans/SansBold/SansItalic faces (CM has no sans bold-italic, so `cmss/bx/it` substitutes `cmss/bx/n`), per-face Computer Modern TFM metrics, and Type1 (PFB) outline embedding for every built-in face plus `cmmi10` math italics, `cmsy10` math symbols and `cmex10` big operators, with Liberation subsets used only as a fallback for characters outside the Type1 encodings; full NFSS family/shape state and Type1 coverage for arbitrary Unicode remain open | | M6 | class/package execution (`article`, `sn-jnl`) | Overleaf page-count parity | | M7 | `\special`, PDF XObjects, hyperref annotations | PDF structure parity | @@ -331,7 +331,7 @@ for a later overlaid slash. | M2 vertical/page builder | partial | vsize, topskip, insertions, marks, Rust output hook, top/bottom floats, float-page/text fractions, rules, vskip, penalties; `page::PageBuilder` scores breakpoints with page badness and penalties and models `\topskip`/`\maxdepth`; `Engine::layout_paged` builds pages through it for documents made of box/glue/penalty/mark vertical material (a unit may span pages), while in-text floats flow inline through the page builder; paged layouts replay edits from the edited page (insertions, bottom floats and interpreted `\output` force a full rebuild), and insertions are placed through the builder too; `\output` interpreted for a `\shipout`/`\ifdim`/`\ifnum` register subset over page globals and `\outputpenalty`/`\pageno`/`\deadcycles` | | M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter | | M4 math | partial | atoms, scripts, fractions (including infix `\over`/`\atop`/`\choose`), roots, delimiters, accents, operators, classes, braces, boxed, negated, math alphabets (incl. `\mathcal`, `\mathbb` and `\mathfrak`), `align`/`gather` rows with per-row tags; no math painter/shrink wrapping | -| M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per face to Liberation when the program does not encode every character | +| M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10/cmssbx10/cmssi10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per face to Liberation when the program does not encode every character | | M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent | | M7 incremental integration | partial | route-D preview/PDF/edit endpoints plus opt-in `?engine=route-d` project preview, content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center/flushright mapping; editor toggle in `texrra-web`; inline math pending | @@ -353,7 +353,7 @@ M3 painter: `Page::display_list()` and `Halign::display_list()` produce absolute PDF writer: `crates/texrra-tex-core/src/pdf.rs` writes multi-page PDF 1.4 with five embedded Liberation Type0/CID faces (Identity-H + ToUnicode + `/W` arrays), filled rectangles, diagonal rules, raw-RGB `/XObject` images, `/Annots` URI links and arbitrary `/special` operators. Ligature substitution and line-end italic correction are implemented; full NFSS family switching remains open. -M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono}`. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end and math-script italic corrections and monospace/sans paragraph faces are applied; paragraph-level NFSS declarations (`\rmfamily`, `\sffamily`, `\ttfamily`, `\bfseries`, `\itshape`, `\texttt`, `\textsf`) select those faces and the `\fontfamily`/`\fontseries`/`\fontshape`/`\fontencoding`/`\selectfont` command forms plus legacy `\rm`/`\sf`/`\tt`/`\bf`/`\it`/`\sl`/`\up`/`\normalfont` declarations are parsed; inline `\textbf`/`\emph`/`\textit`/`\texttt`/`\textsf` groups and `{\bfseries ...}` declaration groups (including nesting) split a paragraph into styled runs, each shaped by its own TFM and painted with its own face; nested faces compose relatively (`\emph` inside bold yields bold italic via cmbxti10, `\emph` inside italic returns upright); styled runs are stored on the paragraph unit, so incremental edits rebuild them through `Engine::edit_runs` instead of flattening the paragraph back to one face; true family/series/shape switching remains open; route-D PDFs now embed all six Knuth Computer Modern Type1 programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10) as simple fonts (PFB `Length1/2/3`, `/Encoding /Differences` from each program's built-in encoding, `/Widths` in 1000-unit text space from that face's TFM advances) whenever the program covers every character of that face on the page, and fall back per face to the Liberation Type0 subset otherwise; `pdffonts` reports `Type 1` faces (CMR10, CMBX10, ...) and `pdftotext` still extracts the text. `Unit::paragraph` now builds its item stream with `layout_paragraph_with_font`, so CMR10 advances, kerns and ligatures drive paragraph widths; each glyph box also carries the TFM height/depth, and the painter emits 10pt glyphs and the Type0 `/W` array reports CMR10 advances, and ligature boxes paint their component letters, so `pdftotext` keeps word boundaries instead of inserting spaces between letters. +M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono}`. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end and math-script italic corrections and monospace/sans paragraph faces are applied; paragraph-level NFSS declarations (`\rmfamily`, `\sffamily`, `\ttfamily`, `\bfseries`, `\itshape`, `\texttt`, `\textsf`) select those faces and the `\fontfamily`/`\fontseries`/`\fontshape`/`\fontencoding`/`\selectfont` command forms plus legacy `\rm`/`\sf`/`\tt`/`\bf`/`\it`/`\sl`/`\up`/`\normalfont` declarations are parsed; inline `\textbf`/`\emph`/`\textit`/`\texttt`/`\textsf` groups and `{\bfseries ...}` declaration groups (including nesting) split a paragraph into styled runs, each shaped by its own TFM and painted with its own face; nested faces compose relatively (`\emph` inside bold yields bold italic via cmbxti10, `\emph` inside italic returns upright, `\sffamily\bfseries` yields cmssbx10 and `\sffamily\itshape` cmssi10, while bold-italic sans falls back to cmssbx10 as TeX's OT1 substitution does); styled runs are stored on the paragraph unit, so incremental edits rebuild them through `Engine::edit_runs` instead of flattening the paragraph back to one face; true family/series/shape switching remains open; route-D PDFs now embed all six Knuth Computer Modern Type1 programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10) as simple fonts (PFB `Length1/2/3`, `/Encoding /Differences` from each program's built-in encoding, `/Widths` in 1000-unit text space from that face's TFM advances) whenever the program covers every character of that face on the page, and fall back per face to the Liberation Type0 subset otherwise; `pdffonts` reports `Type 1` faces (CMR10, CMBX10, ...) and `pdftotext` still extracts the text. `Unit::paragraph` now builds its item stream with `layout_paragraph_with_font`, so CMR10 advances, kerns and ligatures drive paragraph widths; each glyph box also carries the TFM height/depth, and the painter emits 10pt glyphs and the Type0 `/W` array reports CMR10 advances, and ligature boxes paint their component letters, so `pdftotext` keeps word boundaries instead of inserting spaces between letters. M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments. @@ -365,9 +365,9 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits. -Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address. `Engine::edit` preserves the face when reflowing an edited paragraph. +Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`, `cmssbx10`, `cmssi10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address. `Engine::edit` preserves the face when reflowing an edited paragraph. -The crate currently has 388 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 571 tests (388 route-D unit, 37 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 27 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path. +The crate currently has 393 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 577 tests (393 route-D unit, 38 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 27 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path. ### M0 incremental demo diff --git a/src/route_d.rs b/src/route_d.rs index 37d6a81..9192472 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -1038,6 +1038,8 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)> ParagraphFont::BoldItalic => (Family::Roman, true, true), ParagraphFont::Mono => (Family::Mono, false, false), ParagraphFont::Sans => (Family::Sans, false, false), + ParagraphFont::SansBold => (Family::Sans, true, false), + ParagraphFont::SansItalic => (Family::Sans, false, true), }; let mut text = raw.trim_start(); let mut consumed = false; @@ -1125,7 +1127,11 @@ fn nfss_font(raw: &str, base: ParagraphFont) -> Option<(ParagraphFont, String)> } let font = match family { Family::Mono => ParagraphFont::Mono, - Family::Sans => ParagraphFont::Sans, + Family::Sans => match (bold, italic) { + (true, _) => ParagraphFont::SansBold, + (false, true) => ParagraphFont::SansItalic, + (false, false) => ParagraphFont::Sans, + }, Family::Roman => match (bold, italic) { (true, true) => ParagraphFont::BoldItalic, (true, false) => ParagraphFont::Bold, @@ -1212,7 +1218,7 @@ fn inline_wrapper(rest: &str, base: ParagraphFont) -> Option<(ParagraphFont, &st "\\emph" => base.emphasized(), "\\textit" | "\\textsl" => base.italicized(), "\\texttt" => ParagraphFont::Mono, - "\\textsf" => ParagraphFont::Sans, + "\\textsf" => base.sans_family(), "\\textmd" => base.medium(), "\\textup" => base.upright(), "\\textrm" => base.roman_family(), @@ -2167,6 +2173,14 @@ mod nfss_tests { #[test] fn declarations_select_built_in_faces() { assert_eq!(paragraph_font("\\sffamily Sans text"), ParagraphFont::Sans); + assert_eq!( + paragraph_font("\\sffamily\\bfseries Sans text"), + ParagraphFont::SansBold + ); + assert_eq!( + paragraph_font("\\sffamily\\itshape Sans text"), + ParagraphFont::SansItalic + ); assert_eq!(paragraph_font("\\ttfamily Mono text"), ParagraphFont::Mono); assert_eq!(paragraph_font("\\bfseries Bold text"), ParagraphFont::Bold); assert_eq!( @@ -2175,7 +2189,7 @@ mod nfss_tests { ); assert_eq!( paragraph_font("\\sffamily\\bfseries Bold sans"), - ParagraphFont::Sans + ParagraphFont::SansBold ); assert_eq!( paragraph_font("\\rmfamily\\mdseries\\upshape Roman"), @@ -2243,6 +2257,12 @@ mod inline_tests { ); } + #[test] + fn textsf_inside_bold_stays_bold() { + let runs = inline_runs("\\textbf{a \\textsf{b}}", ParagraphFont::Roman).expect("runs"); + assert_eq!(runs[1], (ParagraphFont::SansBold, "b".to_string())); + } + #[test] fn plain_paragraphs_have_no_runs() { assert!(inline_runs("no commands here", ParagraphFont::Sans).is_none());