How to have different text shown in figure caption and in outline?

Hello,

I am currently writing a paper where I need an outline for my images. I have used the following code below to achieve this. What I need now is to either customize the text that will be shown in the outline or that I can remove content based on the pattern. I have to show the source in the caption, but don’t want this to be shown in the outline.

#outline(
   target: figure.where(kind: image)
)

#figure(
   caption: "This is my caption - Source xyz",
   image("test.jpg")
)

Did any of you had this problem before?

Best regards,
Timo

Are you using the function cite() to add the sources to your figure captions? If that is the case, you could use an empty show rule inside the outline entries to hide the citations.

#show cite: it => [ \- Source #it]

#show outline.where(target: figure.where(kind: image)): it => {
  show outline.entry: it => {
    show cite: it => { }
    it
  }
  it
}

#figure(
  box(stroke: black, inset: 10pt)[some image.png],
  caption: [This is my caption #cite(<hh2010a>)]
)

#outline(target: figure.where(kind: image))

// .bib file from https://wiki.contextgarden.net/Sample_bib
#bibliography("refs.bib")

I created an example project here if you want to check the content of each it in the different show rules.

As an alternative, you can fully customize the text that will be shown in the outline with the following code which is taken from the Typst Examples Book.

#let in-outline = state("in-outline", false)
#show outline: it => {
  in-outline.update(true)
  it
  in-outline.update(false)
}

#let flex-caption(long, short) = context if in-outline.get() { short } else { long }

// And this is in the document.
#outline(title: [Figures], target: figure)

#figure(
  rect(),
  caption: flex-caption(
    [This is my long caption text in the document.],
    [This is short],
  )
)
Output