Astrid
January 7, 2026, 11:05am
1
How do I include a reference inside an equation?
Say I have
#set math.equation(numbering: "1.")
$ 2 + 2 = 4 $ <lemma>
$ 2 + 2 + 2 =^"Ref here" 4 + 2 $
How do I replace "Ref here" with a reference to the lemma? The @lemma syntax doesn’t appear to work in math mode and when I try ref("lemma") I get error: unknown variable: ref. Same with link.
2 Likes
Chern
January 7, 2026, 11:34am
2
In Math mode, you can use #[] instead, for example
#set math.equation(numbering: "1.")
$ 2 + 2 = 4 $ <lemma>
$ 2 + 2 + 2 =^(#[@lemma]) 4 + 2 $
2 Likes
hpcfzl
January 7, 2026, 11:46am
3
Adding to what @Chern already brought up.
The parentheses aren’t mandatory:
$ 2 + 2 + 2 =^#[@lemma] 4 + 2 $
Consider also changing the supplement argument to take up less space:
$ 2 + 2 + 2 =^#ref(supplement: "Eq", <lemma>) 4 + 2 $
Depending on how you’re using Typst, a How to fix this? message should appear which would resolve this issue:
2 Likes
Astrid
January 7, 2026, 11:56am
4
This works, thank you both!
I went with =^#[(#ref(supplement: none, <eq:monotonicity>))] and set math.equation(numbering: "(1)") to get references like “(1).”
I am using the built-in compiler and indeed upon further inspection of the output:
= hint: `ref` is not available directly in math, try adding a hash before it: #ref
Is there any logic to when # should be used? I have always thought of math mode as being similar to the {} environments i.e. # is redundant and wrong.
Chern
January 7, 2026, 1:14pm
5
For functions, symbols, etc. in the math module (see Math – Typst Documentation ), you can typically write them directly without the # prefix unless specifically required. For example:
$ lim_x = op("lim", limits: #true)_x $
Here, true requires the # prefix, but lim, op do not.
If you don’t need a supplement , you can write it more concisely as @some-label[] (but in math mode, use #[@some-label[]] instead); To change the supplement for all equations, you can use like:
#set math.equation(numbering: "(1)", supplement: "Eq")
Edit:
If you use
#set math.equation(numbering: "(1)")
then @some-label[] will only output the equation number (e.g., “1”) without the parentheses. You can use the following intead
#set math.equation(
numbering: (..nums) => (numbering("(1)", ..nums))
)
If you want the equation.number to depend on other counters, such as heading, you can write code similar to the following:
#set math.equation(numbering: (..nums) => {
let counter = counter(heading).at(here())
numbering("(1.1)", counter.at(0), ..nums)
})
3 Likes
Andrew
January 7, 2026, 3:08pm
6
Don’t forget to add summary to the details tag, or use a native details block with summary string.