How to make different custom references for images and tables that are placed in figures?

Hello! At the moment, I am in the process of writing a typst template that will meet the standards for the design of a thesis document for my university.

According to the university standard, references to tables and figures in the text have different signatures. Considering the documentation by ref I use this code:

#set ref(supplement: it => {
  if it.func() == heading {
    "chap."
  } else if it.func() == figure {
    "fig."
  } else {
    "smth."    
  }
})

This code currently works only for figures, because images and tables placed in the figures for making corresponding captions for them. What should I do to make different refs for images and tables that are placed in figures?

Hi @Dice,

figures have the key kind to differentiate them by type. The default values are image, table, and raw, but custom kind types can also be used.
In your case, this would work:

#set ref(supplement: it => {
  if it.func() == heading {
    "chap."
  } else if it.func() == figure {
    if it.kind == table {
      "tbl."
    } else if it.kind == image {
      "img."
    }  else if it.kind == raw {
      "lst."
    } else {
      // none default figure kinds
      it.supplement
    }
  } else {
    "smth."    
  }
})
1 Like

Your solution solved my problem, thanks!

1 Like