# Workflow: automatically convert markdown to pdf (pandoc, latex, hazel)

Hi!

In 2016 some very great and helpful users in the MPU community (back then on google+) helped me to realize the following workflow, which I unfortunately am not able to reimplement on my new MacBook Pro (Catalina 10.15.2):

I write personal notes in markdown and have hazel watching the folder where I save them. Once hazel notices the hashtag #finished in the content of my markdown file it runs the following script on the file:


\end{document}


it worked on my old macbook, that is why i guess anything else is wrong… i somehow remember that at that time i had to change some bash file or something like that - might that be something i have to look for?

thank you!

Yes, that was me.

I could reproduce the error “./root.tex:160: LaTeX Error: Missing \begin{document}.”

Replace mytemplate.tex with this: https://www.dropbox.com/s/4x6fdyti7dktasc/mytemplate.tex?dl=0

This is now working on my Mac (Catalina, current MacTeX,…). If it works, let’s take it from there…if not…well dig into error logs.

Hi,

many thanks. It basically works (i haven’t tested in combination with hazel but i guess that should work once it works in terminal). At first i got following error:

kpathsea:make_tex: Invalid filename “Avenir”', contains '?'
kpathsea:make_tex: Invalid filename “Avenir”', contains '?'
Error producing PDF.
! Package fontspec Error: The font "“Avenir”" cannot be found.

For immediate help type H <return>.
...

l.20 \fi


Then I removed "–variable mainfont=“Avenir” from the command line and it worked. I have the font “Avenir” installed, so I don’t understand the error… is there anything else I have to add in the command Line for Avenir?

I have one remaining wish - is it possible to replace “Aktenvermerk” (in left HEADER) and “rexwex” (in left FOOTER) through two variables, which take content of the metadata of the markdown file - the same as the “date” (right HEADER) - therefore i start my markdown file with

 ---
date: MM.DD.YYYY
'---


'---
date: MM.TT.YYYY
case: CASEXY
author: rexwex
'---


how can this be handled?

THX!!!

You are welcome. Something weird happened when transferring the template file and some wonky stuff was in there (line breaks which shouldn’t be there). I just cleaned it, removed excessive line breaks and you are good to go.

As for your fontspec problem: “ and ” and ". Are not the same. Try this: “Avenir” and “Avenir” are not the same. Zoom in and see the subtle difference. You have a keyboard with german layout? Then edit the command and enter is properly: The " you want is Shift+2. It seems that whatever editor you used, replaced them with typographic (but useless) ones.

As for your special request: yes. But I am hungry now. Can you post a markdown file of a note you want to convert, so I can test it? Just fill it with blabla. I recall we created a md template but I have no idea what it looked like.

hi!

Of course you were right with your tipp regarding the fontspec problem - now it works.

THX.

here the file for my special request: https://www.dropbox.com/s/4izqqn29r3os77m/test.md?dl=0

MERCI

Like this? Page x of y is also fixed.

OMG, sensational … exactly what i am looking for … with one more space after the first number in the pagecount… i guess the footer and header look the same on all pages (apart from pagecount), which would be perfect.

would you be so kind and share the tex file with me and tell me how the metadata of the md file has to look like? how can i express my gratitude? would like to give you an amazon voucher or something similar? how is it possible to send direct messages on this board?

Everything (CLI command, tex template, sample md) is here: https://www.dropbox.com/sh/f554b0quj74gdtp/AADInKDz5hoTNcgnEQ8FAgCra?dl=0

I added a stripped-down and commented version (notiztemplate.tex), so you can easily take it from there and do some modifications. Command is simpler (is in command.txt), since I removed some options (just font is left).

It has less features, but I think enough for text notes (pdf is written, pdf meta data is pulled from md and written, full page count, custom headers/footers)

you are a genius! thank you very much, I am deeply thankful and somehow feel bad that I cant give you (at least a little bit) back. is there some option to send you a private message though this board?

THX

hmm… i now tried the new “shorter” file and got this error:


pandoc test.md --template=notiztemplate.tex --pdf-engine=xelatex --variable mainfont="Avenir" -o output.pdf

Error producing PDF.

! Undefined control sequence.

l.49 \tightlist
`

not big of a deal because the other one works anyway…just wanted to tell you…

Easy fix…done…

1 Like