Keep integral scripts beside the operator
This commit is contained in:
1 parent
569160f805
commit
d237e0cc9b
4 files changed
+32
-6
No files matched your search
@@ -1394,6 +1394,15 @@ fn limits_override(chars: &[char], index: usize) -> Option<(bool, usize)> {
|
||||
None
|
||||
}
|
||||
|
||||
/// TeX puts scripts beside an integral unless `\limits` asks otherwise,
|
||||
/// while sums, products and operator-name operators stack them by default.
|
||||
fn operator_default_limits(base: &MathAtom) -> bool {
|
||||
match base {
|
||||
MathAtom::BigOperator { name } => name != "int",
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_limits(chars: &[char], next: usize, base: MathAtom) -> (MathAtom, usize) {
|
||||
let mut after = next;
|
||||
let mut forced = None;
|
||||
@@ -1422,9 +1431,10 @@ fn parse_limits(chars: &[char], next: usize, base: MathAtom) -> (MathAtom, usize
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
let stacked = forced.unwrap_or_else(|| operator_default_limits(&base));
|
||||
if sub.is_none() && sup.is_none() {
|
||||
(base, after)
|
||||
} else if forced == Some(false) {
|
||||
} else if !stacked {
|
||||
(
|
||||
MathAtom::Script {
|
||||
base: Box::new(base),
|
||||
@@ -3065,6 +3075,22 @@ mod tests {
|
||||
let limited = layout_math(&parse_math(r"\mathop{argmax}_{x}"), &font);
|
||||
assert!(limited.depth > plain.depth);
|
||||
}
|
||||
#[test]
|
||||
fn integrals_keep_scripts_beside_them_by_default() {
|
||||
let font = Cmr10Metrics::default();
|
||||
let integral = layout_math(&parse_math(r"\int_0^1"), &font);
|
||||
let sum = layout_math(&parse_math(r"\sum_0^1"), &font);
|
||||
assert!(
|
||||
integral.height < sum.height,
|
||||
"int scripts should sit beside it"
|
||||
);
|
||||
let forced = layout_math(&parse_math(r"\int\limits_0^1"), &font);
|
||||
assert!(
|
||||
forced.height > integral.height,
|
||||
r"\limits should stack int scripts"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nolimits_moves_scripts_beside_the_operator() {
|
||||
let font = Cmr10Metrics::default();
|
||||
|
||||
Reference in new issue
Block a user