typst

Typst: Cannot reference heading/equations/figure/whatever without numbering


How to use reference without numberings. I really do not want to set the numbering, since it is very customized or I just do not want to use numbers! This should still be possible.

= Header
<my-header>

Please see @my-header[the Header]

I know I could just use

#set heading(numbering: "1.")

This however add automatic numeration to my headers, which is not what I want. I want to reference it, not to enumerate it.

This should be however possible, or there should be workarounds! besides cluttering the document with custom notation every single reference?


Solution

  • The error is given because @ref style uses a supplemental label, like Section 1 which isn't possible without a numbering format. An alternative is to just use the link function:

    #show link: it => {
      set text(blue)
      underline(it)
    }
    
    = Header
    <my-header>
    Please see #link(<my-header>)[My Header]
    

    Of course, you can always write your own show rule for refs to enable @ syntax:

    #let blue-underline(it) = underline[
      #set text(blue)
      #it
    ]
    
    #show link: blue-underline
    
    
    #show ref: it => {
      if it.element.numbering == none {
        // Use your custom scheme
        link(it.target, it.element.body)
      } else {
        // Default `ref`
        it
      }
    }
    
    = The Header
    <my-header>
    
    = Another header
    <another-header>
    
    Please see #link(<my-header>)[This heading] for more details.
    
    Or, check out @another-header
    

    enter image description here