No way to assign labels to figures passed to "wrap-content" and "wrap-top-bottom"
Esn024 opened this issue · comments
If what is passed to fixed
parameter in wrap-content
function is a figure, it becomes impossible to assign a label to it and reference it in the text. This is because currently Typst provides no way to add labels in code mode typst/typst#2317
One potential solution: add a label
parameter to wrap-content
function which would then add that label if what is passed to the fixed
parameter is a figure
(and, I suppose, top-label
and bottom-label
for wrap-top-bottom
function, to be added to figures in top-fixed
and bottom-fixed
).
Non-working example:
#set text(
font: "Noto Sans Limbu",
size: 10pt
)
#set page(
width: 4.25in,
height: 5.5in,
margin: (x: 1.1cm, y: 1.2cm),
)
#set par(
leading: 0.42em, //space between lines
justify: true,
)
#set heading(
numbering: "1.1.",
supplement: [§]
)
#outline()
//https://github.com/ntjess/wrap-it
//https://github.com/ntjess/wrap-it/blob/main/docs/manual.pdf
#import "@preview/wrap-it:0.1.0": wrap-content
= Introduction <intro>
Here's a working label/reference: @intro.
#figure(
rect(fill: red, radius: 0.5em, width: 8em, height: 2em),
caption: [A figure],
) <redrect>
Here's another working label/reference: @redrect
#let fig = figure(
rect(fill: teal, radius: 0.5em, width: 8em, height: 6em),
caption: [A figure],
)
#let body = [But it's impossible to reference the figure to the right. #lorem(80)]
#let wrapc(fig, body, align: right) = {
let boxed = box(fig, inset: (bottom: 0.3em, top: 0.3em)) //box with inset to add some more space
wrap-content(boxed, align: align)[#body]
}
#wrapc(fig, body, align: top + right)
You can use square brackets ([]
) to assign a label in this case:
#let fig = [
#figure(
rect(fill: teal, radius: 0.5em, width: 8em, height: 6em),
caption: [A figure],
)<another-label>
]
#let body = [Here's a reference to the next one: @another-label. #lorem(80)]
Thanks a lot! I hadn't thought of that. Might be worthwhile to mention that trick in the readme or manual. :)
Yes, came to the issues for this exact reason! Thank you, ntjess!