countfiguretypst

How can I create a separate count for supplementary figures?


For my thesis, I would like to have the option to count supplementary figures separately, but be able to mention them within the main text, without showing them.

If I simply add a figure in my appendix chapter as such:

#figure(
    grid(
      columns: 2,
      column-gutter: 4mm,
        [#image("../figures/dummy_image.svg", width: 70%)],
        [#image("../figures/dummy_image.svg", width: 70%)],
    ),
  caption: [#lorem(50)],
) <figure_supplementary_test>

and refer to it as @figure_supplementary_test[Supplementary Figure] in the text, it works but the figure count is of course not starting from 1 for the first Supplementary Figure but from its rank in all #figures in the document.

So for my first supplementary figure mentioned, I currently get a working link of the format (Supplementary Figure 7), as it is the 7th figure in my text, but I would like to have a working link of the format (Supplementary Figure 1).

Can I define a new figure type for this? Can I simply add an alternative counter?


Solution

  • You can use the kind parameter of the #figure() function in Typst to specify a separate counter. Then use the supplement parameter to define the label text for references.

    Example:

    = Main Text
    
    See @figure_supplementary_test.
    
    = Appendix
    
    #figure(
      grid(
        columns: 2,
        column-gutter: 4mm,
          image("../figures/dummy_image.svg", width: 70%),
          image("../figures/dummy_image.svg", width: 70%),
      ),
      caption: lorem(50),
      supplement: [Supplementary Figure],
      kind: "supp",
    ) <figure_supplementary_test>
    

    A set-rule can be used if you want to adjust the kind and supplement parameter default values for the rest of the document:

    ...
    
    = Appendix
    
    #set figure(kind: "supp", supplement: [Supplementary Figure])
    
    #figure(
      grid(
        columns: 2,
        column-gutter: 4mm,
          image("../figures/dummy_image.svg", width: 70%),
          image("../figures/dummy_image.svg", width: 70%),
      ),
      caption: lorem(50),
    ) <figure_supplementary_test>
    

    You can revert to the original behavior for figures by setting kind and supplement parameters back to auto, if required.