Writing maths and citations in markdown.
This is a dirty, cheap and easy way to maintain docs including equations and sources in Markdown or a Jupyter notebook and export to HTML (opens in a new tab) or PDF (opens in a new tab). You may choose not to use LaTeX at all.
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. The \tag{1} adds a manually assigned equation number.
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. Add a short sources line for supporting references. For example:
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. Local PDFs can also be linked using paths relative to the Markdown file.
Option B: Zotero bibliography
A citation key is a label for a source. Here, einstein1905 connects the citation in your document to the paper in references.bib.
- Install Zotero and its browser Connector, then 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: Export Collection > Better BibLaTeX > Keep updated. Save as
references.bibbeside your document. - Insert the matching citation key in your text:
In his 1905 paper, Einstein connected the random motion of particlessuspended in a liquid to molecular motion [@einstein1905].- Add this at the end of the document. Pandoc will place the reference list here:
## References
::: {#refs}:::Keep Zotero running for automatic updates. Edit records in Zotero, rather than its exported file. A .bib file is citation data; it does not require LaTeX.
You can mix both citation methods. Use Option B’s export command when the document contains bibliography citations.
4. Export to HTML
Save your document. In the terminal, run the matching command from your document 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 create model.html beside your document. --mathjax enables equation rendering; Option B also uses --citeproc to turn citation keys into formatted citations.
5. 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 exports, use one of these methods. 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 without LaTeX, install Typst, then run:
pandoc model.md --pdf-engine=typst --citeproc --bibliography=references.bib -o model.pdfThis exports the equations and citations, but drops the manual \tag{1} number in this example. Use LaTeX or export from HTML to keep it.
From HTML with a script
You can also export from HTML without LaTeX. Install Python and run these once:
python -m pip install playwrightpython -m playwright install chromiumSave html_to_pdf.py beside your document, then run:
python html_to_pdf.py model.html model.pdfOn macOS or Linux, use python3 if python is not available. The script waits for MathJax to render the equations, then creates the PDF.
Open model.pdf and check the equations and references. After editing your document, repeat the export commands.
Optional citation tools and labels
You can also use the Zotero extension by mblode in your editor when working with Zotero citations.
To display an @ in the label, escape it:
[\@einstein1905](https://doi.org/10.1002/andp.19053220806)Using a Jupyter notebook
Install Microsoft’s Python and Jupyter extensions in VS Code, and write the document in Markdown cells. In the Pandoc commands above, replace model.md with:
model.ipynb --from=ipynb+citations+fenced_divsFootnotes
-
The HTML needs internet access to load MathJax. ↩