You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why can't you reference an item in an enumeration? I would assume you can access it as "Item X" or something similar
From web app user feedback
Reacted by raphCode, Erik Funder Carstensen, Salman Naqvi, Dmitrij Abramov, Christoph Groß, Julius Freudenberger, Benedikt, Jankin Wei, Victor L., Marciano Siniscalchi and 94 more
Reacted by George Honeywood, abejlq, Victor L., Marciano Siniscalchi, bjoluc, Splines, vslavkin, David Gómez-Castro, Moritz Hedtke, Eduard Stromenko and 15 more
I couldn't get the trick with the invisible figure to work on typst 0.12.0 but, FWIW, here's a workaround I came up with. Unfortunately, it only works with explicitly numbered enums, and you have to explicitly provide the numbering scheme in each reference if it isn't "1" (it's also generally a bit wonky).
#showref: it=> {
letel= it.elementifel!=noneandel.func() ==enum.item {
// Reference to an enum.item. Currently only works for _explicitly_ numbered enums; also, the// label must be immediately after the enum.item, but _not_ part of it (i.e., not indented).letsup= it.supplement;
let (text, style) = ifsup==auto {
// Default reference text and style.
([Item~], "1")
} elseifsup.func() ==text {
// The author provided a replacement for "Item"
([#sup.text~], "1")
} else {
// The author provided a replacement for "Item" and a numbering scheme.
(sup.children.slice(0, -1).join(), sup.children.at(-1).text)
}
link(el.location(), [#text#numbering(style, el.number)])
} else {
// Other references as usual.it
}
}
1. first item
<first>
2. second item with a default reference to @first<second>
3. third item with a named reference to @second[Case]
<third>
Reference to @third[Item~(a)] with custom numbering.
Reference to @third[ (i)] with custom numbering and no leading text.
Here is a different workaround for typst 0.12, which doesn't require explicitly numbered enums and abuses the fact that you can't otherwise make a reference to text. Support for supplements and different numbering schemes is left out.
#let enum_numbering = (..it) => {
counter("enum").update(it.pos())
numbering("1.1.", ..it)
}
#set enum(numbering: enum_numbering, full: true)
#show ref: it => {
let el = it.element
if el != none and el.func() == text {
// Override enum references.
link(el.location(), context numbering("1.1", ..counter("enum").at(el.location())))
} else {
// Other references as usual.
it
}
}
+ First <item1>
+ Second <item2>
+ Third <item3>
5. Fourth <item4>
Items @item1, @item2, @item3, and @item4.
Reacted by Robin, Robert Bamler, Thomas and CodeBu
I'm elaborated on @GunnarFarneback 's solution. Added support for custom enum item numbering, custom support, and made it work when the item includes more than text.
Here is the code, with output (typst 0.13.0) if you want to use it copy up-to the demonstration part:
/// Metadata marker for enum items labels,/// used to allow reference with the `enum-label` function#letenu-label-mark= metadata("enumeration_label")
/// Add a label to an enumeration item.////// Used as:/// ```typ/// + #enum-label("first")first/// + second/// + third #enum-label[third]////// I can ref @first and @third[It.]/// // I can ref Item~1 and It.~3/// ```////// The label can be used anywhere in the enumeration item./// Calling enum-label works with str or text content.#letenum-label(label) = {
iftype(label) ==content {
// informative error messageassert(label.has("text"), message: "enum-label requires text content")
label=label.text
}
[#enu-label-mark#std.label(label)]
}
/// Counter name for tracking of enumeration items#letenum-counter-name= "enum-counter"/// State for tracking the numbering format of enumeration items#letenum-numbering-state= state("enum-numbering", none)
/// Wrapper for enum numbering to allow for a references to enum items./// The desired numbering format is passed as an argument (str or function)/// To reference an item use `enum-label` function.////// ```typ////// #set enum(numbering: wrapped-enum-numbering("1.1"), full: true)/// + #enum-label("one")first/// #set enum(numbering: wrapped-enum-numbering("I.1"), start: 2)/// + second/// + third #enum-label[another]///// One is @one[] and another is @another[] // One is 1 and another is II.2/// ```#letwrapped-enum-numbering(numbering) = {
letenum-numbering= (..it,) => {
enum-numbering-state.update(x=>numbering)
counter(enum-counter-name).update(it.pos())
std.numbering(numbering, ..it)
}
enum-numbering
}
/// Copy from tools4typst/// return true if value is an empty array, dictionary, string or content#letis-empty(value) = {
letempty-values= (
array: (),
dictionary: (:),
str: "",
content: [],
)
lett= repr(type(value))
iftinempty-values {
returnvalue==empty-values.at(t)
} else {
returnvalue==none
}
}
#showref: it=> {
letel= it.elementifel!=noneandel.func() ==metadataandel==enu-label-mark {
letsupp= it.supplementifsupp==auto {
supp="Item"
}
// get the counter value in the correct format according to locationletloc= el.location()
letref-counter= contextnumbering(state("enum-numbering").at(loc), ..counter(enum-counter-name).at(loc))
ifis-empty(supp) {
link(el.location(), ref-counter)
}
else {
link(el.location(), box([#supp~#ref-counter]))
}
} else {
it
}
}
/// Demonstration starts here#setenum(numbering: wrapped-enum-numbering("(E1)"), full: true)
Group axioms:
+ #enum-label("ax:ass")Associativity
+ #enum-label("ax:id")Existence of identity element
+ #enum-label("ax:inv")Existence of inverse element
#setenum(numbering: wrapped-enum-numbering("1.a"), full: true)
#setmath.equation(numbering: "(1.1)")
Another important list:
+ Newton's laws of motion are three physical laws that relate the motion of an object to the forces acting on it.
+ A body remains at rest, or in motion at a constant speed in a straight line, unless it is acted upon by a force.
+ The net force on a body is equal to the body's acceleration multiplied by its mass
+ #enum-label[newton-third]If two bodies exert forces on each other, these forces have the same magnitude but opposite directions
+ #enum-label[hook1] Another important force is hooks law:
$arrow(F) = -k arrow(Delta x) $<eq:hook>#enum-label[hook2]
We covered the three group axioms @ax:ass[], @ax:id[] and @ax:inv[].
It is important to remember Newton's third law @newton-third, and Hook's law @hook1. In @hook2 we gave Hook's law in @eq:hook.
Notice that both enum-label-s "hook1" and "hook2" produce good refs (unlike usual labels where only the last works).
Also, notice that I used enum-label("ax:id") and not enum-label[ax:id]. Ideally the second would work but I couldn't think of a simple way to convert the content to string.
Reacted by pippaine, Shivang Patel, la .uetcis., Jason Siefken and Giuseppe Mariotti
I'd like this feature as well. It took me a good deal of searching to convince myself that Typst doesn't have the feature currently. Naively, as a LaTeX user, I took it for granted that Typst supported labels to enum items.
Reacted by Kirill Lukashev, Emily, Fabian Bosshard, Matthew Ward, Juan Felipe Coronel and Javier P. García
I find myself wanting to attach a supplement to my enum references, e.g. 'step 1', 'step 2' / 'goal 1', 'goal 2'. To that end I've written a snippet that supports this like so
#show: enable-referable-enums#setenum(numbering: "a.", full: true)
#referable-enum("step")[
+ foo
+ bar <baz>
]
@baz// Renders as 'step b'
implementation here:
Click to expand
#let_state-referable-enum= state("--state-referable-enum", none)
#let_counter-referable-enum= counter("--counter-referable-enum")
// Both arguments assumed to be strings.#let_get-greatest-suffix(sample1, sample2) = {
letsuffix= ("",)
for (c1, c2) insample1.rev().split("").zip(sample2.rev().split("")) {
ifc1==c2 {
suffix.push(c1)
} else {
break
}
}
suffix.rev().join("")
}
#let_remove-suffix(x, suffix) = {
assert(x.ends-with(suffix))
x.slice(0, x.len() -suffix.len())
}
/// *Example:*////// ```typst/// #show: enable-referable-enums/// #set enum(numbering: "a.", full: true)/// #referable-enum("Step")[/// + foo/// + bar <baz>/// ]/// @baz // Renders as 'Step b'/// ```////// - supplement (str): The name to use when referencing this enum, e.g. the 'Step' in 'Step 1'./// - doc (content): Content/// -> content#letreferable-enum(supplement, doc) = context {
letcurrent-numbering= enum.numberingassert(enum.full, message: "Only `enum.full = true` is supported right now. Add `#set enum(full: true)`.")
letwrap-numbering(..it) = {
_counter-referable-enum.update(it.pos())
numbering(current-numbering, ..it)
}
setenum(numbering: wrap-numbering)
letsample1= numbering(current-numbering, 1)
letsample2= numbering(current-numbering, 2)
letsuffix= _get-greatest-suffix(sample1, sample2)
_state-referable-enum.update((supplement, suffix, current-numbering))
doc
}
/// Referable enums./// Use as e.g. `#show: enable-referable-enums`#letenable-referable-enums(doc) = {
showref: it=> {
letel= it.elementletloc= el.location()
ifel!=noneandel.func() ==textand_state-referable-enum.at(loc) !=none {
let (supplement, suffix, current-numbering) = _state-referable-enum.at(loc)
letnumbers= numbering(current-numbering, .._counter-referable-enum.at(loc))
// Override enum references.link(loc, supplement+""+_remove-suffix(numbers, suffix))
} else {
// Other references as usual.it
}
}
doc
}
Reacted by Tamás Halasi, Paul Adam, Brandon Stride, Steven Morad and AprilGrimoire
Activity
Wsine commentedon Nov 22, 2023
I do favor this feature.
I want to write a research statement with a bibliography in a single
.typdocument.caemor commentedon Nov 29, 2023
There is a workaround by @PgBiel : https://gist.github.com/PgBiel/23a116de4a235ad4cf6c7a05d6648ca9
Still native integration would be preferred.
Y-jiji commentedon May 2, 2024
Just add a dummy figure before the labeled item, and use a
placecommand and remove its presence in layout.Wsine commentedon May 7, 2024
I tested the usage. This amended works.
Be aware to add
#fake_label("your_label")to every enum item. Otherwise, the indexes are wrong.robamler commentedon Nov 3, 2024
I couldn't get the trick with the invisible figure to work on typst 0.12.0 but, FWIW, here's a workaround I came up with. Unfortunately, it only works with explicitly numbered enums, and you have to explicitly provide the numbering scheme in each reference if it isn't
"1"(it's also generally a bit wonky).GunnarFarneback commentedon Jan 16, 2025
Here is a different workaround for typst 0.12, which doesn't require explicitly numbered enums and abuses the fact that you can't otherwise make a reference to text. Support for supplements and different numbering schemes is left out.
MiledMFN commentedon Feb 4, 2025
I couldn’t get the actual label from the code of @GunnarFarneback. My code of labeling is this:
#set heading(numbering: "I.1")
#set heading(numbering: (..nums) => {
if nums.pos().len() == 1 {
"I" // For level 1
} else {
str(nums.pos().last()) // For level 2, show only the second number
}
})
#let current-section() = {
context counter(heading).display()
}
#set enum(numbering: n => {
current-section() + numbering("a", n) + "."
})
Help please. Thank you for the previous answers.
BarakKatzir commentedon Mar 5, 2025
I'm elaborated on @GunnarFarneback 's solution. Added support for custom enum item numbering, custom support, and made it work when the item includes more than text.
Here is the code, with output (typst 0.13.0) if you want to use it copy up-to the demonstration part:
Notice that both
enum-label-s"hook1"and"hook2"produce good refs (unlike usual labels where only the last works).Also, notice that I used
enum-label("ax:id")and notenum-label[ax:id]. Ideally the second would work but I couldn't think of a simple way to convert the content to string.gkb commentedon Sep 29, 2025
I'd like this feature as well. It took me a good deal of searching to convince myself that Typst doesn't have the feature currently. Naively, as a LaTeX user, I took it for granted that Typst supported labels to enum items.
DegrangeM commentedon Oct 14, 2025
With #6619 enum can now be used with query. Couldn't this be used to make reference enum item ?
patrick-kidger commentedon Oct 15, 2025
I find myself wanting to attach a supplement to my enum references, e.g. 'step 1', 'step 2' / 'goal 1', 'goal 2'. To that end I've written a snippet that supports this like so
implementation here:
Click to expand