Dear community,
I am currently trying to create a Tufte-style document. I am aware of the tufte-memo template on Typst universe, since I latook inspiration from it. However, I need to apply more style to obtain the look and feel of LaTeX tufte-book class.
Overall, I succeeded to create all the elements I need. However, I am struggling in referencing the figure elements. I have seen this discussion on the forum. It explains the problem, but the solution seems to not fit my needs.
The problem is the following. I want to create a sidefigure that can take any kind of content (image, table) which follows the general numbering of figures or tables. To this end, I use the drafting package.
Here is a MWE of the template
// mwe.typ
#import "@preview/drafting:0.2.2": *
#let template(body) = {
set par(justify: true)
set page(
paper: "a4",
margin: (
left: 1.5cm,
right: 7cm
)
)
set-page-properties()
set-margin-note-defaults(
stroke: none,
side: right,
margin-right: 5cm,
margin-left: 1.75cm,
)
body
}
#let sidefigure(content, caption: none, dy: - 1.5em) = margin-note(
context {
show figure.caption: it => context [
#set align(left)
#let kind = none
#if it.supplement.text.contains("Fig") {
kind = image
} else if it.supplement.text.contains("Tab") {
kind = table
}
#it.supplement #counter(figure.where(kind: kind)).display()#it.separator #it.body
]
set figure.caption(position: bottom)
figure(
content,
caption: caption
)
}, dy: dy
)
Here is the main.typ
// main.typ
#import "mwe.typ": *
#show: template.with()
= Section 1
#lorem(50)
#sidefigure(
rect(),
caption: "Figure Caption",
dy: -2em
) <fig:1>
// @fig:1 (it throws an error)
As you will see, the figure and its caption are correct. However, I can’t cite this figure in the text because the result of the sidefigure function is not a figure.
I tried something like #let subfigure = figure.with(kind: "subfig", supplement:[Figure]) and #show figure.where(kind: "subfig"): it => {...}, but I would like to avoid to have custom counters and a function for each kind of elements (e.g. sidetable, …).
Is there a workaround ?
Thank you.