summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <me@mkor.je>2024-09-27 08:34:38 +0000
committerGitHub <noreply@github.com>2024-09-27 08:34:38 +0000
commit93a5b712b1919859fa526e989477db2e7256689f (patch)
tree3a104a02465cb5012e127b400d0e1afd2ffa8432
parentab67eee2d479e72834598bb681bd0eb493f0dec2 (diff)
Fix `math.lr` size argument not being applied to enclosed `math.mid` (#5050)
-rw-r--r--crates/typst/src/math/lr.rs27
-rw-r--r--tests/ref/math-lr-mid-size-nested-equation.pngbin0 -> 900 bytes
-rw-r--r--tests/ref/math-lr-mid-size.pngbin0 -> 2210 bytes
-rw-r--r--tests/ref/math-lr-nested.pngbin0 -> 126 bytes
-rw-r--r--tests/suite/math/delimited.typ35
5 files changed, 51 insertions, 11 deletions
diff --git a/crates/typst/src/math/lr.rs b/crates/typst/src/math/lr.rs
index 80ce55eb..ccaf2959 100644
--- a/crates/typst/src/math/lr.rs
+++ b/crates/typst/src/math/lr.rs
@@ -3,7 +3,9 @@ use unicode_math_class::MathClass;
use crate::diag::SourceResult;
use crate::foundations::{elem, func, Content, NativeElement, Packed, Smart, StyleChain};
use crate::layout::{Abs, Axis, Em, Length, Rel};
-use crate::math::{stretch_fragment, LayoutMath, MathContext, MathFragment, Scaled};
+use crate::math::{
+ stretch_fragment, EquationElem, LayoutMath, MathContext, MathFragment, Scaled,
+};
use crate::text::TextElem;
/// How much less high scaled delimiters can be than what they wrap.
@@ -21,13 +23,9 @@ pub struct LrElem {
/// The delimited content, including the delimiters.
#[required]
#[parse(
- let mut body = Content::empty();
- for (i, arg) in args.all::<Content>()?.into_iter().enumerate() {
- if i > 0 {
- body += TextElem::packed(',');
- }
- body += arg;
- }
+ let mut arguments = args.all::<Content>()?.into_iter();
+ let mut body = arguments.next().unwrap_or_default();
+ arguments.for_each(|arg| body += TextElem::packed(',') + arg);
body
)]
pub body: Content,
@@ -37,9 +35,16 @@ impl LayoutMath for Packed<LrElem> {
#[typst_macros::time(name = "math.lr", span = self.span())]
fn layout_math(&self, ctx: &mut MathContext, styles: StyleChain) -> SourceResult<()> {
let mut body = self.body();
- if let Some(elem) = body.to_packed::<LrElem>() {
- if elem.size(styles).is_auto() {
- body = elem.body();
+
+ // Extract from an EquationElem.
+ if let Some(equation) = body.to_packed::<EquationElem>() {
+ body = equation.body();
+ }
+
+ // Extract implicit LrElem.
+ if let Some(lr) = body.to_packed::<LrElem>() {
+ if lr.size(styles).is_auto() {
+ body = lr.body();
}
}
diff --git a/tests/ref/math-lr-mid-size-nested-equation.png b/tests/ref/math-lr-mid-size-nested-equation.png
new file mode 100644
index 00000000..df010668
--- /dev/null
+++ b/tests/ref/math-lr-mid-size-nested-equation.png
Binary files differ
diff --git a/tests/ref/math-lr-mid-size.png b/tests/ref/math-lr-mid-size.png
new file mode 100644
index 00000000..12b4c086
--- /dev/null
+++ b/tests/ref/math-lr-mid-size.png
Binary files differ
diff --git a/tests/ref/math-lr-nested.png b/tests/ref/math-lr-nested.png
new file mode 100644
index 00000000..eb172009
--- /dev/null
+++ b/tests/ref/math-lr-nested.png
Binary files differ
diff --git a/tests/suite/math/delimited.typ b/tests/suite/math/delimited.typ
index 632fbd40..d6e1d864 100644
--- a/tests/suite/math/delimited.typ
+++ b/tests/suite/math/delimited.typ
@@ -52,6 +52,31 @@ $ { x mid(|) sum_(i=1)^oo phi_i (x) < 1 } \
mid(bar.v.double)
floor(hat(I) mid(slash) { dot mid(|) dot } mid(|) I/n) } $
+--- math-lr-mid-size ---
+// Test mid when lr size is set.
+#set page(width: auto)
+
+$ lr({ A mid(|) integral }) quad
+ lr(size: #1em, { A mid(|) integral }) quad
+ lr(size: #(1em+20%), { A mid(|) integral }) \
+
+ lr(] A mid(|) integral ]) quad
+ lr(size: #1em, ] A mid(|) integral ]) quad
+ lr(size: #(1em+20%), ] A mid(|) integral ]) \
+
+ lr(( A mid(|) integral ]) quad
+ lr(size: #1em, ( A mid(|) integral ]) quad
+ lr(size: #(1em+20%), ( A mid(|) integral ]) $
+
+--- math-lr-mid-size-nested-equation ---
+// Test mid size when lr size is set, when nested in an equation.
+#set page(width: auto)
+
+#let body = ${ A mid(|) integral }$
+$ lr(body) quad
+ lr(size: #1em, body) quad
+ lr(size: #(1em+20%), body) $
+
--- math-lr-unbalanced ---
// Test unbalanced delimiters.
$ 1/(2 (x) $
@@ -63,6 +88,16 @@ $ 1/(2 y (x) (2(3)) $
// and immediately before the closing.
$ [#h(1em, weak: true)A(dif x, f(x) dif x)sum#h(1em, weak: true)] $
+--- math-lr-nested ---
+// Test nested lr calls.
+#let body1 = math.lr($|$, size: 4em)
+#let body2 = $lr(|, size: #4em)$
+
+$lr(|, size: #2em)$
+$lr(lr(|, size: #4em), size: #50%)$
+$lr(body1, size: #50%)$
+$lr(body2, size: #50%)$
+
--- issue-4188-lr-corner-brackets ---
// Test positioning of U+231C to U+231F
$⌜a⌟⌞b⌝$ = $⌜$$a$$⌟$$⌞$$b$$⌝$