Ignore preamble-only guards

This commit is contained in:
gloamxun committed 2026-10-26 20:34:06 +08:00
1 parent 991498b0e1
commit 7c98c61b7a
3 files changed
+26 -2

No files matched your search

+24
View File
@@ -1028,6 +1028,23 @@ fn latex_internal_at(rest: &str, macros: &[MacroDefinition]) -> Option<(String,
return Some((chosen.to_string(), offset));
}
}
for command in ["\\@onlypreamble", "\\@nopreamble"] {
if let Some(after) = rest.strip_prefix(command) {
if boundary(after) {
let mut offset = command.len();
let cursor = after.trim_start();
offset += after.len() - cursor.len();
if let Some((_, used)) = braced_group(cursor) {
offset += used;
return Some((String::new(), offset));
}
if let Some((_, used)) = control_sequence(cursor) {
offset += used;
return Some((String::new(), offset));
}
}
}
}
for (command, pick) in [
("\\@firstofone", 0_usize),
("\\@firstoftwo", 0_usize),
@@ -12541,6 +12558,13 @@ See \ref{fig:a} and \ref{tab:b}.";
assert_eq!(body.trim(), "Yes andB");
}
#[test]
fn preamble_only_guards_leave_no_text() {
let source = "\\@onlypreamble\\foo\\@nopreamble\\bar Text";
let (body, _) = geometry_and_body(source);
assert_eq!(body.trim(), "Text");
}
#[test]
fn ifdefinable_runs_its_branch_for_undefined_commands() {
let source =