Converting markdown to pdf with pandoc

About

With the linux commandline tool pandoc you can easily generate a nice looking PDF file from any other format you want.
I personally write my notes in markdown, but converting them is always a pain if someone needs them. With pandoc you can easily convert any markdown file to pdf in mere seconds from your commandline.

Installation

For windows users there exists a .msi installer on https://pandoc.org/installing.html.
For linux users you can run the following commands:

sudo apt-get install texlive-xetex fonts-liberation
wget https://github.com/jgm/pandoc/releases/download/2.16.2/pandoc-2.16.2-1-amd64.deb
sudo dpkg -i pandoc-2.16.2-1-amd64.deb
texlive-xetex is a pdf engine that makes amazing .pdf files.
fonts-liberation contains windows-like fonts which are remade and open source.
Installing by binary from github makes it always up to date because the debian repo version is .14 versions behind and has many problems that are long fixed.
Now you can run it with the pandoc example commands below.

Converting

Converting files is really easy.

pandoc workshopdoku.md -o workshop.html
The above command converts a markdown file called docs.md, which is simply a text file, to a html site called docs.html.

To convert to pdf i recommend using the xetex pdf engine:
pandoc workshopdoku.txt --pdf-engine=xelatex -o workshop.pdf
This converts a text file (which contains markdown text) to a beautiful pdf.
For more files that can be converted visit their github: https://github.com/jgm/pandoc.
There are many more tips and settings which can all be found in the https://pandoc.org/MANUAL.html.

Example md to pdf

The example file, which is the source of this convertion, can be downloaded here.
To convert it the following command is used:

pandoc pandoc_md.txt --pdf-engine=xelatex -o pandoc_pdf.pdf
The pdf that was created can be found here.
If your browser supports loading PDFs via iframe tags it can also be viewed here:

Explaining the example input file

This is the full input file. Every // after a line means it's a comment about what this line does.

---
title: Example Pandoc Document
author: Me, Myself and I
date: 10.11.2021
toc: true   // If a "Table of content" should be generated
numbersections: true // If the headings should be numbered, e.g. "1.2 Header"
geometry: margin=3cm // The gap between text and paper-edge
urlcolor: blue
mainfont: LiberationSans
header-includes: |
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \lfoot{Generated with pandoc} // Left foot note
    \rfoot{Seite \thepage} // Right foot note
---

\newpage // Makes the text after this appear on a new page
// The Heading above will generate a "Table of Content"
// This newpage sperates content from table of content


# Header 1

## Header 2

This is content. Now an image:

![Utage from Arknights](test.png "test.png image at 50% width"){ width=50% }



The next Heading will be on the next page because i write a \\newpage after this sentence.

\newpage

# Header 3
You can do all things markdown provides, like _italic_ and **bold** and code with 4 spaces

    echo "Hello World"
    Hello World

Now comes a "list of figures" with \\listoffigures:

\listoffigures

Generate presentations with pandoc

With pandoc you can also generate powerpoint-like web presentations from a text file.
There are multiple designs, the commands are:

pandoc -s --mathml -i -t dzslides SLIDES -o example16a.html

pandoc -s --webtex -i -t slidy SLIDES -o example16b.html

pandoc -s --mathjax -i -t revealjs SLIDES -o example16d.html
You can also make them "self-contained" by adding a --self-contained before the -s. This makes the .html output file +3MB in size but it can be used offline as all the CSS and JS files are inside this one file.

An example for the last "mathjax and revealjs" one:
The input file can be found here or below:
---
title: Example
--background-image: https://img3.gelbooru.com/images/7b/fe/7bfed13e0c310bc5fb1de167ffe564bc.jpg
title-slide-attributes:
    data-background-image: https://img3.gelbooru.com/images/70/53/7053e91ecc3930e12131300b42d2ae64.jpg
    data-background-size: contain
---

# Slide One

- Press s to open the presenter view in a popup window
- There will be notes there if you are on this slide

::: notes

This is my note.

- It can contain Markdown
- like this list

:::

# Slide Two

Pandoc is:

- Easy to generate
- Can run in every browser
- No lag or delay

# Slide Three

Now a table:

:::::::::::::: {.columns}
::: {.column width="40%"}
Money  
Time
:::
::: {.column width="60%"}
Not much  
Even less
:::
::::::::::::::

# Conclusion

Pandoc is awesome!

. . .

Thanks for listening! 

The command used was:
pandoc -s --mathjax -i -t revealjs pandoc_slides.txt -o pandoc_slides.html
The output presentation that was created can be found here.
If your browser supports iframe tags it can also be viewed here: