Can I create my own custom syntax similar to @label?

Say I want §label (or another rare symbol) to refer to #ref(label, form: “page”), similar to how @label already refers to #ref(label, form: “normal”). Is something like that doable?

Sorry if there are posts about this already, I just don’t know any terms I could search for.

No, it’s not possible to add custom syntax like that. A variant that I’ve seen for citations is to use the supplement for custom rules like this. Here’s an example where we use @test[page] and page is the supplement:

#set page(numbering: "1")
#set heading(numbering: "1.1")

= Test <test>

#show ref: it => {
  if it.supplement == [page] {
    let (target, ..fields) = it.fields()
    ref(target, form: "page")
  } else {
    it
  }
}
See @test on @test[page]

1 Like

Thanks! Doesn’t look too bad, at least it’s much prettier than a full-on custom function.

You can achieve this using a show rule with a regex.

#show regex("§([a-z,0-9,A-Z]*)"): it => {
  let key = it.text.replace("§","")
  ref(label(key), form: "page")
}

#set page(numbering: "1")

= First <first>

#pagebreak()

= Second <second>

§first
§second

But I have no idea, which sideeffects this has.

1 Like