Expand parameterised newcolumntype letters
This commit is contained in:
1 parent
9d57ca604e
commit
8e884e6db1
3 files changed
+68
-27
No files matched your search
@@ -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`). 941 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 942 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.
|
||||
|
||||
+1
-1
@@ -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 941 tests (430 route-D unit, 326 engine binary unit, 10 route-D integration, 39 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 942 tests (430 route-D unit, 327 engine binary unit, 10 route-D integration, 39 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
+66
-25
@@ -160,7 +160,7 @@ struct PageGeometry {
|
||||
/// `\tabcolsep` on each side of a tabular column.
|
||||
tab_col_sep: Option<i64>,
|
||||
/// Custom column letters declared with `\newcolumntype`.
|
||||
column_types: Vec<(char, String)>,
|
||||
column_types: Vec<(char, String, u8)>,
|
||||
/// `\itemsep` between list items, as width/stretch/shrink.
|
||||
item_sep: Option<(i64, i64, i64)>,
|
||||
/// `\topsep` above a list, as width/stretch/shrink.
|
||||
@@ -2098,29 +2098,26 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
}
|
||||
if let Some(rest) = trimmed.strip_prefix("\\newcolumntype") {
|
||||
let rest = rest.trim_start();
|
||||
let rest = if rest.starts_with('[') {
|
||||
rest.find(']')
|
||||
.map(|close| rest[close + 1..].trim_start())
|
||||
.unwrap_or(rest)
|
||||
} else {
|
||||
rest
|
||||
let Some((name, used)) = braced_group(rest) else {
|
||||
continue;
|
||||
};
|
||||
if let Some((name, used)) = braced_group(rest) {
|
||||
let after = rest[used..].trim_start();
|
||||
let after = if after.starts_with('[') {
|
||||
after
|
||||
.find(']')
|
||||
.map(|close| after[close + 1..].trim_start())
|
||||
.unwrap_or(after)
|
||||
let after = rest[used..].trim_start();
|
||||
let mut arg_count = 0_u8;
|
||||
let after = if let Some(inner) = after.strip_prefix('[') {
|
||||
if let Some(bracket) = inner.find(']') {
|
||||
arg_count = inner[..bracket].trim().parse().unwrap_or(0);
|
||||
inner[bracket + 1..].trim_start()
|
||||
} else {
|
||||
after
|
||||
};
|
||||
if let Some((spec, _)) = braced_group(after) {
|
||||
if let Some(letter) = name.trim().chars().next() {
|
||||
geometry
|
||||
.column_types
|
||||
.push((letter, spec.trim().to_string()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
after
|
||||
};
|
||||
if let Some((spec, _)) = braced_group(after) {
|
||||
if let Some(letter) = name.trim().chars().next() {
|
||||
geometry
|
||||
.column_types
|
||||
.push((letter, spec.trim().to_string(), arg_count));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -2791,13 +2788,14 @@ fn expand_tabular_template(template: &str, source: &str, target: Option<i64>) ->
|
||||
}
|
||||
|
||||
/// Substitute `\newcolumntype` letters at the top level of a column spec.
|
||||
fn expand_column_types(template: &str, types: &[(char, String)]) -> String {
|
||||
fn expand_column_types(template: &str, types: &[(char, String, u8)]) -> String {
|
||||
if types.is_empty() {
|
||||
return template.to_string();
|
||||
}
|
||||
let mut characters = template.chars().peekable();
|
||||
let mut out = String::new();
|
||||
let mut depth = 0_usize;
|
||||
for character in template.chars() {
|
||||
while let Some(character) = characters.next() {
|
||||
match character {
|
||||
'{' => {
|
||||
depth += 1;
|
||||
@@ -2808,8 +2806,39 @@ fn expand_column_types(template: &str, types: &[(char, String)]) -> String {
|
||||
out.push(character);
|
||||
}
|
||||
_ if depth == 0 => {
|
||||
if let Some((_, spec)) = types.iter().find(|(letter, _)| *letter == character) {
|
||||
out.push_str(spec);
|
||||
if let Some((_, spec, args)) =
|
||||
types.iter().find(|(letter, _, _)| *letter == character)
|
||||
{
|
||||
let mut spec = spec.clone();
|
||||
for index in 1..=*args {
|
||||
while characters.peek().is_some_and(|next| next.is_whitespace()) {
|
||||
characters.next();
|
||||
}
|
||||
if characters.peek() != Some(&'{') {
|
||||
break;
|
||||
}
|
||||
characters.next();
|
||||
let mut argument = String::new();
|
||||
let mut nested = 1_usize;
|
||||
while let Some(inner) = characters.next() {
|
||||
match inner {
|
||||
'{' => {
|
||||
nested += 1;
|
||||
argument.push(inner);
|
||||
}
|
||||
'}' => {
|
||||
nested -= 1;
|
||||
if nested == 0 {
|
||||
break;
|
||||
}
|
||||
argument.push(inner);
|
||||
}
|
||||
_ => argument.push(inner),
|
||||
}
|
||||
}
|
||||
spec = spec.replace(&format!("#{index}"), &argument);
|
||||
}
|
||||
out.push_str(&spec);
|
||||
} else {
|
||||
out.push(character);
|
||||
}
|
||||
@@ -12152,6 +12181,18 @@ See \ref{fig:a} and \ref{tab:b}.";
|
||||
assert!(json.contains(">S</text>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newcolumntype_accepts_arguments() {
|
||||
let source = "\\newcolumntype{C}[1]{>{\\centering}p{#1}}\n\n\\begin{tabular}{C{20mm}l}\nalpha beta & right \\\\\n\\end{tabular}";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
assert_eq!(geometry.column_types.len(), 1);
|
||||
assert_eq!(geometry.column_types[0].2, 1);
|
||||
assert!(!body.contains("newcolumntype"));
|
||||
let json = preview_json(source).expect("preview");
|
||||
assert!(json.contains("\"warnings\":[]"), "warnings: {json}");
|
||||
assert!(!json.contains("#1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newcolumntype_expands_in_templates() {
|
||||
let source = "\\newcolumntype{L}{>{\\centering}p{20mm}}\n\n\\begin{tabular}{Ll}\nalpha beta & right \\\\\n\\end{tabular}";
|
||||
|
||||
Reference in new issue
Block a user