Markdown to PDF

Requirement

get Pandoc and friends,

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

https://tex.stackexchange.com/questions/816/cyrillic-in-latex

PDF Documents

The inline way

pandoc --latex-engine=xelatex -V geometry:margin=1in -V papersize:a4paper \
    -f markdown+pandoc_title_block \
    -V lang=english,russian -V mainfont="FreeSerif" \
    --listings $1 -o ${1%\.md}.pdf && echo done

The preamble way

vi ~/preamble.tex

\usepackage[T1,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,russian]{babel}
\usepackage[labelformat=empty]{caption}

pandoc --latex-engine=xelatex -V geometry:margin=1in -V papersize:a4paper \
--listings -H ~/preamble.tex $1 -o ${1%\.md}.pdf && echo done

https://tex.stackexchange.com/questions/21795/how-to-remove-figure-label

PDF Slides

Preamble mandatory here

vi ~/preamble.slides.tex

\setbeamercolor{normal text}{fg=white,bg=black!90}
\setbeamercolor*{structure}{fg=blue!33!white}
\setbeamercolor{alerted text}{use=structure,fg=structure.fg}
\setbeamercolor*{palette primary}{use=structure,fg=structure.fg}
\setbeamercolor*{palette secondary}{use=structure,fg=structure.fg!95!black}
\setbeamercolor*{palette tertiary}{use=structure,fg=structure.fg!90!black}
\setbeamercolor*{palette quaternary}{use=structure,fg=structure.fg!95!black,bg=black!80}
\setbeamercolor*{framesubtitle}{fg=white}

\usepackage[T1,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,russian]{babel}
\usepackage[labelformat=empty]{caption}

pandoc --latex-engine=xelatex -V geometry:margin=1in -t beamer \
        --listings -H ~/preamble.slides.tex \
        -V lang=english,russian -V mainfont="FreeSerif" \
        $1 -o ${1%\.md}.slides.pdf && echo done

More Options

cyrillic,

-V lang -V babel-lang=russian

index,

#--toc 
#--toc --slide-level=3

misc,

#-f markdown+fancy_lists
#-t context

Fancy Code Blocks

vi preamble.tex

\usepackage{xcolor}
\usepackage{listings}

\lstset{
    basicstyle=\ttfamily,
    numbers=left,
    keywordstyle=\color[rgb]{0.13,0.29,0.53}\bfseries,
    stringstyle=\color[rgb]{0.31,0.60,0.02},
    commentstyle=\color[rgb]{0.56,0.35,0.01}\itshape,
    numberstyle=\footnotesize,
    stepnumber=0,
    numbersep=5pt,
    backgroundcolor=\color[RGB]{248,248,248},
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2,
    captionpos=b,
    breaklines=true,
    breakatwhitespace=true,
    breakautoindent=true,
    escapeinside={\%*}{*)},
    linewidth=\textwidth,
    basewidth=0.5em,
}

and you need to add either the listings package manually in the preamble or with --listings

https://tex.stackexchange.com/questions/323329/pandoc-code-blocks-in-markdown-with-very-long-lines-get-cut-off-when-outputting https://tex.stackexchange.com/questions/179926/pandoc-markdown-to-pdf-without-cutting-off-code-block-lines-that-are-too-long/412316#412316

Fancy inline-code

TODO

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.

https://texfaq.org/FAQ-divzero https://tex.stackexchange.com/questions/159948/pandoc-generated-pdf-contains-large-images-how-can-i-make-them-fit-into-the-pag

Resources

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

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

pdflatex and some fonts https://gist.github.com/rain1024/98dd5e2c6c8c28f9ea9d

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/


Nethence | Pub | Lab | Pbraun | SNE Russia | xhtml