Hello and welcome @TheVisibleThing! The docs are difficult to navigate, information is pretty dispersed throughout!
1- How can I make reference for a custom counter
that I created?
In the docs, you can read about counter(key)
The counter element serves only one purpose: counting. A counter cannot be referenced by Typst’s ref
.
Now, if you want to create a custom element that is both countable and referenceable, you need
Then you will be able to count counter(figure.where(kind: "custom"))
. See the docs for ref
.
How can I get the number of any counter (as an integer) in some part of the text?
See Accessing a counter.
#context counter(heading).get()
With the new line
numbers, how can I get the current line number in some part of the document?
The line number is exposed through counter(par.line)
. However, I can’t seem to access the line number, I’ll have to ask @PgBiel to tag in for this one (if you don’t mind!).
#set par.line(numbering: "1")
#context counter(par.line).get()
Roses are red. \
#context counter(par.line).get()
Violets are blue. \
#context counter(par.line).get()
Typst is there for you.
How can I make a reference to a line number?
See this answer by @laurmaedje for TeX’s \pageref
.
#let pageref(label) = context {
let loc = locate(label)
let nums = counter(page).at(loc)
link(loc, numbering(loc.page-numbering(), ..nums))
}
Adapting this example for lineref
would be as simple as replacing counter(page)
by counter(par.line)
.
Unfortunately, there is no location.line-numbering
, so if your line numbering pattern changes throughout your document, best thing would be to update a state
variable.
Ideally, you would write something like
#let line-numbering = "1"
#set par.line(numbering: line-numbering)
#let lineref(label) = context {
let loc = locate(label)
let nums = counter(par.line).at(loc)
link(loc, numbering(line-numbering, ..nums))
}
= Lorem <ipsum>
#lineref(<ipsum>)
But I am unable to make counter(page.line)
return the correct line number.