[fastpages] [SOLVED] How to include footnotes in Jupyter Notebooks

I had these docs hidden for a while, they were in the repo but I forgot to put them in the README. This is a follow up to @ducha-aiki’s questions about footnotes in Jupyter Notebooks in fastpages.

These are the instructions from https://github.com/fastai/fastpages/blob/master/_fastpages_docs/NOTEBOOK_FOOTNOTES.md

Blockquote

Detailed Guide To Footnotes in Notebooks

Notebook -> HTML Footnotes don’t work the same as Markdown. There isn’t a good solution, so made these Jekyll plugins as a workaround

This adds a linked superscript {% fn 15 %}

{{ "This is the actual footnote" | fndetail: 15 }}

You can have links, but then you have to use single quotes to escape the link.

This adds a linked superscript {% fn 20 %}

{{ 'This is the actual footnote with a [link](www.github.com) as well!'  | fndetail: 20 }}

However, what if you want a single quote in your footnote? There is not an easy way to escape that. Fortunately, you can use the special HTML character ' (you must keep the semicolon!). For example, you can include a single quote like this:

This adds a linked superscript {% fn 20 %}

{{ 'This is the actual footnote; with a [link](www.github.com) as well! and a single quote ' too!'  | fndetail: 20 }}

4 Likes

This is not a big issue, but I am not able to include footnotes inside a box such as

>Note: A footnote {% fn 15 %} {{ "This is the actual footnote" | fndetail: 15 }} is inserted in this box.

Specifically, when I run make server locally, I get

jekyll_1     |   Liquid Exception: Invalid syntax for include tag: content='A footnote {% fn 15 Valid syntax: {% include file.ext param='value' param2='value' %} in /data/_posts/2020-05-27-footnotes-in-boxes.md
jekyll_1     | /usr/local/bundle/ruby/2.6.0/gems/jekyll-4.0.0/lib/jekyll/tags/include.rb:73:in `validate_params': Invalid syntax for include tag: (ArgumentError)
jekyll_1     | 
jekyll_1     | content='A footnote {% fn 15
jekyll_1     | 
jekyll_1     | Valid syntax:
jekyll_1     | 
jekyll_1     | {% include file.ext param='value' param2='value' %}

The entire sample notebook:

{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# \"footnotes in boxes\"\n",
    "> \"Errors are thrown when inserting a footnote inside a box\"\n",
    "\n",
    "- toc: true \n",
    "- badges: true\n",
    "- comments: true\n",
    "- categories: [test]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Typing `>Note: this box is plain.` will render this."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">Note: this box is plain."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But typing `>Note: A footnote {% fn 15 %} {{ \"This is the actual footnote\" | fndetail: 15 }} is inserted in this box.` will throw an error when running `make server` locally."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">Note: A footnote {% fn 15 %} {{ \"This is the actual footnote\" | fndetail: 15 }} is inserted in this box."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
1 Like

Can you try the footnote outside the codeblock? > to see what happens

Yes it works to place the footnote outside of the > code block (but in the same cell), e.g.

> Note: I want a footnote but it doesn't seem to work inside this box.

This adds a linked superscript {% fn 15 %}

{{ "This is the actual footnote" | fndetail: 15 }}

On the other hand, footnotes in jupyter notebooks end up at the bottom of the cell, typically only a few lines lower, so this is probably not a big use case (unless the notebook is one, long cell, and then there is no point in using a jupyter notebook in the first place).

EDIT: I hadn’t realised that the footnote appears where it is placed, and not automatically at the bottom of the post.

I thought it would nevertheless be useful to flag this behaviour, others might encounter it.

Yes you can put the footnote wherever you want