Capture body-level let aliases

This commit is contained in:
gloamxun committed 2026-10-26 20:34:44 +08:00
1 parent 6efb210781
commit 2408736c5e
3 files changed
+31 -2

No files matched your search

+29
View File
@@ -4207,6 +4207,28 @@ fn capture_body_definitions(body: &mut String, macros: &mut Vec<MacroDefinition>
changed = true;
continue;
}
if let Some((name, target)) = macro_alias(definition_line) {
let source = macros
.iter()
.find(|definition| definition.name == target)
.cloned();
let definition = source.unwrap_or(MacroDefinition {
name: name.clone(),
args: 0,
default: None,
body: String::new(),
params: None,
});
macros.push(MacroDefinition {
name,
args: definition.args,
default: definition.default,
body: definition.body,
params: definition.params,
});
changed = true;
continue;
}
kept.push_str(line);
kept.push('\n');
}
@@ -12611,6 +12633,13 @@ See \ref{fig:a} and \ref{tab:b}.";
assert_eq!(body.trim(), "loaded missing");
}
#[test]
fn body_let_aliases_expand() {
let source = "\\def\\x{A}\n\\let\\y=\\x\n\n\\y b.";
let (body, _) = geometry_and_body(source);
assert_eq!(body.trim(), "A b.");
}
#[test]
fn body_definitions_expand_later_in_the_document() {
let source = "\\def\\greet{Hello}\n\n\\greet world.";