Search code examples
ryamlquarto

How to add footnote in the YAML block of a Quarto document?


I am trying to add a footnote to affiliation in the YAML block, but got a mixed result:

Output

  1. It successfully shows the footnote in both the behavior and format.
  2. But in the Footnote section below, it shows 3 repetitive footnotes, rather than one unique note.
    (I have tested with different words and combinations, they always result in 3 footnotes, so the length of text should not be the reason caused this)
  3. In addition, it starts from 3, instead of 1.

I am just wondering how to display the footnote correctly?

Here is my full YAML block:

---
title: "How to add footnote in the YAML block?"
subtitle: "A Quesiton for Stackoverflow<br>"
date: today
published-title: "LAST UPDATED"
affiliation-title: "TEAMS"

author:
  - name: "Yang Hu"
    affiliation: 
        name: \- ^[Retired]

execute: 
  freeze: auto

toc: true
toc-title: "Contents"
toc-location: "left"
toc-depth: 4

format:
  html:
    embed-resources: true
    self-contained: true
    smooth-scroll: true
    link-external-newwindow: true
    code-overflow: scroll
    code-fold: show
    code-line-numbers: true
    code-tools: true
    grid:
      sidebar-width: 268px
      body-width: 800px
      margin-width: 320px
      
number-sections: false
code-annotations: hover
reference-location: document
---

Solution

  • I can reproduce the issue on my end. The minimal YAML header to reproduce seems to be:

    ---
    title: "How to add a footnote in the YAML block?"
    subtitle: "A Question for Stackoverflow"
    author: "Yang Hu ^[Retired]"
    format: html
    ---
    

    After changing the format to native we can see that pandoc renders the author information and the footnote three times in the meta data, for author, authors and author-by.

    We can write a little pandoc filter in Lua that removes the first two notes and only accepts the third note and notes after that.

    fix_meta_notes.lua:

    notes = 0
    
    return {
      {
        Note = function (el)
          notes = notes + 1
          if notes >= 3 then
            return el
          else
            return ""
          end
        end,
      }
    }
    

    And this is what the YAML header with another note in the body would look like.

    
    ---
    title: "How to add footnote in the YAML block?"
    subtitle: "A Quesiton for Stackoverflow"
    author: "Yang Hu ^[Retired]"
    format:
      html: 
        filters: 
          - fix_meta_notes.lua
    ---
    
    Something ^[Another Note]