Writing maths and citations in markdown.
This is a dirty, cheap, and easy way to maintain notes with equations and sources in Markdown or a Jupyter notebook and export them to HTML (opens in a new tab) or PDF (opens in a new tab) without needing LaTeX.
1. Install the tools
Install VS Code and Pandoc.
2. Create your document model.md
# Model notes
For this example, $c(x,t)$ is concentration, $x$ is position,$t$ is time, and $D$ is a constant diffusion coefficient.
$$\frac{\partial c}{\partial t}= D\frac{\partial^2 c}{\partial x^2}.\tag{1}$$Use $...$ for inline math and $$...$$ for display equations. \tag{1} numbers the equation manually.
3. Choose a citation method
Use direct links if you want to write the source labels yourself. Use Zotero if you want Pandoc to generate the citations and reference list.
Option A: Direct links
Link the author’s name beside the claim and add a short sources line for supporting references:
In his 1905 paper, [Einstein](https://doi.org/10.1002/andp.19053220806)connected the random motion of particles suspended in a liquid to molecular motion.
Sources: [Einstein (1905), Brownian motion](https://doi.org/10.1002/andp.19053220806).This needs no Zotero or bibliography file. You can also link local PDFs using paths relative to the Markdown file. To display a literal @ in a link label, escape it as [\@einstein1905](https://doi.org/10.1002/andp.19053220806).
Option B: Zotero bibliography
A citation key is a short label for a source. Here, einstein1905 connects the citation in your document to the entry in references.bib.
- Install Zotero and its browser Connector, then install Better BibTeX through Zotero > Tools > Plugins > Install Plugin From File.
- Create a Zotero collection and save your papers or webpages into it. Check the imported authors, title, date, and URL.
- For this example, import DOI
10.1002/andp.19053220806and set its Citation Key toeinstein1905. Keep automatic key regeneration off. - Right-click the collection and choose Export Collection > Better BibLaTeX > Keep updated. Save it as
references.bibbeside your document. - Cite the key in your text:
In his 1905 paper, Einstein connected the random motion of particlessuspended in a liquid to molecular motion [@einstein1905].- Add this block at the end of the document where Pandoc should place the reference list:
## References
::: {#refs}:::Keep Zotero running so references.bib updates automatically, and edit records in Zotero rather than in the exported .bib file. You can also use the Zotero extension by mblode in VS Code to insert citation keys.
You can mix both citation methods in the same file. Use Option B’s export command whenever the document includes bibliography keys.
4. Export to HTML
Save your document and run the matching command from that folder.
Option A: Direct links
pandoc model.md --standalone --mathjax --metadata pagetitle="Model" -o model.htmlOption B: Bibliography citations
pandoc model.md --standalone --mathjax --citeproc --bibliography=references.bib --metadata link-citations=true --metadata pagetitle="Model" -o model.htmlBoth commands write model.html beside your document. --mathjax renders the equations, and --citeproc formats the citations from references.bib.
If you write in a Jupyter notebook instead of .md (with Microsoft’s Python and Jupyter extensions in VS Code), replace model.md in any Pandoc command with:
model.ipynb --from=ipynb+citations+fenced_divs5. Save as PDF
Open model.html from Step 4 in your browser, wait for the equations to render, and choose Print > Save as PDF.1
For command-line PDF exports, pick one of the three options below. In the LaTeX and Typst commands, omit --citeproc --bibliography=references.bib if you only use direct links.
With LaTeX
Install a LaTeX distribution, then run:
pandoc model.md --citeproc --bibliography=references.bib -o model.pdfWith Typst
To export directly from Markdown without LaTeX, install Typst and run:
pandoc model.md --pdf-engine=typst --citeproc --bibliography=references.bib -o model.pdfTypst renders the equations and citations, but drops the manual \tag{1} number in this example. Use LaTeX or the HTML script below to keep \tag{1}.
From HTML with a script
To export from model.html without LaTeX, install Python and run once:
python -m pip install playwrightpython -m playwright install chromiumSave html_to_pdf.py beside your document and run:
python html_to_pdf.py model.html model.pdfOn macOS or Linux, use python3 if python is not on your PATH. The script waits for MathJax to finish rendering before printing model.pdf.
Footnotes
-
The HTML file needs internet access to load MathJax. ↩