Multimarkdown to PDF
As I currently write my diploma thesis, there is this need to do other things than writing the actual thesis. This and the fact that I really like the idea of markdown resulted in writing my thesis in markdown. Actually I write it in multimarkdown, an extension of it. As the name implies markdown is something contrary to markup in that is deemphasizes the markdown. All mardown files are actually plain text files. But they have a markup which makes plain sense. But as there is a definition behind your writing style you can convert that plain text in a number of markup languages, including html and latex. Some generators even support the open document format or rtf.
So what I do is the following:
- writing in a number of markdown files,
- putting them together to one large markdown file,
- convert that into a latex file,
- include that into my main latex file
- and mklatex the hell out of that one.
How that works out? Pretty well so far, I have to say. Sometimes I have to use standard latex, which you can embed in your document. I always have the option to go back to writing standard latex if I want to by running my files through the converter so I get my normal latex files.
So if you want to do the same, here is the code that I use. Stuff it into a .sh file in your main directory. This is my file structure:
- content.md (contains a list all the .md-files for sorting)
- your other .md files
Keep in mind that this is on a Mac, so on other unix systems you might have to adopt your code a little bit. For windows … well you can get the idea :)
#!/bin/sh # this script takes everything that is in content-markdown and turns it into one pdf file. # it also stops everytime it encouters an error in any of the steps. # make sure we start in this directory (needed for running it from finder) cd "`dirname "$0"`" # multimarkdown source, concatenate files given in content.md cd content/ perl ~/Library/Application\ Support/MultiMarkdown/Utilities/mmd_merge.pl content.md > ../main-document-content.md rc=$? if [[ $rc != 0 ]] ; then echo "mmd_merge.pl exited with status code $rc" exit $rc fi cd ../ # generate latex code from that one markdown file. this uses multimarkdown multimarkdown -t latex -o "main-document-content.tex" "main-document-content.md" rc=$? if [[ $rc != 0 ]] ; then echo "multimarkdown compilation exited with status code $rc" exit $rc else echo "multimarkdown compilation done!" fi # change all \autoref commands to vref. This makes the references use pagenumbers as well (i.e. section 2.1 on page 4) sed -ie 's/\\autoref/\\vref/g' "main-document-content.tex" # compile pdf from latex source: # we need bibtex and pdf output option + use xelatex instead of pdflatex (so we get nice otf & aat support) latexmk -bibtex -pdf main-document -e '$pdflatex=q/xelatex %O %S/' rc=$? if [[ $rc != 0 ]] ; then echo "latexmk run #1 exited with status code $rc" exit $rc fi # remove temporary files latexmk -c main-document # open file in preview.app open main-document.pdf exit 0