Split colour, link and sized runs at any base size
inline_math_segments returned None for every paragraph whose base size was not 10pt, so a 12pt or \Large paragraph kept \textcolor/\href/\textsuperscript delimiters as literal text. Only inline math actually depends on the 10pt metric baseline: build the segments at any size and fall back to literal delimiters only when a math segment is present and the size differs. The existing sized-href test moves from "href is stripped but not linked" to "the sized run keeps its link", and a new 12pt test covers a red run, a link and a superscript in one paragraph with no warnings.
This commit is contained in:
1 parent
15b5437987
commit
56faec6046
3 files changed
+39
-10
No files matched your search
+34
-6
@@ -8272,9 +8272,6 @@ fn inline_math_segments(
|
||||
custom: &[(String, [u8; 3])],
|
||||
link_color: Option<[u8; 3]>,
|
||||
) -> Option<Vec<texrra_tex_core::paragraph::InlineSegment>> {
|
||||
if style.font_size != 655_360 {
|
||||
return None;
|
||||
}
|
||||
let mut segments = Vec::new();
|
||||
let mut found_math = false;
|
||||
let mut found_link = false;
|
||||
@@ -8347,6 +8344,13 @@ fn inline_math_segments(
|
||||
}
|
||||
}
|
||||
}
|
||||
// Math metrics are laid out at 10pt, so a paragraph that mixes math with
|
||||
// another base size keeps its literal delimiters instead of painting the
|
||||
// formula at the wrong size. Colour, link and sized runs are safe at any
|
||||
// base size.
|
||||
if found_math && style.font_size != 655_360 {
|
||||
return None;
|
||||
}
|
||||
(found_math || found_link || found_size || found_color).then_some(segments)
|
||||
}
|
||||
|
||||
@@ -14263,6 +14267,30 @@ A definition.
|
||||
assert_eq!(document.widow_penalty, 88);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_colours_and_links_work_at_twelve_point() {
|
||||
let source = "\\documentclass[12pt]{article}\n\\begin{document}\n\nA \\textcolor{red}{red word} and a \\href{https://example.com}{link} and x\\textsuperscript{2}.\n\n\\end{document}\n";
|
||||
let json = preview_json(source).expect("preview");
|
||||
let value: serde_json::Value = serde_json::from_str(&json).expect("JSON");
|
||||
assert_eq!(value["status"], "ok");
|
||||
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
||||
let text: String = svg
|
||||
.split('>')
|
||||
.filter_map(|piece| piece.split('<').next())
|
||||
.collect::<String>()
|
||||
.split_whitespace()
|
||||
.collect();
|
||||
assert!(!text.contains("textcolor"), "colour command leaked: {text}");
|
||||
assert!(!text.contains("href"), "link command leaked: {text}");
|
||||
assert!(text.contains("redword"), "coloured text missing: {text}");
|
||||
assert!(text.contains("link"), "link label missing: {text}");
|
||||
assert!(
|
||||
value["warnings"].as_array().is_some_and(Vec::is_empty),
|
||||
"{}",
|
||||
value["warnings"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_math_uses_article_display_skips() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\nBefore.\n\n\\[ x \\]\n\nAfter.\n\n\\end{document}\n";
|
||||
@@ -15168,7 +15196,7 @@ A definition.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sized_paragraphs_strip_href_commands() {
|
||||
fn sized_paragraphs_link_href_commands() {
|
||||
let source = "\\Large Visit \\href{https://example.com}{the site}.";
|
||||
let blocks = paragraphs(source).expect("paragraphs");
|
||||
let document = build_document(&blocks, &PageGeometry::default());
|
||||
@@ -15194,8 +15222,8 @@ A definition.
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(linked, 0);
|
||||
assert_eq!(backslashes, 0);
|
||||
assert!(linked > 0, "sized runs must keep their link");
|
||||
assert_eq!(backslashes, 0, "href delimiters leaked");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user