diff options
| author | Pg Biel <9021226+PgBiel@users.noreply.github.com> | 2023-05-12 06:00:55 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-12 11:00:55 +0200 |
| commit | a8728be9b03f6f19df6adf1ea26a4713562dc0ae (patch) | |
| tree | 5f23c21b9e510b514cd61c256260602be83278f2 | |
| parent | e8de8a49c57671854f657a4eb1e2d86e5b12a281 (diff) | |
Initial support for breakable figures (#1121)
| -rw-r--r-- | library/src/meta/figure.rs | 15 | ||||
| -rw-r--r-- | tests/ref/meta/figure.png | bin | 54464 -> 71757 bytes | |||
| -rw-r--r-- | tests/typ/meta/figure.typ | 9 |
3 files changed, 21 insertions, 3 deletions
diff --git a/library/src/meta/figure.rs b/library/src/meta/figure.rs index 548233c4..2082701b 100644 --- a/library/src/meta/figure.rs +++ b/library/src/meta/figure.rs @@ -70,9 +70,14 @@ use crate::visualize::ImageElem; /// ) /// ``` /// +/// If your figure is too large and its contents are breakable across pages +/// (e.g. if it contains a large table), then you can make the figure breakable +/// across pages as well by using `#show figure: set block(breakable: true)` +/// (see the [block]($func/block) documentation for more information). +/// /// Display: Figure /// Category: meta -#[element(Locatable, Synthesize, Count, Show, Refable)] +#[element(Locatable, Synthesize, Count, Show, Finalize, Refable)] pub struct FigureElem { /// The content of the figure. Often, an [image]($func/image). #[required] @@ -254,12 +259,18 @@ impl Show for FigureElem { // We wrap the contents in a block. Ok(BlockElem::new() .with_body(Some(realized)) - .with_breakable(false) .pack() .aligned(Axes::with_x(Some(Align::Center.into())))) } } +impl Finalize for FigureElem { + fn finalize(&self, realized: Content, _: StyleChain) -> Content { + // Allow breakable figures with `show figure: set block(breakable: true)`. + realized.styled(BlockElem::set_breakable(false)) + } +} + impl Count for FigureElem { fn update(&self) -> Option<CounterUpdate> { // If the figure is numbered, step the counter by one. diff --git a/tests/ref/meta/figure.png b/tests/ref/meta/figure.png Binary files differindex 4969e5a0..593c6438 100644 --- a/tests/ref/meta/figure.png +++ b/tests/ref/meta/figure.png diff --git a/tests/typ/meta/figure.typ b/tests/typ/meta/figure.typ index 3537bbe1..81db3edf 100644 --- a/tests/typ/meta/figure.typ +++ b/tests/typ/meta/figure.typ @@ -101,4 +101,11 @@ We can clearly see that @fig-cylinder and println!("Hello, world!"); } ``` -]
\ No newline at end of file +] + +--- +// Test breakable figures +#set page(width: 200pt, height: 6em) +#show figure: set block(breakable: true) + +#figure(table[a][b][c][d][e], caption: [A table]) |
