> Due to the way Bibtex works, you may need to compile at least three times to see correct reference numbers in the PDF.
I'm not sure I understand why the second or third compile would work, but not the first.
This talk contains a really good explanation of this problem (and also discussion around how it's solved in Typst) https://www.youtube.com/watch?v=yWWVhbyOWWE
It is not 3 compiles of the same code after another, but e.g. latex, bibtex, latex, with each step creating part of the final output. I imagine latex like part of multi-pass compiler, so calling latex once is like running only one stage of the compiler. Latexmk (https://www.ctan.org/pkg/latexmk) solves this problem more elegantly by knowing how often each tool and in what order is required.
In latex, I have to compile once so that it can find out the references it needs, then bibtex so that it extracts the actual references, compile a second time to get the references into the paper and then a third time because a ton of things shift around and now it knows all the figure/page numbers etc.
There are Latex documents whose output keeps changing no matter how many times you run Latex on them: https://tex.stackexchange.com/questions/30674/document-requi...