Actually nevermind, I got it to work with
show ref: it => {
if it.element.has("body") and it.element.body == [ ] {
return emph(link(it.target, label-to-string(it.target)), bold: false)
}
let referencable = (figure, math.equation, heading, footnote)
if it.element == none { return it }
if it.element.func() in referencable { return it }
if it.target != to-label(it.element) { return it }
emph(link(it.target, it.element), bold: false)
}
and
#let to-label(body) = {
// Convert body to string, replace non-letter characters with
// hyphens, and ensure that it doesn't end with a hyphen.
import "@preview/t4t:0.4.2": get
label(get.text(body)
.replace(regex("[^\p{L}\p{N}\-]+"), "-")
.trim("-", at: end))
}
#let label-to-string(string) = str(string).replace("-", " ")
#let define(word, hide: false) = {
if hide {
[
#figure(
[ ],
)
#to-label(word)
#v(0fr)
]
// emph[#word#to-label(word)]
} else {
emph[#word#to-label(word)]
}
}