Consume caption and numbering declarations
\captionsetup, \numberwithin and \DeclareCaption were unsupported and could leak into the body. The page-geometry pass now consumes those declaration lines (the caption styling and equation-number scoping are not modelled), in the preamble and in the body alike. A preview test declares \captionsetup (plain and with [figure]) and \numberwithin before and inside the document, then checks "Text." renders with no warnings and no leaked declarations.
This commit is contained in:
1 parent
ebb178bff5
commit
6139621653
4 files changed
+31
-6
No files matched your search
@@ -3051,6 +3051,14 @@ fn strip_page_geometry(
|
||||
// document's chosen families; consume the declaration.
|
||||
continue;
|
||||
}
|
||||
if trimmed.starts_with("\\captionsetup")
|
||||
|| trimmed.starts_with("\\numberwithin")
|
||||
|| trimmed.starts_with("\\DeclareCaption")
|
||||
{
|
||||
// Caption styling and equation-number scoping are accepted as
|
||||
// declarations; their visual/numbering effects are not modelled.
|
||||
continue;
|
||||
}
|
||||
if trimmed.starts_with("\\newenvironment") || trimmed.starts_with("\\renewenvironment") {
|
||||
if let Some(definition) = environment_definition(trimmed) {
|
||||
geometry.environments.push(definition);
|
||||
@@ -16515,6 +16523,23 @@ A definition.
|
||||
assert!(!text.contains("makeatletter"), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn caption_and_numbering_declarations_are_consumed() {
|
||||
let source = "\\documentclass{article}\n\\captionsetup{font=small}\n\\numberwithin{equation}{section}\n\\begin{document}\n\n\\captionsetup[figure]{font=small}\n\nText.\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["warnings"].as_array().map(Vec::len),
|
||||
Some(0),
|
||||
"{}",
|
||||
value["warnings"]
|
||||
);
|
||||
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
||||
assert!(svg.contains(">T</text>"), "{svg}");
|
||||
assert!(!svg.contains("captionsetup"), "{svg}");
|
||||
assert!(!svg.contains("numberwithin"), "{svg}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn phantom_commands_reserve_invisible_space() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\nA\\phantom{wide}B and \\vphantom{XX}C and \\hphantom{QQ}D.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user