Alias colours with colorlet
\colorlet{alias}{source} was unsupported, so a colour alias used by
\textcolor or \color leaked. The page-geometry pass now reads both brace groups,
looks the source up in the custom colours and the standard named colours, and
records the alias with the same RGB value.
A preview test defines an HTML colour, aliases it, colours a word with the
alias, and checks the RGB value reaches the SVG with no warnings.
This commit is contained in:
1 parent
7975671882
commit
c89f972a25
4 files changed
+34
-6
No files matched your search
@@ -3445,6 +3445,20 @@ fn strip_page_geometry(
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(rest) = trimmed.strip_prefix("\\colorlet") {
|
||||
let rest = rest.trim_start();
|
||||
if let Some((alias, used)) = braced_group(rest) {
|
||||
let tail = rest[used..].trim_start();
|
||||
if let Some((source, _)) = braced_group(tail)
|
||||
&& let Some(rgb) = named_color(source.trim(), &geometry.colors)
|
||||
{
|
||||
let alias = alias.trim().to_string();
|
||||
geometry.colors.retain(|(known, _)| known != &alias);
|
||||
geometry.colors.push((alias, rgb));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some((name, rgb)) = define_color(trimmed) {
|
||||
geometry.colors.retain(|(known, _)| known != &name);
|
||||
geometry.colors.push((name, rgb));
|
||||
@@ -17496,6 +17510,20 @@ A definition.
|
||||
assert!(text.contains("D"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colorlet_aliases_colors_for_textcolor() {
|
||||
let source = "\\definecolor{accent}{HTML}{336699}\n\\colorlet{link}{accent}\n\n\\textcolor{link}{Deep}";
|
||||
let json = preview_json(source).expect("preview");
|
||||
let value: serde_json::Value = serde_json::from_str(&json).expect("JSON");
|
||||
assert_eq!(
|
||||
value["warnings"].as_array().map(Vec::len),
|
||||
Some(0),
|
||||
"{}",
|
||||
value["warnings"]
|
||||
);
|
||||
assert!(json.contains("336699"), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn titlepage_gets_its_own_page() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\begin{titlepage}\nTitle page.\n\\end{titlepage}\n\nBody.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user