Fix the arXiv-template PDF output
The user-supplied template PDF exposed four concrete problems:
- title/headings were letter-spaced: plain text in a large paragraph took the
SizedText segment path and was scaled twice; the fallback run now stays at
the base size and is scaled once by the paragraph;
- the table lost its third column because unsupported math glyphs were sent
through the PDF fallback font; table-cell math now has a readable ASCII
fallback (Size (um), approx. 100, 10**6);
- fancyhdr's \cfoot{\thepage} was painted together with route-D's default page
number; default numbering is skipped for a fancy pagestyle;
- .bib data was ignored; simple @article/@inproceedings entries are now parsed
from project .bib files, inlined as thebibliography entries, and resolved by
the existing citation pass, producing References and [1]-[3].
The regenerated 3-page PDF was checked for title/heading spacing, table text,
references and a single page number per page. A project regression test covers
the .bib path, and the table/heading fixes have unit tests.
Remaining visible limits in this template: the complex display equation, the
\fbox/rule figure body, vector/PDF images and the author block layout.
Test count moves to 1069 (444 core, 432 engine, 65 server).
This commit is contained in:
1 parent
fab26234fc
commit
b1e3e03f00
9 files changed
+457
-26
No files matched your search
@@ -4557,6 +4557,81 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
|
||||
/// Table cells currently paint plain text, not inline math. Convert common
|
||||
/// math commands to readable ASCII so a cell such as `Size ($\mu$m)` is not
|
||||
/// reduced to a single unsupported backslash glyph by the PDF font fallback.
|
||||
fn table_cell_plain_text(text: &str) -> String {
|
||||
let mut out = String::new();
|
||||
let mut math = false;
|
||||
let mut chars = text.chars().peekable();
|
||||
while let Some(character) = chars.next() {
|
||||
if character == '$' {
|
||||
math = !math;
|
||||
continue;
|
||||
}
|
||||
if !math {
|
||||
out.push(character);
|
||||
continue;
|
||||
}
|
||||
if character == '\\' {
|
||||
let mut name = String::new();
|
||||
while let Some(&next) = chars.peek() {
|
||||
if next.is_ascii_alphabetic() {
|
||||
name.push(next);
|
||||
chars.next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
match name.as_str() {
|
||||
"mu" => out.push_str("u"),
|
||||
"sim" => out.push_str("approx. "),
|
||||
"times" => out.push('x'),
|
||||
"pm" => out.push_str("+/-"),
|
||||
"le" => out.push_str("<="),
|
||||
"ge" => out.push_str(">="),
|
||||
"approx" => out.push('~'),
|
||||
"cdot" => out.push('*'),
|
||||
"ldots" | "dots" => out.push_str("..."),
|
||||
"alpha" => out.push_str("alpha"),
|
||||
"beta" => out.push_str("beta"),
|
||||
"gamma" => out.push_str("gamma"),
|
||||
"delta" => out.push_str("delta"),
|
||||
"theta" => out.push_str("theta"),
|
||||
"lambda" => out.push_str("lambda"),
|
||||
"pi" => out.push_str("pi"),
|
||||
"sigma" => out.push_str("sigma"),
|
||||
"phi" => out.push_str("phi"),
|
||||
"omega" => out.push_str("omega"),
|
||||
_ => {}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if character == '^' {
|
||||
let mut exponent = String::new();
|
||||
if chars.peek() == Some(&'{') {
|
||||
chars.next();
|
||||
while let Some(next) = chars.next() {
|
||||
if next == '}' {
|
||||
break;
|
||||
}
|
||||
exponent.push(next);
|
||||
}
|
||||
} else if let Some(next) = chars.next() {
|
||||
exponent.push(next);
|
||||
}
|
||||
out.push_str("**");
|
||||
out.push_str(&exponent);
|
||||
continue;
|
||||
}
|
||||
if character == '{' || character == '}' {
|
||||
continue;
|
||||
}
|
||||
out.push(character);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -7972,6 +8047,14 @@ mod tests {
|
||||
assert_eq!(rule.width, 26_214);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_cells_keep_readable_math_fallbacks() {
|
||||
assert_eq!(table_cell_plain_text("Size ($\\mu$m)"), "Size (um)");
|
||||
assert_eq!(table_cell_plain_text("$\\sim$100"), "approx. 100");
|
||||
assert_eq!(table_cell_plain_text("up to $10^6$"), "up to 10**6");
|
||||
assert_eq!(table_cell_plain_text("$\\alpha + \\beta$"), "alpha + beta");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn halign_parses_multicolumn_cells() {
|
||||
let unit =
|
||||
@@ -10081,4 +10164,28 @@ mod runs_edit_tests {
|
||||
);
|
||||
assert!(bold_glyphs(&engine) > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn debug_arxiv_halign_cells() {
|
||||
let source = r"\toprule
|
||||
\multicolumn{2}{c}{Part} \
|
||||
\cmidrule(r){1-2}
|
||||
Name & Description & Size ($\mu) \
|
||||
\midrule
|
||||
Dendrite & Input terminal & $\sim00 \
|
||||
Axon & Output terminal & $\sim0 \
|
||||
Soma & Cell body & up to 0^6$ \
|
||||
\bottomrule";
|
||||
let unit = Unit::halign_from_source_with_template(1, "lll", source, 12);
|
||||
if let VerticalItem::Halign(halign) = &unit.items[0] {
|
||||
for (index, row) in halign.rows.iter().enumerate() {
|
||||
let cells: Vec<_> = row
|
||||
.cells
|
||||
.iter()
|
||||
.map(|cell| (cell.text.clone(), cell.span))
|
||||
.collect();
|
||||
eprintln!("ROW {index} rule={} cells={:?}", row.rule, cells);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user