Cross-references

Give a chunk a label and you can refer to its output from the prose with Typst’s @label syntax. Use a recognized prefix so Calepin knows what the label points at; a fig- label attaches to figure output.

There are three ways to attach a label. Use exactly one of them per chunk.

label argument

The clearest place for a label is the label argument of #calepin.chunk, alongside the caption:

In prose we mention Figure 1.

plot(mpg ~ hp, data = mtcars)

Figure 1: Miles per gallon and horsepower

Put #| label: at the top of a plain fenced block when you want the label next to other chunk options:

```r
#| label: fig-cross-qmd
#| fig-caption: Distribution of car weights
hist(mtcars$wt, col = "gray80", border = "white")
```

In prose we mention Figure 2.

hist(mtcars$wt, col = "gray80", border = "white")

Figure 2: Distribution of car weights

Trailing fence label

For a plain fenced block, you can also write a single label right after the closing fence. This is the most compact form, equivalent to one #| label: header:

```r
plot(dist ~ speed, data = cars)
```<fig-cross-trailing>
```

In prose we mention Figure 3.

```r
plot(dist ~ speed, data = cars)
```<fig-cross-trailing>
```
plot(dist ~ speed, data = cars)

Figure 3: Speed and stopping distance

Label prefixes

Use a recognized prefix so Calepin knows where the label belongs. A label without a recognized prefix, such as label: "myplot", is still a valid chunk identifier (you can look it up with #calepin.results), but it is not a cross-reference, so @myplot will not resolve.

PrefixTargetStatus
fig-Figure or plot outputSupported.
tbl-Table outputReserved for a later milestone.
lst-Code listing outputReserved for a later milestone.

tbl- and lst- labels are classified and can appear in chunk metadata today, but only fig- labels are attached to rendered output for now. Independent labels for sub-captioned panels (so a panel can be referenced as @fig-name-2) and multiple labels per chunk (label: ("fig-name", "lst-name")) are also planned for later milestones.