Fix weak spacing broken in math (#1966)

This commit is contained in:
sitandr 2023-08-26 18:36:52 +03:00 committed by GitHub
parent 45bd58fbaa
commit b2d6cb58dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View file

@ -418,11 +418,12 @@ impl LayoutMath for Content {
return realized.layout_math(ctx);
}
if let Some(children) = self.to_sequence() {
if self.is_sequence() {
let mut bb = BehavedBuilder::new();
for child in children {
bb.push(child.clone(), StyleChain::default());
}
self.sequence_recursive_for_each(&mut |child: &Content| {
bb.push(child.clone(), StyleChain::default())
});
for (child, _) in bb.finish().0.iter() {
child.layout_math(ctx)?;
}

View file

@ -85,12 +85,25 @@ impl Content {
/// Access the children if this is a sequence.
pub fn to_sequence(&self) -> Option<impl Iterator<Item = &Self>> {
if !self.is::<SequenceElem>() {
if !self.is_sequence() {
return None;
}
Some(self.attrs.iter().filter_map(Attr::child))
}
pub fn is_sequence(&self) -> bool {
self.is::<SequenceElem>()
}
/// Also auto expands sequence of sequences into flat sequence
pub fn sequence_recursive_for_each(&self, f: &mut impl FnMut(&Self)) {
if let Some(childs) = self.to_sequence() {
childs.for_each(|c| c.sequence_recursive_for_each(f));
} else {
f(self);
}
}
/// Access the child and styles.
pub fn to_styled(&self) -> Option<(&Content, &Styles)> {
if !self.is::<StyledElem>() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -39,3 +39,10 @@ $a cancel(equiv) b overline(+) c arrow(-) d hat(=>) e cancel(log) 5 dot(op("ln")
$a overbrace(equiv) b underline(+) c grave(-) d underbracket(=>) e circle(log) 5 caron(op("ln")) 6$ \
\
$a attach(equiv, tl: a, tr: b) b attach(limits(+), t: a, b: b) c tilde(-) d breve(=>) e attach(limits(log), t: a, b: b) 5 attach(op("ln"), tr: a, bl: b) 6$
---
// Test weak spacing
$integral f(x) dif x$,
// Not weak
$integral f(x) thin dif x$,
// Both are weak, collide
$integral f(x) #h(0.166em, weak: true)dif x$