Set operator names upright and declare new ones
This commit is contained in:
1 parent
a4c4864d2b
commit
7ba66392ea
6 files changed
+120
-32
No files matched your search
@@ -1231,6 +1231,31 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
geometry.list_table_name = Some(name);
|
||||
continue;
|
||||
}
|
||||
if let Some(rest) = trimmed.strip_prefix("\\DeclareMathOperator") {
|
||||
let mut rest = rest.trim_start();
|
||||
let mut starred = false;
|
||||
if let Some(after) = rest.strip_prefix('*') {
|
||||
starred = true;
|
||||
rest = after.trim_start();
|
||||
}
|
||||
if let Some((command, tail)) = braced(rest) {
|
||||
if let Some((body, _)) = braced(tail.trim_start()) {
|
||||
let name = command.trim().trim_start_matches('\\').to_string();
|
||||
let operator = if starred {
|
||||
format!("\\operatorname*{{{}}}", body.trim())
|
||||
} else {
|
||||
format!("\\operatorname{{{}}}", body.trim())
|
||||
};
|
||||
geometry.macros.push(MacroDefinition {
|
||||
name,
|
||||
args: 0,
|
||||
default: None,
|
||||
body: operator,
|
||||
});
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if trimmed.starts_with("\\newcommand")
|
||||
|| trimmed.starts_with("\\renewcommand")
|
||||
|| trimmed.starts_with("\\providecommand")
|
||||
@@ -7560,6 +7585,17 @@ mod source_tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[test]
|
||||
fn operator_names_and_declared_operators_render() {
|
||||
let source = r"\DeclareMathOperator{\Tr}{Tr}
|
||||
|
||||
Body $\operatorname{rank}(A)$ and $\Tr(B)$.";
|
||||
let json = preview_json(source).expect("preview");
|
||||
assert!(json.contains(">r</text>"));
|
||||
assert!(!json.contains("operatorname"));
|
||||
assert!(!json.contains("DeclareMathOperator"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substack_scripts_paint_their_rows() {
|
||||
let json = preview_json("\\[\\sum_{\\substack{i=1 \\\\ j=2}} x\\]").expect("preview");
|
||||
|
||||
Reference in new issue
Block a user