Skip to content

Instantly share code, notes, and snippets.

@ilessing
Last active April 26, 2024 22:15
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilessing/7ff705de0f594510e463146762cef779 to your computer and use it in GitHub Desktop.
Save ilessing/7ff705de0f594510e463146762cef779 to your computer and use it in GitHub Desktop.
getting pandoc to generate PDF from Markdown on MacOS

Using Pandoc to generate PDFs from Markdown

on a Mac running macOS 10.13.4

To install the needed components you can use Homebrew

Two Components are needed:

  1. Pandoc
  2. PDFLaTex

Install instructions:

Use Homebrew to install pandoc:

brew install pandoc

Then use Homebrew to install the PDFLaTex program.

brew install --cask basictex

You should now have all the needed components but it won't work until the pdflatex executable is available in your PATH environment variable. To configure this my technique is to sym link the executable to a directory already in my PATH.

ln -s -v /Library/TeX/texbin/pdflatex /usr/local/bin/pdflatex

Now if I enter which pdflatex on the command line the system responds:

/usr/local/bin/pdflatex

And now I'm able to generate a PDF from my Markdown file with this command:

pandoc file.md -s -o file.pdf

Pandoc will take your Markdown file, tranform it to TeX and then run it through the PDFLaTex program to output a PDF file.


  • Date: 2018-05-22

  • System info: MacBook Pro, macOS 10.13.4

Written with StackEdit

@cguethle
Copy link

cguethle commented Oct 7, 2021

Should this not be using the --cask arg instead?
Ex: brew install --cask basictex

@ilessing
Copy link
Author

thank you! @cguethle You're correct. I've updated the gist. I think the homebrew syntax changed since 2018

@andrezunido
Copy link

Thanks, works like a charm!

@marvingabler
Copy link

The generate command is leading to
marvingabler@MacBook-Pro-von-Marvin awesome-meteo % pandoc -s -o README.md awesome-meteo.pdf Unknown input format pdf Pandoc can convert to PDF, but not from PDF

while

pandoc -o out.pdf README.md

works like a charm

@allyouaskfor
Copy link

The generate command is leading to marvingabler@MacBook-Pro-von-Marvin awesome-meteo % pandoc -s -o README.md awesome-meteo.pdf Unknown input format pdf Pandoc can convert to PDF, but not from PDF

while

pandoc -o out.pdf README.md

works like a charm

You are getting that error because you placed your arguments before your input and output files rather than between your input and output as the example had shown. Pandoc will take the file directly after the -o argument as the output.

Example: pandoc INPUT.md -s -o OUTPUT.pdf
Yours: pandoc -s -o INPUT.md OUTPUT.pdf

@marvingabler
Copy link

Thanks, must have been tired 🤦

@michaelmcguire
Copy link

Slight update:

Since the instructions use brew and on Apple Silicon Macs, the default location has changed, I recommend linking to pdflatex with the following command instead to get it in the $PATH

ln -s -v /Library/TeX/texbin/pdflatex /opt/homebrew/bin/pdflatex

Trying to link into /usr/local/bin required sudo, at least on my machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment