A simple setup for Sublime to jot down notes in Markdown and compile a nice PDF with LaTeX through Pandoc conversion.
Why? Markdown is quick and easy to write, LaTeX is more of a hassle. But LaTeX produces nice PDFs. Using Pandoc, you can utilize the best features of both worlds by writing in markdown and compiling PDFs with LaTeX, with a simple one-click in your editor. This works fairly well for simple documents and pandoc supports most of Markdown syntax, in addition to supporting a range of variables set in a YAML meta block. Did I mention that it also supports writing LaTeX-style math and other LaTeX-commands in your Document? (Like this:
The output PDF is a A4 paper with 12pt font and 1 inch margins. It uses fancyhead
to style the header and footer with date, pagenumbering and title/author. (This can be changed in your Pandoc-settings)
This is based on a Linux-system, but AFAIK all these utilities are available for Win/MacOS as well. It should also work for other editors if you can implement shortcuts for Pandoc-conversion and LaTeX-building.
You can see other versions (PDF, docx, html) of this guide here, to show how pandoc transoforms between different formats. Raw output from pandoc:
- http://folk.ntnu.no/matshes/random/pandoc-setup.pdf (using my template)
- http://folk.ntnu.no/matshes/random/pandoc-setup.docx (standard template - style and math rendering still ok!)
- http://folk.ntnu.no/matshes/random/pandoc-setup.html (standard template - bad math rendering, no css)
- Pandoc
- LaTeX
- Sublime Text with Package Control
- Pandoc plugin (install through Package Control)
- LaTeXTools plugin (install through Package Control)
- A decent PDF viewer (Okular, Evince, Skim (MacOS), Sumatra (Win))
- Template file (in this gist, scroll down)
-
After installing the requirements, add the file
pandoc-template.latex
to your preferred location. -
In Sublime, edit the user settings for Pandoc. Add this to your user settings for Pandoc in Sublime (
Pandoc.sublime-settings
):
{
"user": {
"pandoc-path": "/usr/bin/pandoc", // check path
"transformations": {
"PDF-custom": { // change this to custom name
"scope": {
"text.html": "html",
"text.html.markdown": "markdown"
},
"pandoc-arguments": [
"-t", "pdf",
"--template", "/path/to/pandoc-template.latex", // change path
"-V", "papersize:a4paper",
"-V", "fontsize:12pt",
"-V", "geometry:margin=1in",
"--latex-engine=/usr/bin/pdflatex",
"--filter", "/usr/bin/pandoc-citeproc",
]
},
},
}
}
You can now create a note in .md-format in Sublime like this.
- Example note:
---
header-title: Your title
header-author: Your name
---
# Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- Test 1
- Test 2
`$ user@host pandoc`
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- Open the Command Palette (Ctrl+Shift+P) in Sublime and enter Pandoc. Then enter the name of the transformation.
If you have configured LaTeXTools to automatically open PDFs upon build, the pdf-viewer of your choice will open with the compilated file.
- See example build: http://folk.ntnu.no/matshes/random/pdf-note-test.pdf
-
Since this is a markdown file, you can also use
pandoc
to convert it to other formats like HTML or docx. -
Check out pandocs manual: http://pandoc.org/MANUAL.html.
-
See the full supported Markdown syntax in pandoc: http://pandoc.org/MANUAL.html#pandocs-markdown
-
You can use many variables in the header for rendering LaTeX-documents! Check about other variables you can use: http://pandoc.org/MANUAL.html#variables-for-latex. My template is based on the standard one, so it support all of those. If you want to look around in the template, you can also find which
$variables$
you can include in your header.