Skip to content

Instantly share code, notes, and snippets.

@keuv-grvl
Last active May 10, 2024 09:35
Show Gist options
  • Save keuv-grvl/12f386624061672637997790fc2d0472 to your computer and use it in GitHub Desktop.
Save keuv-grvl/12f386624061672637997790fc2d0472 to your computer and use it in GitHub Desktop.
Convert Markdown to PDF within Sublime Text using Pandoc
{
"cmd": ["pandoc --latex-engine=xelatex --filter=pandoc-citeproc -o '$file_base_name.pdf' '$file_name'"],
"selector": "text.html.markdown",
"shell": true
}
@keuv-grvl
Copy link
Author

keuv-grvl commented Apr 12, 2016

Requirements and features

  • pandoc, pandoc-citeproc and xelatex must be installed and accessible from your PATH
  • Excessive use of pandoc YAML metadata is recommended
  • Handle bibliography and UTF-8

Add to Sublime Text

  • Within Sublime Text: Tools > Build system > New build system...
  • Paste this gist
  • Save as pandoc.md2pdf.sublime-build

Usage

  • Within Sublime Text, Tools > Build (Ctrl+b) to compile a markdown file to PDF
  • Build your markdown, open the PDF with Evince, edit and re-build your markdown and Evince will automagically show the result!

Alternatives

@mariohuq
Copy link

mariohuq commented May 7, 2018

Doesn't work on my Windows machine

Outputs

'"pandoc -s -S -o 'pp.html' 'pp.md'"' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.1s]

@keuv-grvl
Copy link
Author

keuv-grvl commented Aug 23, 2018

@mariohuq I am not familiar with Windows command line, but I suppose that you have to add the pandoc executable to your PATH.

@codingforpleasure
Copy link

codingforpleasure commented Jun 13, 2020

I'm using pandoc version 1.19.2.4 , the updated snippet of @keuv-grvl should modify the argument name from --pdf-engine to --latex-engine.

@keuv-grvl
Copy link
Author

@codingforpleasure Updated! I don't use SublimeText anymore, let me know if this snippet fails.

@SpectralHiss
Copy link

I think also that the --filter=pandoc-citeproc bit is no longer required in my version of pandoc (2.15) it worked without it.
However, I needed to add lmodern latex sty package by simply doing sudo apt-get install lmodern

Thanks for the gist!

@yanisallouch
Copy link

I'm using pandoc version 1.19.2.4 , the updated snippet of @keuv-grvl should modify the argument name from --pdf-engine to --latex-engine.

As of today, the usage of latex-engine is no longer possible for pandoc v2.19.2 (windows tested) see my console output :

PS > pandoc --latex-engine=xelatex -o 'README.pdf' 'README.md'
--latex-engine has been removed.  Use --pdf-engine instead.
Try pandoc.exe --help for more information.
PS > pandoc -v
pandoc.exe 2.19.2
Compiled with pandoc-types 1.22.2.1, texmath 0.12.5.2, skylighting 0.13,
citeproc 0.8.0.1, ipynb 0.2, hslua 2.2.1
Scripting engine: Lua 5.4
User data directory: C:\Users\%USER%\AppData\Roaming\pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.7
PSEdition                      Core
GitCommitId                    7.2.7
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@promicrobial
Copy link

I'm using pandoc v2.9.2.1 on Linux Mint (21.3) and by changing --latex-engine=xelatex to --pdf-engine=pdflatex things were back in working order:

{
	"cmd": ["pandoc --pdf-engine=pdflatex --filter=pandoc-citeproc -o '$file_base_name.pdf' '$file_name'"],
	"selector": "text.html.markdown",
	"shell": true
}

There are several pdf engines you can use, including xelatex as used above: https://pandoc.org/MANUAL.html#option--pdf-engine

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