mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Fix math.lr
size argument not being applied to enclosed math.mid
(#5050)
This commit is contained in:
parent
ab67eee2d4
commit
93a5b712b1
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
tests/ref/math-lr-mid-size-nested-equation.png
Normal file
BIN
tests/ref/math-lr-mid-size-nested-equation.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 900 B |
BIN
tests/ref/math-lr-mid-size.png
Normal file
BIN
tests/ref/math-lr-mid-size.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
tests/ref/math-lr-nested.png
Normal file
BIN
tests/ref/math-lr-nested.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 126 B |
@ -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$$⌝$
|
||||
|
Loading…
x
Reference in New Issue
Block a user