DEV Community

Andrea Giacobino for Ape Unit

Posted on • Updated on

From HackMD to PDF

Full disclosure, I'm a big fan of Markdown, and also a big fan of HackMD (and it's community fork CodiMD).

Now imagine you have to write a technical assessment or specifications and you started writing it down on hackmd/codimd because, you know, reasons 😤. But then, for the sake of the argument, let's say that you have to produce a deliverable artifact that can be shipped to someone, like a customer; then a link to a online document might just not cut it 🤔.

So what to do? Alright, easy solution, fire up typora (or similar), paste the markdown, File > Export > PDF. The day is saved.

You go back skimming through the news and you find this: Writing a Book with Pandoc, Make, and Vim

Wait a second... what if... 🤯 vim Makefile

AU_HACKMD_CODE  = bfScafhcTdGzzhJ4B3evlQ
AU_FONT         = NeufileGrotesk
AU_FONT_DIR     = $(HOME)/.fonts/NeufileGrotesk
AU_OUTFILE      = $(HOME)/$(AU_HACKMD_CODE).MD.$(shell date +%F).pdf
AU_FORMAT       = article

    @echo format doc
    curl -s -L "$(AU_HACKMD_CODE)/download" -o /tmp/$(AU_HACKMD_CODE).md
    pandoc /tmp/$(AU_HACKMD_CODE).md -o $(AU_OUTFILE) \
  --table-of-contents \
  --pdf-engine=xelatex \
  --highlight-style=monochrome \
  --number-sections \
  -H $(HOME)/.config/apeunit/header-$(AU_FORMAT).tex \
  -V 'mainfont:$(AU_FONT)' \
  -V 'mainfontoptions:Extension=.otf, UprightFont=*-MediumExtended, BoldFont=*-BoldExtended, ItalicFont=*-MediumExtendedItalic, BoldItalicFont=*-BoldExtendedItalic, Path=$(AU_FONT_DIR)/' \
  -V 'fontsize: 12pt' \
  -V 'papersize: A4' \
  -V 'urlcolor: blue' \
  -V 'date: \today{}' \
  -V 'documentclass: $(AU_FORMAT)' \
  -V 'geometry:margin=3.8cm'
    xdg-open $(AU_OUTFILE)
    @echo done

Enter fullscreen mode Exit fullscreen mode
make hackmd2pdf HACKMD_CODE=bfScafhcTdGzzhJ4B3evlQ
Enter fullscreen mode Exit fullscreen mode


Now, I do understand that from a pure aesthetic point of view this might not be enough to satisfy the sensitive eye of the graphic designer, but it can be shipped!

Alt Text

  1. some dependencies need to be installed, on ubuntu texlive-xetex and pandoc 

  2. this command will not work for you, because it contains specific branding stuff from Ape Unit, but if you are looking for a simpler one, look no further

Top comments (0)