Why does a citation in a figure caption get numbered in the wrong order?

I am writing a thesis and use the bibliography to cite my sources.

bibliography(title: "bibliography", "../bibliography.bib") 

And want to use the ieee style which is default. But now the problem is that I am first cite in the text an then I am using a cite in a figure/image like this:

blablabla #cite(<source1>).
later...
#figure(
  image("../images/Logo1.png", width: 40%),
  kind: image,
  caption: [Company Logo #cite(<logo>)]
)

Now the problem is that the figure get the [1] and in the text it gets [2]. Thats wrong because the one in the text is the first one cited.
I dont know if typst is rendering it earlier or something?

I hope someone can help

Hi there @Maximilian,

In order to help us help you, could you please:

  • mark your code appropriately for ease of reading and copy/pasting. You can syntax-highlight Typst code by wrapping it in ` ```typ … ````.

  • ensure you provide a minimum working example (MWE) that we could try to compile and then provide insight.

Thanks for your cooperation :wink:

To give you a hint, this would be an example of a MWE, which compiles, and which is quoted with back ticks.

#let bib-file-text = ```bib
@article{doe2020,
  author = {John Doe},
  title = {An IEEE Example},
  journal = {Journal of Examples},
  year = {2020}
}

@article{smith2025,
  author = {Bob Smith},
  title = {A Typst Example},
  journal = {Journal of Examples},
  year = {2025}
}

```.text

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

First cited #lorem(5) #cite(<doe2020>, form: "prose").

#figure(
  rect(), //image(“…/images/Logo1.png”, width: 40%),
  caption: [Second cited #cite(<smith2025>, form:"prose")]
)

#bibliography(bytes(bib-file-text), style: "ieee")
//#bibliography(bytes(bib-file-text), style: "ieee")

Note that in the previous example, this renders as expected with [1] in all cases.

EDIT: Added image outline to the MWE.
EDIT EDIT: Now we can reproduce your problem by moving the image outline at the beginning.

@PgBiel has quoted the proper way to solve.

But in my case the text and the figure cite got two different sources.
I want the image which is citing later to have the [2] and the text one [1].
But in my case its the other way around

Please see above. Describing the issue is good, but providing an example of the problem is easier.

It sounds like you have may have a figure outline, causing the citation to appear at the outline, such that it comes before the citation in your text. See this for a fix: How to have different text shown in figure caption and in outline? - #2 by janekfleper

2 Likes

Indeed, adding this:

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

solves the problem.

Thanks @PgBiel, I couldn’t understand the issue properly.