How to change numbering format of equations, figures and tables only in supplement?

Hi all, I am attempting to write an academic paper in Typst, but I have hit some formatting issues.

The paper I am writing is composed of a main section, as well as a supplement. I would like to number headings, figures, tables and equations in the main section like “1” etc, but in the supplement I would like to number them like “S1” etc.

Since there is no way to cross reference a separate document in Typst I am just including the supplement at the end of the main document. This is necessary, as I refer to supplementary sections from the main paper.

Based on a similar question I have created a MWE for the main paper:

#let supplement(content) = {
  set heading(numbering: "S1")
  set math.equation(numbering: "(S1)") // this is not changing the formating...
  counter(heading).update(0)
  counter(figure).update(0) // why is this not updating?
  counter(math.equation).update(1) // this seems to work?

  state("supplement").update(true)
  content
}

#set figure(numbering: n => {
  let appx = state("supplement", false).get()
  let format = if appx {
    "S 1"
  } else {
    "1"
  }
  numbering(format, n)
})

#set math.equation(numbering: n=> { // why does this not do anything?
  let appx = state("supplement", false).get()
  let format = if appx {
    "S 1"
  } else {
    "1"
  }
  numbering(format, n)
})

#set heading(numbering: "1")
#set math.equation(numbering: "(1)")

#let testfig(caption) = {
	figure(box(width:3cm, height:1cm, stroke: 1pt), caption: caption)
}
#set page(width: auto, height: auto, margin: 2em)

= Start
<sec1>
In @sec1 Citing the figures in order @first, @second, and @third.
#testfig[First Box] <first>
Let us cite @eq1 as well.
$
2+2
$ <eq1>
Use a table here called @tab which is different to @stab.
#figure(
  table(
    columns: 2,
    [blah], [blah]
  ),
  caption: [A table]
) <tab>

= Next
#lorem(10)
#testfig[Second Box] <second>

Supplementary citations include: @s_sec and @a_eq but these don't display...

#show: supplement

#include "supp.typ"

and another MWE for the supplement:

#let testfig(caption) = {
	figure(box(width:3cm, height:1cm, stroke: 1pt), caption: caption)
}
#set page(width: auto, height: auto, margin: 2em)


= Supplement
<s_sec>
#lorem(10)
#testfig[Third Box] <third>

Some more text...

#figure(
  table(
    columns: 2,
    [blah], [blah]
  ),
  caption: [A table]
) <stab>

$1 + 1$ <a_eq>

Unfortunately, this solution does not work because:

  1. the figure and table counters do not reset (but the header, and maybe the equation?, does weirdly enough…)
  2. the math equation in the supplement does not display its numbering next to its definition
  3. The heading and math references in the supplement do not display the “S1” style formatting

If anyone has any fixes, I would really appreciate it! I am at a loss of what to do now :frowning:

the issue is that there isn’t a single figure counter, but one for each figure kind. so, instead of just doing this:

counter(figure).update(0)

you also wanna do:

counter(figure.where(kind: table)).update(0)
counter(figure.where(kind: image)).update(0)
counter(figure.where(kind: raw)).update(0)

as for the equation in the supplement, you forgot to make it a block equation; inline equations (which is what you have) aren’t numbered. just change $1+1$ to $ 1+1 $.

also, to S-ify your numberings, you can just use normal set rules directly and skip all of your state code. i see that you’d already done that with headings and equations, so just add this for figures:

#let supplement(content) = {
  set heading(numbering: "S1")
  set math.equation(numbering: "(S1)")
  set figure(numbering: "S1")
  // ...
  content

and delete your appx (unless you truly need it, for something else) and all of the individual #set xxx(numbering: n => ... overrides that look at the appx state. they’re unnecessary.

as for the references not being S-ified, i think that’s an automatic feature that strips affixes from numbering patterns when they’re in prose. you can avoid this by using a function:

  set heading(numbering: (..ns) => numbering("S1", ..ns))
  // etc. for the other ones

though this doesn’t really work for equations (because in that case, you do want the affixes to be stripped, rather than showing “see Equation (S2)”). i’m not sure how to work around that…

you can see the WIP result here

1 Like

Wow, this works perfectly, thank you very much!!

I really appreciate the fixes, I can submit my paper now :)

1 Like