title | author | type | created | modified | output | sup | state | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Obsidian Pandoc |
zcysxy |
tool |
2023-07-20 08:47:11 -0700 |
2023-10-30 22:14:24 -0700 |
|
|
done |
Note
- This workflow focuses on
markdown -> latex -> pdf
. There are many great plugins for other pipelines, such as Obsidian Webpage Export. - Basic knowledge of pandoc, YAML, etc., is assumed.
Imagine your professor gives you a LaTeX template and asks you to scribe a lecture note,1 while you have already taken the note in Obsidian with handy features like callouts and block links, and even advanced plugins like Pseudocode and TikZ. Spend another year to type it again or do some tedious manual conversion? 😩 Never! With one command within Obsidian and you are ready to submit! 🥳
- A workflow that helps you seamlessly convert your Obsidian notes to camera-ready PDFs
- Pandoc filters that transform Obsidian Markdown for pandoc conversion
callout.lua
transforms Obsidian callouts into LaTeX environments and color boxes with labeling supportlink.lua
transforms wikilinks into LaTeX references, supporting heading links and block links with aliascodeblock.lua
parses codeblocks for plugins, including TikZ and Pseudocodeimage.lua
parses image captions and attributes, supporting Obsidian image aliasshift_headings.lua
shifts heading levels to avoid duplicate H1 titles, supporting customizable shift levelsdiv.lua
transforms custom pandoc divspreamble.lua
loads your reusable preamble file, e.g.,preamble.sty
for obsidian-latex
- A defaults file that configures all the pandoc options and meta variables
- ❗ Please substitute the placeholders in the defaults file with your own configurations
- Some templates that control the look of the generated PDF
- Other filters
cross-ref
: Pandoc filter for cross-referencesmermaid-filter
: Pandoc filter for Mermaid diagrams
- Pandoc wrappers
- Obisidian plugin
- Install pandoc and recommended programs that suit your needs.
- Copy the three folders
filters
,templates
, anddefaults
to the directory you choose, e.g.,obsidian_vault/config/pandoc/
. - Customize the
defaults/pdf.yaml
file to configure your pandoc options and replace the placeholders.
When you compose the note, it is a good practice to keep the syntax simple and compatible with pandoc and other Markdown programs. Add meta variables in the frontmatter (properties) that you want pandoc and your template to pick up, e.g.,
---
title: Obsidian Pandoc
author: zcysxy
uni: Obsidian University # this is a variable specified in templates/scribe.tex
---
Now, you are ready to generate the PDF outside Obsidian, by running the following shell command
pandoc --defaults obsidian_vault/config/pandoc/defaults/pdf.yaml note.md
There are many plugins that can help you run shell commands within Obsidian, e.g., obsidian-shellcommands My obsidian-shellcommands command looks like this:
Under the current setup, to change a template, you can either change the template
configuration in the defaults file or modify the shell command, adding the option --template
.
Both methods are not ideal and break the automation.
What if we can specify the template in the frontmatter?
However, this is a limitation of the vanilla pandoc (Issue#4627).
In the issue, several programs are mentioned to solve this problem, e.g., my fork of panrun. 3
With panrun, we can specify the pandoc arguments like template
in the frontmatter:
---
output:
pdf_document:
pandoc_args:
defaults: pdf
template: scribe.tex
---
And the shell command becomes
panrun note.md --data-dir obsidian_vault/config/pandoc/
Therefore, the actual obsidian-shellcommands command I am using looks like this:
- Add more filters for
- beamer
- embeds
- literature note links as citations
- Obsidian comments
- Integrate with obsidian-pandoc-templates and obsidian-enhancing-export
- Directly read the
preamble.sty
file used by obsidian-latex
WIP
Footnotes
-
Here is a genuine compliment from my professor on my docs generated using this workflow. ↩
-
Interested in the note in the figure? Check out our new preprint Riemannian Adaptive Regularized Newton Methods with Hölder Continuous Hessians 🎉 ↩
-
This fork allows configurations in the frontmatter to override the defaults file, which is not supported in the original panrun. ↩