I have a custom function for figures (my-block) and I am trying to add spacing above the figure which only activates after a line of text. That is, the padding above is not added if a my-block follows another my-block or a heading.
This is achieved by using the below:
par(spacing: 1.5cm)[] // padding above only on if it follows a paragraph
block(above: 0cm, below: 1.5cm) // padding below always on
See below for a MWE:
// mypackage:
#show figure.where(kind: "block"): set align(left)
#let set_figure_spacing(it) = {
show figure.where(kind: "block"): it => {
par(spacing: 1.5cm)[]
block(above: 0cm, below: 1.5cm, it
)
}
it
}
#let my-block(body, ..args) = {
figure(kind: "block", supplement: "Block", {
block(fill: red.lighten(70%), ..args, [#body])
}
)
}
//import: "mypackage.typ" *
// // wishing to remove this line and have it fully implemented on the basis of the package import above.
#show: set_figure_spacing
== Heading
#my-block[This is a block.] <ref>
Content goes in here @ref
#my-block[This is a block.]
#my-block[This is a block.]
Works.
Output:
The issue is that I have to use a show rule to get around putting the padding directly in my-block, as if I try and do this I am presented with the error: âcannot reference sequenceâ, e.g.
#let my-block(body, ..args) = {
par(spacing: 1.5cm)[]
figure(kind: "block", supplement: "Block", {
block(fill: red.lighten(70%), ..args, [#body])
}
)
}
For more complex reasons, I canât have anything in my main doc other than the package import, and currently not able to execute show in the package so it then flows through to where the package is called.
Looking for one of the two solutions:
- The ability to call show in the package and it be automatically applied when we import the package into a new doc
- The ability to include
par(spacing: 1.5cm)[]at the top andblock(above:0cm, below: 1.5cm)at the bottom withinmy-block
As both will allow the package import with no other code to achieve desired functionality.
Is either possible?
