mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix equation resizing when adding the equation number (#4179)
This commit is contained in:
parent
90ce65adca
commit
53c306e32c
@ -466,25 +466,33 @@ fn resize_equation(
|
|||||||
if matches!(number_align.y, FixedAlignment::Center if is_multiline) {
|
if matches!(number_align.y, FixedAlignment::Center if is_multiline) {
|
||||||
// In this case, the center lines (not baselines) of the number frame
|
// In this case, the center lines (not baselines) of the number frame
|
||||||
// and the equation frame shall be aligned.
|
// and the equation frame shall be aligned.
|
||||||
let height = equation.height().max(number.height());
|
|
||||||
return equation.resize(
|
return equation.resize(
|
||||||
Size::new(width, height),
|
Size::new(width, equation.height().max(number.height())),
|
||||||
Axes::<FixedAlignment>::new(equation_align, FixedAlignment::Center),
|
Axes::<FixedAlignment>::new(equation_align, FixedAlignment::Center),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let excess_above = Abs::zero().max({
|
let excess_above = Abs::zero().max({
|
||||||
|
if !is_multiline || matches!(number_align.y, FixedAlignment::Start) {
|
||||||
let (.., baseline) = first;
|
let (.., baseline) = first;
|
||||||
number.baseline() - baseline
|
number.baseline() - baseline
|
||||||
|
} else {
|
||||||
|
Abs::zero()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let excess_below = Abs::zero().max({
|
let excess_below = Abs::zero().max({
|
||||||
|
if !is_multiline || matches!(number_align.y, FixedAlignment::End) {
|
||||||
let (size, .., baseline) = last;
|
let (size, .., baseline) = last;
|
||||||
(number.height() - number.baseline()) - (size.y - baseline)
|
(number.height() - number.baseline()) - (size.y - baseline)
|
||||||
|
} else {
|
||||||
|
Abs::zero()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let height = equation.height() + excess_above + excess_below;
|
|
||||||
|
|
||||||
|
// The vertical expansion is asymmetric on the top and bottom edges, so we
|
||||||
|
// first align at the top then translate the content downward later.
|
||||||
let resizing_offset = equation.resize(
|
let resizing_offset = equation.resize(
|
||||||
Size::new(width, height),
|
Size::new(width, equation.height() + excess_above + excess_below),
|
||||||
Axes::<FixedAlignment>::new(equation_align, FixedAlignment::Start),
|
Axes::<FixedAlignment>::new(equation_align, FixedAlignment::Start),
|
||||||
);
|
);
|
||||||
equation.translate(Point::with_y(excess_above));
|
equation.translate(Point::with_y(excess_above));
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 518 B After Width: | Height: | Size: 1.2 KiB |
BIN
tests/ref/math-equation-number-align-multiline-no-expand.png
Normal file
BIN
tests/ref/math-equation-number-align-multiline-no-expand.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@ -194,22 +194,67 @@ $ q &= sum_k ln A \
|
|||||||
// numbering's layout box. Note we use pattern "1" here, not "(1)", since
|
// numbering's layout box. Note we use pattern "1" here, not "(1)", since
|
||||||
// the parenthesis exceeds the numbering's layout box, due to the default
|
// the parenthesis exceeds the numbering's layout box, due to the default
|
||||||
// settings of top-edge and bottom-edge of the TextElem that laid it out.
|
// settings of top-edge and bottom-edge of the TextElem that laid it out.
|
||||||
|
#let equations = [
|
||||||
|
#box($ - - - $, fill: silver)
|
||||||
|
#box(
|
||||||
|
$ - - - \
|
||||||
|
a = b $,
|
||||||
|
fill: silver)
|
||||||
|
#box(
|
||||||
|
$ a = b \
|
||||||
|
- - - $,
|
||||||
|
fill: silver)
|
||||||
|
]
|
||||||
|
|
||||||
#set math.equation(numbering: "1", number-align: top)
|
#set math.equation(numbering: "1", number-align: top)
|
||||||
#box(
|
#equations
|
||||||
$ - &- - \
|
|
||||||
a &= b $,
|
|
||||||
fill: silver)
|
|
||||||
|
|
||||||
#set math.equation(numbering: "1", number-align: horizon)
|
#set math.equation(numbering: "1", number-align: horizon)
|
||||||
#box(
|
#equations
|
||||||
$ - - - $,
|
|
||||||
fill: silver)
|
|
||||||
|
|
||||||
#set math.equation(numbering: "1", number-align: bottom)
|
#set math.equation(numbering: "1", number-align: bottom)
|
||||||
#box(
|
#equations
|
||||||
$ a &= b \
|
|
||||||
- &- - $,
|
--- math-equation-number-align-multiline-no-expand ---
|
||||||
fill: silver)
|
// Tests that if the numbering's layout box doesn't vertically exceed the
|
||||||
|
// box of the equation frame's boundary, the latter's frame size remains.
|
||||||
|
// So, in the grid below, frames in each row should have the same height.
|
||||||
|
#set math.equation(numbering: "1")
|
||||||
|
#grid(
|
||||||
|
columns: 4 * (1fr,),
|
||||||
|
column-gutter: 3 * (2pt,),
|
||||||
|
row-gutter: 2pt,
|
||||||
|
align: horizon,
|
||||||
|
[
|
||||||
|
#set math.equation(number-align: horizon)
|
||||||
|
#box($ - - \ a \ sum $, fill: silver)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
#set math.equation(number-align: bottom)
|
||||||
|
#box($ - - \ a \ sum $, fill: silver)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
#set math.equation(number-align: horizon)
|
||||||
|
#box($ sum \ a \ - - $, fill: silver)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
#set math.equation(number-align: top)
|
||||||
|
#box($ sum \ a \ - - $, fill: silver)
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
#set math.equation(number-align: horizon)
|
||||||
|
#box($ - - $, fill: silver)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
#set math.equation(number-align: top)
|
||||||
|
#box($ - - $, fill: silver)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
#set math.equation(number-align: bottom)
|
||||||
|
#box($ - - $, fill: silver)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
--- issue-numbering-hint ---
|
--- issue-numbering-hint ---
|
||||||
// In this bug, the hint and error messages for an equation
|
// In this bug, the hint and error messages for an equation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user