Markdown to PDF with Pandoc

Install

    apt install pandoc lmodern texlive-latex-base texlive-fonts-recommended pandoc-citeproc
    apt install texlive-xetex texlive-lang-cyrillic
    apt install texlive-plain-generic # ulem.py

# texlive-fonts-extra

Casual usage

note the --listings option does a little more than just adding the package to preamble. it actually enables \lstlisting and \lstinline on-the-fly…

Custom template

the default template

pandoc -D latex | less

if you wanted to use your own, it would go as follows

--standalone --template=$HOME/template.tex

Custom script

we’re rather interested in DIY. here are our scripts for converting Markdown to PDF documents and slides

https://pub.nethence.com/bin/pandocument.bash.txt

https://pub.nethence.com/bin/pandocslides.bash.txt

Tips & tricks

given some markdown input as follows

some title
http://some-link/

this regex makes the trick to happend the links after a carriage return on the resulting PDF

sed -r 's@^([^#h$-].+)@\1 \\@' links.md > linksfix.md
pandocument.bash linksfix.md

Acceptance

here’s a MWE with code blocks and inline code

pandocument.bash codeblock.md
    evince codeblock.pdf &

Troubleshooting

! Package graphics Error: Division by 0.

==> Latex needs headers. It does not matter whether the image is online or local. Its size does not matter either.

Graphics division by zero https://texfaq.org/FAQ-divzero

Pandoc-generated PDF contains large images, how can I make them fit into the page? https://tex.stackexchange.com/questions/159948/pandoc-generated-pdf-contains-large-images-how-can-i-make-them-fit-into-the-pag

[WARNING] Missing character: There is no я in font [lmroman10-regular]:mapping=tex-text;!

==> use an appropriate font as shown above.

Resources

https://pandoc.org/MANUAL.html

https://pandoc.org/scripting-1.11.html

Pandoc User’s Guide https://pandoc.org/MANUAL.html

Installing pandoc http://pandoc.org/installing.html

Index of /demo http://pandoc.org/demo/

Tutorial 17.3 - Markdown and Pandoc https://www.flutterbys.com.au/stats/tut/tut17.3.html

Academic Pandoc template https://maehr.github.io/academic-pandoc-template/markdown.html

Easy LaTeX with Markdown and Pandoc http://tech.lauritz.me/easy-latex-with-markdown-pandoc/

pandoc: Conversion between markup formats https://hackage.haskell.org/package/pandoc

enable citations https://gist.github.com/maxogden/97190db73ac19fc6c1d9beee1a6e4fc8

margins https://pandoc.org/faqs.html#how-do-i-change-the-margins-in-pdf-output

beamer https://andrewgoldstone.com/blog/2014/12/24/slides/ http://nval.andreasherten.de/2016/01/26/latex-beamer-with-markdown.html https://andrewgoldstone.com/blog/2014/12/24/slides/

alternative with Markdown -> HTML -> PDF https://github.com/cwjohan/markdown-to-html https://julien.ponge.org/blog/exporting-html-slides-in-markdown-to-pdf/

line breaks

Preserve line breaks in title using pandoc https://stackoverflow.com/questions/28283008/preserve-line-breaks-in-title-using-pandoc

Allow multiline Markdown headers #82 https://github.com/jgm/pandoc/issues/82

Multi line titles with pandoc https://tex.stackexchange.com/questions/502581/multi-line-titles-with-pandoc

Preserve line breaks in title using pandoc https://stackoverflow.com/questions/28283008/preserve-line-breaks-in-title-using-pandoc

Extension: escaped_line_breaks https://pandoc.org/MANUAL.html#extension-escaped_line_breaks

pandoc code blocks

Pandoc: code blocks in MarkDown with very long lines get cut off when outputting to PDF https://tex.stackexchange.com/questions/323329/pandoc-code-blocks-in-markdown-with-very-long-lines-get-cut-off-when-outputting

academia

Scientific Writing with Markdown https://jaantollander.com/post/scientific-writing-with-markdown/

Page Elements: Writing content with Markdown, LaTeX, and Shortcodes https://wowchemy.com/docs/content/writing-markdown-latex/

Markdown vs latex for thesis https://tex.stackexchange.com/questions/418962/markdown-vs-latex-for-thesis

pandoc passthrough

https://stackoverflow.com/questions/50854429/bookdown-undefined-control-sequence-recently-read-passthrough

https://github.com/jgm/pandoc/issues/4713

https://tex.stackexchange.com/questions/167594/why-shorthandon-and-shorthandoff-cannot-be-embedded-in-other-macros/167598#167598

https://tex.stackexchange.com/questions/557548/how-can-i-automatically-do-shorthandoff-in-all-inline-listings-with-pandoc

https://tex.stackexchange.com/questions/59960/passthrough-tex-input

https://mirror.szerverem.hu/ctan/macros/latex/required/babel/base/babel.pdf ==> shorthandon / shorthandoff

https://github.com/jgm/pandoc/issues/5696

pandoc hypertarget

https://stackoverflow.com/questions/52341046/remove-hypertarget-from-pandoc-latex-output

multimarkdown

Remove chapter and part text from LaTeX documents https://www.arj.no/2011/05/04/remove-chapter-and-part-text-from-latex-documents/

rubber

https://stackoverflow.com/questions/3232334/xetex-detect-when-re-run-is-needed

https://gitlab.com/latex-rubber/rubber/

font size

https://stackoverflow.com/questions/23811002/from-markdown-to-pdf-how-to-change-the-font-size-with-pandoc


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun