Max Weylandt.

← Back

Drag and drop pandoc conversion using batch

03 January, 2023
the conversion process in action

I switched to writing in markdown a few months back and enjoy it so far — but pandoc conversion can be a bit of a pain. I could get better at remembering the syntax and quickly type out my typical command:

 pandoc draft.md --template eisvogel --mathjax --bibliography=path/to/my/lib.bib --citeproc --metadata link-citations=true --o draft.md

But I thought it would be nice to be able to do conversion quicker than that. 99% of the time I use the same template and citation style, so why not just have that at hand?

So here’s batch file that in windows 11 lets me drag a .md file onto it, and then creates pdf and .docx files with the same name:

 
echo The full path of the file is: %1
pause

:: Get information about the file
:: it's incredibly important to focus on details here
:: no spaces after the = sign because those spaces get introduced into the filename, causing errors
:: enclose in quotation marks so that the string is so enclosed and can be passed to pandoc
:: I'm leaving in some echos that I used for debugging

set file="%~nx1"
echo file is: %file%

set folder=%~dp1
echo the folder is: %folder%

set filename-noext=%~n1

echo running pandoc:

echo writing pdf ...
pandoc %file% --template eisvogel --mathjax --bibliography=C:/path/to/my/library.bib --citeproc --metadata link-citations=true --o "%filename-noext%.pdf"
echo writing docx ...


pandoc  %file% --mathjax --bibliography=C:/path/to/my/library.bib --citeproc --o  "%filename-noext%.docx"  --metadata link-citations=true

echo complete!
pause

This is helped greatly by the fact that I have one bibliography file that I use for everything. It contains my entire Zotero library and is auto-updated by Zotero.


← Back ↑ Top