How to reference multiple figures at once?

I want to reference multiple figures at once so that it displays as “(Figures 1 and 2)” or something along the lines. Is there a way to remove the automated prefix applied when I reference a figure?

1 Like

You can do this manually by setting the supplement, @fig1 @fig2[and]

You can also create a semi-automated solution:

#let multiref(..tags, default: ",", last: " and") = {
  tags = tags.pos()
  ref(tags.first())
  for key in tags.slice(1, -1) {
    ref(key, supplement: default)
  }
  if tags.len() >= 2 {
    ref(tags.last(), supplement: default + last)
  }
}

#multiref(<fig1>, <fig2>)
2 Likes

Thank you! I wasn’t aware of the supplement modifier

Does this not produce “Figure 1 and 2” (singular)?


I guess you can use @fig1[Figures] @fig2[and]. Or you can query the tags, extract the figure supplement and add an ‘s’. But both options would not work across languages, if that’s a concern. (Then again, you probably won’t change the document’s language too often :slight_smile: )

#let multiref(..args, default: ",", last: " and") = context{
  let tags = args.pos()
  let fig = query(tags.first()).first()
  let suppl = fig.supplement
  
  if tags.len() >= 2 { suppl + "s" } else { suppl }  // assumes we get the plural by adding an "s" to the singular form
  ref(tags.first(), supplement: "")  // figure number, alternatively our do something with the fig.counter
  for key in tags.slice(1, -1) {
    ref(key, supplement: default)
  }
  ref(tags.last(), supplement: last)
  // Figure 1; Figures 1 and 2; Figures 1, 2 and 3
}

You’re right, I somehow missed that. Thanks for fixing the code!

1 Like

It would be nice if Typst automatically handled contiguous references similar to citation references.

1 Like