Footnotes & citations

Typst supports #footnote[...], @citation, and #bibliography(...) natively. In paged PDFs, footnotes settle at the bottom of each page; on the web, you choose between endnotes and margin sidenotes while keeping counters and bibliographies scoped per article.

Endnotes

Typst HTML export collects #footnote[...] at the end of a document with back-and-forth links. Across multiple #document(...) calls in one Bundle, reset the footnote counter at the start of each page so numbering does not carry over between articles:

typst
#document(page.output, format: "html", title: page.meta.title)[
  #counter(footnote).update(0)
  #html.main[
    #include page.file
  ]
]

If a custom #html.html shell needs footnotes placed strictly inside <article> (rather than after <footer>) or needs custom markup, collect them with query(selector(footnote).within(current-document().location)):

typst
#import "@tola/document:0.0.0": current-document

#let render-endnotes() = context {
  let doc = current-document().location
  let notes = query(selector(footnote).within(doc))
  if notes.len() == 0 { return }

  html.section(class: "footnotes", aria-label: "Footnotes")[
    #html.hr()
    #html.ol[
      #for (i, note) in notes.enumerate() {
        let num = str(i + 1)
        html.li(id: "fn-" + num)[
          #note.body
          #html.a(href: "#fnref-" + num, class: "fn-back", aria-label: "Back to content")[↩]
        ]
      }
    ]
  ]
}

Sidenotes

Blogs and research notes often float notes into the right margin on wide screens while collapsing them inline behind clickable numbers on narrow screens. Rewrite footnote under target() == "html" while leaving PDF output untouched:

typst
#let sidenote-counter = counter("sidenote")

#let reset-sidenotes() = sidenote-counter.update(0)

#let sidenote-rule(note) = context {
  if target() != "html" { return note }
  sidenote-counter.step()
  let n = sidenote-counter.get().first()
  let id = "sn-" + str(n)

  html.span(class: "sidenote-wrapper")[
    #html.elem("label", attrs: (for: id, class: "sidenote-number"), str(n))
    #html.elem("input", attrs: (type: "checkbox", id: id, class: "sidenote-toggle"))
    #html.span(class: "sidenote")[
      #html.span(class: "sidenote-prefix")[#n. ]
      #note.body
    ]
  ]
}
css
.sidenote-toggle { display: none; }

.sidenote-number {
  font-size: 0.75em;
  vertical-align: super;
  cursor: pointer;
  color: var(--accent);
}

/* Wide screens: float into right margin */
@media (min-width: 1120px) {
  .sidenote {
    float: right;
    clear: right;
    width: 16rem;
    margin-right: -18rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--muted);
  }
}

/* Narrow screens: collapsed by default, toggle on tap */
@media (max-width: 1119px) {
  .sidenote { display: none; }
  .sidenote-toggle:checked + .sidenote {
    display: block;
    margin: 0.5rem 0;
    padding: 0.6rem 0.85rem;
    border-left: 2px solid var(--border);
    font-size: 0.875rem;
  }
}

Authors write ordinary #footnote[...] in prose; PDF builds render bottom-of-page footnotes and HTML builds render margin sidenotes without JavaScript.

Bibliography

Typst reads BibTeX (.bib) and Hayagriva (.yml) files natively. Cite entries in prose with @key (or #cite(<key>)) and place #bibliography(...) inside the article:

typst
// content/posts/incremental-builds.typ
See @salsa2022 and @typst2023 for details on incremental evaluation.

#bibliography("/data/refs.bib", title: "References", style: "ieee")

Place #bibliography(...) per document rather than at site.typ top level so numbering stays scoped to each post. When attaching a shared bibliography from the post template, guard it so uncited posts omit an empty heading:

typst
#import "@tola/document:0.0.0": current-document

#let maybe-bibliography(bib-path, style: "ieee") = context {
  let doc = current-document().location
  if query(selector(cite).within(doc)).len() > 0 {
    bibliography(bib-path, title: "References", style: style)
  }
}

Because heading <label> tags and .bib keys share @... syntax, prefix bibliography keys (or use author-year keys) to avoid collisions with section labels.

Search this site

Use the arrow keys to move through results.

Type to search.