From 326fd3380151551538d6f245f884d174551bdf0f Mon Sep 17 00:00:00 2001 From: Eric Biedert Date: Mon, 26 Aug 2024 17:26:50 +0200 Subject: [PATCH] Don't number empty regions of broken block equations (#4836) --- crates/typst/src/math/equation.rs | 9 ++++++++- .../issue-4829-math-pagebreaking-wrong-number.png | Bin 0 -> 394 bytes tests/ref/math-equation-number-empty.png | Bin 0 -> 116 bytes tests/suite/math/equation.typ | 4 ++++ tests/suite/math/multiline.typ | 12 ++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/ref/issue-4829-math-pagebreaking-wrong-number.png create mode 100644 tests/ref/math-equation-number-empty.png diff --git a/crates/typst/src/math/equation.rs b/crates/typst/src/math/equation.rs index df7cc0216..208540cd0 100644 --- a/crates/typst/src/math/equation.rs +++ b/crates/typst/src/math/equation.rs @@ -332,8 +332,10 @@ fn layout_equation_block( .layout_into_run(elem, styles)? .multiline_frame_builder(&ctx, styles); let width = full_equation_builder.size.x; + let can_break = + BlockElem::breakable_in(styles) && full_equation_builder.frames.len() > 1; - let equation_builders = if BlockElem::breakable_in(styles) { + let equation_builders = if can_break { let mut rows = full_equation_builder.frames.into_iter().peekable(); let mut equation_builders = vec![]; let mut last_first_pos = Point::zero(); @@ -415,9 +417,14 @@ fn layout_equation_block( }; // Add equation numbers to each equation region. + let region_count = equation_builders.len(); let frames = equation_builders .into_iter() .map(|builder| { + if builder.frames.is_empty() && region_count > 1 { + // Don't number empty regions, but do number empty equations. + return builder.build(); + } add_equation_number( builder, number.clone(), diff --git a/tests/ref/issue-4829-math-pagebreaking-wrong-number.png b/tests/ref/issue-4829-math-pagebreaking-wrong-number.png new file mode 100644 index 0000000000000000000000000000000000000000..1db8a5110a3d748bceb72e66dc5cf9ecd7c0002d GIT binary patch literal 394 zcmeAS@N?(olHy`uVBq!ia0vp^6+oQI0VEg}yH|KKFfaysx;TbZ+N1OXPK$`93r|Fbcu>w`c?s1u z1v<;D?&|TV*WbTAXXUrV8>#6=SC$$zFfz-jL@Yn4ye4#ljc7&7WgBm1HXaFs2M?R3 z`px^q5j;UHrj`LLlyCs3_#Nwx=!ddEeuc%uUo%W{?skZ!Jb1sl-F&-I-jr>t_A?dO z{0`i}6Q{L5kNZGb`zK!|D^s=XGrWSSE2oJ!lzOZ>SZ3q@T9om}$_lgcgAWd0TK6G5 zc3DVmQN${F>qChY)VzqP;NdJarEQNhtu(j}Og&xjY0kmyvoY=r%bve@dV1}* lyDzRJ-C4~D^~PU@|I81+b3Oa;+E5!5$eyl#F6*2UngDmHq|^Wa literal 0 HcmV?d00001 diff --git a/tests/ref/math-equation-number-empty.png b/tests/ref/math-equation-number-empty.png new file mode 100644 index 0000000000000000000000000000000000000000..9311f1147ab376893dd87e12b5d78e50b82b2471 GIT binary patch literal 116 zcmeAS@N?(olHy`uVBq!ia0vp^6+kS_0VEhE<%|3RQr4a>jv*Ddl7HAcG$dYm6xi*q zE4Q`cL-e2O=vNGpf3Br0XsWvM=waT+`8Ugg@Arx+EEemJvdQ`wuuXzNHfm~_M3K=- Oka3=_elF{r5}E)`1u1?2 literal 0 HcmV?d00001 diff --git a/tests/suite/math/equation.typ b/tests/suite/math/equation.typ index 2345de549..6cdf7b7ed 100644 --- a/tests/suite/math/equation.typ +++ b/tests/suite/math/equation.typ @@ -256,6 +256,10 @@ $ q &= sum_k ln A \ ], ) +--- math-equation-number-empty --- +// Test numbering on empty equations. +#math.equation(numbering: "1", block: true, []) + --- issue-4187-alignment-point-affects-row-height --- // In this bug, a row of "-" only should have a very small height; but // after adding an alignment point "&", the row gains a larger height. diff --git a/tests/suite/math/multiline.typ b/tests/suite/math/multiline.typ index 35f10ea41..b6d970f36 100644 --- a/tests/suite/math/multiline.typ +++ b/tests/suite/math/multiline.typ @@ -133,3 +133,15 @@ $ a &+ b + & c \ --- issue-1948-math-text-break --- // Test text with linebreaks in math. $ x := "a\nb\nc\nd\ne" $ + + +--- issue-4829-math-pagebreaking-wrong-number --- +// Test numbering of empty regions of broken equations. +#set page(height: 5em) +#set math.equation(numbering: "1") +#show math.equation: set block(breakable: true) + +#rect(height: 1.5em) + +$ a + b \ + a + b $