Appendices: best way to reference them (and reference each other)

Hello, I have the following layout of documents:

  • A main paper, which references several appendices.
  • Some of these appendices also refer to other appendices.
  • The main paper has its own bibliography, and so do some appendices.

What is the best way to refer to appendices from:

  • Within the main paper
  • Within another appendix

In the end for the final submitted paper I would still want a pdf that shows
main paper → appendix A → appendix B → …

I read about include, but that does not work in this case since I have multiple bibliographies. It also conflicts with the fact that appendix B refers to appendix A (this would mean if the main paper references both A and B, A is included twice (once original reference and once through B)).

What is the best way to approach this? Without too much manual referencing.
Are there any guides out there on how to do this properly?

I have implement this using a function and show rule. You can look at the code of bookly, elsearticle or elsepub templates available on Typst universe.

Here is how it is implemented:

// Appendix
#let appendix(body) = {
  set heading(numbering: "A.1.", supplement: [Appendix])
  // Reset heading counter
  counter(heading).update(0)

  // Equation numbering
  let numbering-eq = (..n) => {
    let h1 = counter(heading).get().first()
    numbering("(A.1a)", h1, ..n)
  }
  set math.equation(numbering: numbering-eq)

  // Figure and Table numbering
  let numbering-fig = n => {
    let h1 = counter(heading).get().first()
    numbering("A.1", h1, n)
  }
  show figure.where(kind: image): set figure(numbering: numbering-fig)
  show figure.where(kind: table): set figure(numbering: numbering-fig)

  isappendix.update(true)

  body
}