diff --git a/README.md b/README.md index db33a0f..7941a1f 100644 --- a/README.md +++ b/README.md @@ -473,7 +473,7 @@ the assignable TeX parameters `\\delimiterfactor` (default 901) and 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. `\scshape`/`\textsc` select the real cmcsc10 small-caps face, `\slshape`/`\textsl` use cmsl10 (or cmbxsl10 when bold) rather than the italic cmti10, and `\ttfamily\itshape` reaches cmitt10. All twelve text programs (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10, cmssbx10, cmssi10, cmcsc10, cmsl10, cmbxsl10, cmitt10) are embedded as Type1 outlines. Characters outside a program's encoding fall back per glyph to a Liberation subset, so the ASCII letters of an accented word still use Computer Modern and Greek text keeps its Unicode text under PDF extraction, including capital Omega, because the embedded Type1 faces carry a ToUnicode CMap built from the requested characters rather than relying on glyph names. Accent commands such as `\'`, `` \` ``, `\"`, `\^`, `\~`, `\c`, `\v` and `\=` compose precomposed Unicode letters and fall back to the base letter plus a combining mark. `\textsuperscript` and `\textsubscript` set a 70% run raised or lowered by 0.4em. `\MakeUppercase` and `\MakeLowercase` (also `\uppercase`/`\lowercase`) transform their braced text while keeping the surrounding face. Because Computer Modern has no bold small caps, a bold small-caps request falls back to cmbx10. A `\textcolor{name}{...}` run paints in one of the standard named colours in both the SVG preview and the PDF, and a leading `\\color{name}` switch colours the rest of its paragraph (`\definecolor` supports rgb, RGB, gray, HTML and cmyk models, `\pagecolor{name}` fills the page background, a `name!percent!other` spec mixes two named colours linearly, the second defaulting to white, and `\hypersetup{urlcolor=...}` colours `\href` labels, and `\colorbox{name}{...}` paints a filled rectangle behind its text, and `\fcolorbox{frame}{background}{...}` draws a 0.4pt frame around that rectangle).. Section-wide declarations such as `\bfseries` apply from where they appear to the end of their group, and `\em` toggles emphasis relative to the surrounding face. Paragraph base sizes come from `\fontsize{}{}` and the article size commands (`\tiny` through `\Huge`), scaling glyph metrics and the default interline glue while the measure, indentation and authored skips stay absolute. The class options `10pt`/`11pt`/`12pt` on `\documentclass[...]` set the default base size (and article `\baselineskip` of 12pt/13.6pt/14.5pt), and `\linespread{factor}` (or `\renewcommand{\baselinestretch}{factor}`) scales that baseline; a size command inside a paragraph overrides the class default and keeps its own glyph size in that run. Inline math inside a styled run keeps its math face while the surrounding text retains its style. The paragraph measure follows `\textwidth`/`\hsize` (or `\setlength{\textwidth}{...}`), and `\setlength` accepts the other supported layout lengths, including a `\parskip` with plus/minus glue; a counter declared with `\newcounter{name}` starts at zero and can be changed by `\setcounter`/`\addtocounter`, and a length declared with `\newlength{\name}` can be set by `\setlength{\name}{...}` and then used as the value of a later `\setlength{\parindent}{\name}`, and `\addtolength{\name}{...}` adds to such a length, so class code that stores its dimensions in named lengths takes effect. The `geometry` package's `margin`/`hmargin`/`vmargin`/`left`/`right`/`top`/`bottom`/`textwidth`/`textheight` options (or `\geometry{...}`) are applied to the page measure and height; other package code is not executed. Block environments `center`, `flushleft` and `flushright` set the paragraph alignment, and aligned short lines are centring/flushing within the full measure rather than at the natural line width. A leading `\noindent` starts its paragraph flush with the measure. Page numbers print centred below the text block, `\setcounter{page}` offsets the printed number, `\addtocounter{page}` shifts it (`\pagenumbering` resets it to 1), and `\pagenumbering{roman|Roman|alph|Alph|arabic}` changes their format and `\pagestyle{empty}` suppresses them on every page and `\thispagestyle{empty}` on the first page. `\hypersetup{pdftitle=...}` writes the PDF Info dictionary (title, author, subject and keywords, UTF-16BE for non-ASCII text), each numbered heading becomes a PDF bookmark nested by heading level, `\title`, `\author` and `\date` are captured from the preamble, `\today` expands to the current date, and `\maketitle` expands into a centered title block at the article class sizes (using today's date when `\date` is absent and none for `\date{}`). `\section`, `\subsection`, `\subsubsection`, `\paragraph` and `\subparagraph` advance five-level article counters, prefix their titles with the number, and paint bold at `\Large`/`\large`/`\normalsize` (the two deepest levels stay at the base size); starred headings stay unnumbered, and an optional `[short]` title replaces the long title in the table of contents. The `abstract` environment expands into a centered bold heading and a 9pt body, and `\maketitle` joins multiple `\and` authors and turns `\thanks` notes into title footnotes. Section labels resolve `\ref`/`\eqref` to the heading number (standalone `\label` lines attach to the previous heading, unknown references print `??`), and `\pageref{label}` reports that heading's formatted page number after a probe layout, `\appendix` restarts sectioning with letter numbers, `\tableofcontents` lists the numbered headings through `\subsubsection` with their page numbers right-aligned after dot leaders (the default article `tocdepth` of 3, changed by `\setcounter{tocdepth}`), `\setcounter{secnumdepth}` limits which levels are numbered, `\setcounter{section}`/`{figure}`/`{table}`/`{equation}`/`{theorem}` offsets the next counter value, `\listoffigures`/`\listoftables` reproduce the numbered captions with each float's page number right-aligned after dot leaders, `verbatim` keeps monospaced source lines, `\verb|...|` renders inline literal text monospaced, and text commands such as `\LaTeX`, `\TeX`, `\ldots`, `\S`, `\ss`, `\ae`, `\oe`, `\o`, `\l`, `\dh`, `\th`, `\textdegree`, `\textmu`, `\textonehalf` and `\texteuro` expand to their characters (a control word swallows the spaces that follow it), `\href` keeps its link text and paints a PDF `/Link` URI annotation over the label, and `\url` becomes typewriter text, and the `abstract` environment expands to its heading and body. 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`), and `\genfrac` takes explicit delimiters and rule thickness; only `\over`-style fractions draw a bar and fractions never draw parentheses. `displaymath` and `math` environments are accepted alongside `$$`, `\[` and `\(...\)`, and `cases`, `matrix`/`pmatrix`/`bmatrix`/`Bmatrix`/`vmatrix`/`Vmatrix` and `array` environments build a grid with the matching delimiters (an `array` column spec chooses left, centred or right alignment). `\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, `alignat` numbers rows the same way while ignoring its column-count argument, a `split` body inside `equation` is numbered once, and `multline` sets its first row flush left, its last row flush right and the rest centred around a single number. Inter-atom spacing uses TeX's 3/4/5mu classes (`1mu` is `1/18em`), `\mid` is a relation and `\colon` punctuation, `\limits` stacks an operator's scripts above and below using TeX's script size and clearance rules while `\nolimits` keeps them beside it, `\substack{...}` stacks its rows with TeX's inter-row gaps, and an integral stays sideways unless `\limits` is given, and `\mskip`/`\mkern`/`\mspace`/`\hskip`/`\kern`/`\hspace` scan TeX dimensions, taking the natural width of any `plus`/`minus` parts; `\operatorname{...}` sets an upright operator name, its starred form stacks following limits and `\DeclareMathOperator{\name}{text}` defines new ones. `\footnote{...}` leaves a numbered marker in the paragraph and sets the note as a 9pt page insertion at the bottom of the page that mentions it. A `thebibliography` environment turns its `\bibitem` entries into numbered `[n]` paragraphs, and `\cite{...}` resolves to `[n]`/`[n, m]` (unknown keys print `[?]`; optional citation notes are dropped, `\citep`/`\citet` behave like `\cite`, `\nocite` is ignored, and `\bibliography`/`\bibliographystyle` are consumed without BibTeX). A `figure` environment becomes a float at its `[t]`/`[b]`/`[h]` placement, its `\caption` numbers as `Figure n:` and feeds `\ref`, and `\includegraphics` embeds the referenced project image when it decodes (PNG/JPEG/BMP become a PDF XObject; missing or undecodable files keep the rule placeholder), a standalone `\includegraphics` paragraph becomes an in-text graphic float, and a standalone `\rule{width}{height}` becomes an in-text rule box; `width=`/`height=` take dimensions or fractions of `\textwidth`/`\textheight`, `scale=` a percentage, `keepaspectratio` fits both dimensions, and `\graphicspath` directories are searched (with `.png`/`.jpg`/`.bmp` fallbacks) when a path has no suffix. `table` environments likewise become floats carrying their captured `tabular` body, with `Table n:` captions that resolve from `\ref`. Table captions sit above the tabular as in LaTeX, figure captions below the graphic, and `\caption*` leaves either unnumbered; an optional `[short]` caption is used by `\listoffigures`/`\listoftables` while the long caption stays on the float; the glue on each side of a tabular column follows `\tabcolsep` (6pt by default), `\arraystretch` scales the tabular row heights, a begin-position option is accepted and ignored, and `\\[dim]` adds an extra gap after that row, and `|` rules in the column template paint vertical rules, and `*{n}{cols}` repeats a column group (a `tabularx` target width expands its `X` columns to share the leftover measure, and a `\multirow{n}{width}{text}` cell keeps its text on the first row of its span), and `\renewcommand` can rename the `Figure`/`Table` caption prefixes, the `Abstract` heading, and the `References`/`Contents`/`List of Figures`/`List of Tables` headings that open the bibliography, table of contents and float lists. Theorem-like environments (`theorem`, `lemma`, `corollary`, `proposition`, `definition`, `example`, `remark`, `proof`) produce a bold numbered heading with an optional `[title]`, italic statements for the theorem group, and unnumbered proofs whose optional argument replaces the heading, with `\label`/`\ref` resolving to the theorem number. `\newtheorem{env}[shared]{Display}`, `\newtheorem{env}{Display}[section]` and `\newtheorem*{env}{Display}` add custom theorem environments: a shared counter numbers the env with its parent, `[section]` scopes numbers to the enclosing section, and the starred form stays unnumbered. In project previews and PDF exports, `\input{...}` and `\include{...}` expand from files in the same project (a missing `.tex` suffix is added), so chapter files render in place; a project's own `.sty`/`.cls` files are inlined for `\usepackage{name}`/`\documentclass{name}` with local `\RequirePackage` dependencies inlined recursively, local base classes named by `\LoadClass`/`\LoadClassWithOptions` inlined the same way, class and package bodies inlining their local `\input{...}` files (missing files are dropped), and package/class boilerplate dropped, `\AtBeginDocument`/`\AtEndDocument` bodies executed, and `\makeatletter`/`\makeatother` stripped; local class and package files run their `\DeclareOption` code for the options named on `\documentclass[...]` / `\usepackage[...]` (with `\ExecuteOptions` defaults), and preamble `\PassOptionsToPackage`/`\PassOptionsToClass` lines are merged into the next request, and unknown paths stay as literal text. Preview JSON also reports a `warnings` array naming environments route-D cannot lay out and control words that survived layout, so unsupported source is reported rather than silently typeset. Route-D project previews are memoised by a hash of the expanded source (32 entries) and invalidated on edit; PDF exports cache the last eight results and the cache key also covers decoded image bytes, so replacing an image re-renders both. A malformed source answers 422 with a JSON error body and never populates either cache. `itemize`/`enumerate`/`description` environments nest arbitrarily: bullet labels cycle `•`/`–`/`*`, sub-enumerations use `(a)`, roman and upper-letter labels, description items print their `[term]` in bold before the definition, an optional `\item[label]` replaces the generated marker, each depth adds 12pt of indentation, and list items take article's per-level `\topsep`, `\itemsep` and `\partopsep` (top level 8+2/4pt at 10pt, 9+3/4.5pt at 11pt and 10+3/5pt at 12pt; second level 4+2/2pt, 4.5+3/2pt and 5+3/2pt) unless `\setlength{\topsep}`, `\setlength{\itemsep}` or `\setlength{\partopsep}` override them, a wrapped item hangs its continuation lines at the text indent while its first line stays at the bullet indent, and an `\setcounter{enumi}` (or `enumii`/`enumiii`/`enumiv`) line before the first `\item` resumes enumerate numbering. A `quotation` environment splits its blank-line-separated paragraphs into blocks indented 20pt on both sides, and `quote` uses the same 20pt margins, and `verse` keeps its explicit line breaks as separate 20pt-indented lines, and a `minipage{w}` environment lays its body out at width `w` (its optional position argument is ignored). -Inline `$...$` and `\(...\)` math is laid out inside 10pt paragraphs (larger sizes keep the delimiters literal). `\newcommand`/`\renewcommand` definitions are captured from the preamble and expanded textually, including numbered arguments and one `[default]` optional first argument; TeX's `\def` parameter texts and `\let` aliases are executed the same way, `\edef`/`\xdef` expand their bodies once at definition time and `\csname...\endcsname` builds the named control sequence, `\expandafter` runs the macro after its prefix once, and `\newenvironment` definitions wrap their bodies with the declared begin/end material. `\newif` flags select between `\if...\else...\fi` branches, with assignments honoured in the preamble or the body, so class conditionals like `\ifdraft` work, and `\ifdefined\name` tests whether a macro is declared. `\ifnum` compares integers from literals, `\newcount` registers or `\value{counter}`, and `\ifx` compares token meanings (two macros are equal when their parameter text and body match) `\ifcase ` chooses the n-th `\or` branch and falls back to `\else` when the value is out of range.. the scratch registers `\dimen0`-`\dimen255` and `\skip0`-`\skip9` hold dimensions and glue with the same assignment and `\advance` forms, and `\count0`-`\count9` take assignments, `\advance`, `\multiply` and `\divide` and print through `\the`/`\number`, while `\newcount\name` declares an integer register whose value `\name= `\dimexpr ... \relax` evaluates `+`, `-`, `*` (by an integer) and `/` over dimensions and `\newdimen` registers and prints through `\the`, while `\glueexpr ... \relax` evaluates glue with `plus`/`minus` components over dimensions and `\newskip` registers, with parenthesised sub-expressions allowed and register operands keeping all three components; `\noexpand\token` keeps the token unexpanded for the current pass (a later pass still expands it), and a later `\def` with the same name replaces the earlier definition The LaTeX internals `\@namedef`, `\@nameuse`, `\@ifundefined`, `\@firstofone`, `\@firstoftwo`, `\@secondoftwo` and `\@empty` expand, and `\@ifstar{yes}{no}` / `\@ifnextchar{yes}{no}` choose from the following token, and `@` counts as a letter in control words so `\makeatletter`-guarded names parse `\numexpr` evaluates `+`, `-`, `*`, `/` and parentheses over integers and integer registers, either standalone or after `\the` `\newskip\name` declares a glue register that `\the\name` prints as `wpt plus spt minus hpt`. `\newdimen\name` declares a dimension register whose value `\name=`, `\advance\name by `, `\multiply\name by ` and `\divide\name by ` update and which `\the\name` prints in TeX's `pt` form.......`, `\advance\name by ...`, `\multiply\name by ...` and `\divide\name by ...` update and which `\the\name`/`\number\name` print. +Inline `$...$` and `\(...\)` math is laid out inside 10pt paragraphs (larger sizes keep the delimiters literal). `\newcommand`/`\renewcommand`/`\DeclareRobustCommand` definitions are captured from the preamble (and `\providecommand` only fills a name that is still undefined) and expanded textually, including numbered arguments and one `[default]` optional first argument; TeX's `\def` parameter texts and `\let` aliases are executed the same way, `\edef`/`\xdef` expand their bodies once at definition time and `\csname...\endcsname` builds the named control sequence, `\expandafter` runs the macro after its prefix once, and `\newenvironment` definitions wrap their bodies with the declared begin/end material. `\newif` flags select between `\if...\else...\fi` branches, with assignments honoured in the preamble or the body, so class conditionals like `\ifdraft` work, and `\ifdefined\name` tests whether a macro is declared. `\ifnum` compares integers from literals, `\newcount` registers or `\value{counter}`, and `\ifx` compares token meanings (two macros are equal when their parameter text and body match) `\ifcase ` chooses the n-th `\or` branch and falls back to `\else` when the value is out of range.. the scratch registers `\dimen0`-`\dimen255` and `\skip0`-`\skip9` hold dimensions and glue with the same assignment and `\advance` forms, and `\count0`-`\count9` take assignments, `\advance`, `\multiply` and `\divide` and print through `\the`/`\number`, while `\newcount\name` declares an integer register whose value `\name= `\dimexpr ... \relax` evaluates `+`, `-`, `*` (by an integer) and `/` over dimensions and `\newdimen` registers and prints through `\the`, while `\glueexpr ... \relax` evaluates glue with `plus`/`minus` components over dimensions and `\newskip` registers, with parenthesised sub-expressions allowed and register operands keeping all three components; `\noexpand\token` keeps the token unexpanded for the current pass (a later pass still expands it), and a later `\def` with the same name replaces the earlier definition The LaTeX internals `\@namedef`, `\@nameuse`, `\@ifundefined`, `\@firstofone`, `\@firstoftwo`, `\@secondoftwo` and `\@empty` expand, and `\@ifstar{yes}{no}` / `\@ifnextchar{yes}{no}` choose from the following token, and `@` counts as a letter in control words so `\makeatletter`-guarded names parse `\numexpr` evaluates `+`, `-`, `*`, `/` and parentheses over integers and integer registers, either standalone or after `\the` `\newskip\name` declares a glue register that `\the\name` prints as `wpt plus spt minus hpt`. `\newdimen\name` declares a dimension register whose value `\name=`, `\advance\name by `, `\multiply\name by ` and `\divide\name by ` update and which `\the\name` prints in TeX's `pt` form.......`, `\advance\name by ...`, `\multiply\name by ...` and `\divide\name by ...` update and which `\the\name`/`\number\name` print. 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/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index f3556de..f9ff714 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`). 886 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 888 workspace tests are green and no oracle fixture is ignored. Preview JSON also carries a `warnings` array naming environments route-D cannot lay out and control words that survived layout, so unsupported source is reported instead of being silently typeset. diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 452af0f..f63e3a1 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -332,7 +332,7 @@ for a later overlaid slash. | 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/cmssbx10/cmssi10/cmcsc10/cmsl10/cmbxsl10/cmitt10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per glyph to a Liberation subset when a character is outside the encoding while the rest of the face stays in Computer Modern | -| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; route-D reads `\documentclass` size options (10/11/12pt) into the paragraph base size and `\baselineskip`, executes `\newcommand`/`\renewcommand` macros textually (with numbered arguments, one `[default]` optional first argument and an eight-pass recursion guard; `\edef`/`\xdef` expand their bodies at definition time and `\csname...\endcsname` resolves to the named control sequence; `\expandafter` expands the zero-argument macro after its prefix once, `\@gobble`/`\@gobbletwo` discard arguments and `\@ifmtarg{arg}{yes}{no}` chooses a branch by emptiness, and definition prefixes (`\long`, `\global`, `\outer`, `\protected`, plus `\gdef` and `\protected@edef`/`\protected@xdef`) are accepted), and expands `geometry`, `\setlength`, title/author/date, `\maketitle`, sectioning, theorem, float and bibliography markup; local `.cls`/`.sty` files are inlined, execute their `\DeclareOption` subset for the options given on `\documentclass`/`\usepackage`, and recurse through local `\LoadClass` bases, while full class layout execution remains absent | +| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; route-D reads `\documentclass` size options (10/11/12pt) into the paragraph base size and `\baselineskip`, executes `\newcommand`/`\renewcommand`/`\DeclareRobustCommand` macros textually (with numbered arguments, one `[default]` optional first argument and an eight-pass recursion guard; `\edef`/`\xdef` expand their bodies at definition time and `\csname...\endcsname` resolves to the named control sequence; `\expandafter` expands the zero-argument macro after its prefix once, `\@gobble`/`\@gobbletwo` discard arguments and `\@ifmtarg{arg}{yes}{no}` chooses a branch by emptiness, and definition prefixes (`\long`, `\global`, `\outer`, `\protected`, plus `\gdef` and `\protected@edef`/`\protected@xdef`) are accepted), and expands `geometry`, `\setlength`, title/author/date, `\maketitle`, sectioning, theorem, float and bibliography markup; local `.cls`/`.sty` files are inlined, execute their `\DeclareOption` subset for the options given on `\documentclass`/`\usepackage`, and recurse through local `\LoadClass` bases, while full class layout execution remains 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/inline-math/itemize/enumerate/description/quote/center/flushleft/flushright mapping; editor toggle in `texrra-web`; project route-D previews are memoised by a hash of the expanded source (32 entries) and invalidated automatically when the source changes; project route-D PDF exports are cached by the same expanded-source hash (eight entries) and report `X-Texrra-Cache: hit`/`miss`; the flat `POST /api/route-d/preview` and `/api/route-d/pdf` endpoints likewise memoise the last 32 previews and eight PDFs by source hash and report the same header; malformed sources answer 422 with a JSON `{"error": "..."}` body and never populate either cache, the flat caches keep the newest 32 previews and eight PDFs in FIFO order (eviction is covered by tests), and four concurrent identical flat previews (or three flat PDFs) share a single mutex-protected cache entry and return identical bodies; a deployment can default to route-D with `TEXRRA_ENGINE=route-d`, and an explicit `?engine=` overrides that default for both project previews and PDFs (v1 and route-d alike; covered by an engine-parameter matrix test); inline `$...$`/`\(...\)` math is laid out inside 10pt paragraphs, while larger paragraphs keep delimiters literal; `\href` labels paint PDF `/Link` URI annotations over their runs | v1 remains the production renderer; the route-D core is additive and tested independently. @@ -367,7 +367,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal 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`, `cmcsc10`) 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`/`cmcsc10`, 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; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph. -The crate currently has 427 unit tests plus ten route-D integration tests and thirty-eight oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 886 tests (427 route-D unit, 275 engine binary unit, 10 route-D integration, 38 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path. +The crate currently has 427 unit tests plus ten route-D integration tests and thirty-eight oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 888 tests (427 route-D unit, 277 engine binary unit, 10 route-D integration, 38 oracle, 71 v1 integration, 60 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 be37add..b94d09c 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -494,6 +494,7 @@ fn macro_definition(line: &str) -> Option { let rest = line .strip_prefix("\\newcommand") .or_else(|| line.strip_prefix("\\renewcommand")) + .or_else(|| line.strip_prefix("\\DeclareRobustCommand")) .or_else(|| line.strip_prefix("\\providecommand"))?; let rest = rest.trim_start(); let rest = rest.strip_prefix('*').unwrap_or(rest).trim_start(); @@ -1959,12 +1960,21 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) { }; if is_macro_command("\\newcommand") || is_macro_command("\\renewcommand") + || is_macro_command("\\DeclareRobustCommand") || is_macro_command("\\providecommand") || is_macro_command("\\def") || is_macro_command("\\gdef") { if let Some(definition) = macro_definition(definition_line) { - geometry.macros.push(definition); + let provided = definition_line.trim_start().starts_with("\\providecommand"); + if !provided + || !geometry + .macros + .iter() + .any(|known| known.name == definition.name) + { + geometry.macros.push(definition); + } } continue; } @@ -10201,6 +10211,22 @@ a & b ); } + #[test] + fn declare_robust_command_defines_a_macro() { + let (body, geometry) = + geometry_and_body("\\DeclareRobustCommand{\\hello}{Hi}\n\n\\hello there."); + assert!(body.contains("Hi there."), "{body:?}"); + assert!(geometry.macros.iter().any(|m| m.name == "\\hello")); + } + + #[test] + fn providecommand_keeps_an_existing_definition() { + let (body, _) = geometry_and_body("\\newcommand{\\a}{A}\n\\providecommand{\\a}{B}\n\n\\a."); + assert!(body.contains("A."), "{body:?}"); + let (body, _) = geometry_and_body("\\providecommand{\\b}{B}\n\n\\b."); + assert!(body.contains("B."), "{body:?}"); + } + #[test] fn setlength_assigns_skip_registers() { let (body, geometry) = geometry_and_body(