github twitter linkedin email
Markdown for flexible reporting

Transparency, multiple devices, multiple operating systems, paper/electronic,… when we write documents, we often need to adjust to different constrains.

This is the reason why I think that the dissociation between the information and the presentation of the said information is an important step that allows you on the long run to become more efficient. This is clearly has no immediate benefit, but on the long I really started to see the advantage.

I have started some time ago to use the combination of pandoc and its Markdown. You write your text in a regular text file, following extended Markdown syntax and then you use pandoc’s incredible power to convert it into : pdf, word, openoffice, html, … I found that using this strategy in combination with a proper library management system that can export to bib file format is rather efficient in my hands.

The major bottleneck for me has been to get the conversion and the templates right to automate the whole process and this what I am sharing below. Nothing fancy, just clean and efficient.

The global idea is to have your markdown document ( in a folder together with the style sheet for html (style.css), the xelatex template file (template.tex), your bibliography (doc.bib),… and then running the makefile or the batch file depending on your system.

It requires of course a full install of pandoc and LaTeX distribution that I won’t cover but multiple resources can be found on the web.

Makefile (for *nix)

PANDOC = pandoc
%.html: style.css Makefile
    $(PANDOC) -c style.css -s -f markdown \
    -t html --standalone \
    --bibliography=doc.bib -o $@ $<
%.odt: Makefile
    $(PANDOC) --standalone -f markdown \
    -t odt --bibliography=doc.bib -o $@ $<
%.epub: Makefile
    $(PANDOC) -o $@ $<
%.pdf: Makefile
    $(PANDOC) --bibliography=doc.bib --latex-engine xelatex --template=template.tex \
    -V lang=english \
    -V mainfont='Ubuntu' \
    -V date='' \
    -V fontsize='11pt' \
    -o $@ $<
%.tex: Makefile
    $(PANDOC) --bibliography=doc.bib --latex-engine xelatex \
    -V lang=english \
    -V mainfont='Ubuntu' \
    -V date='' \
    -V fontsize='11pt' \
    -o $@ $<
all: doc.html doc.epub doc.odt doc.pdf
    rm -f *.{html,odt,epub,pdf,tex}

Makefiles.bat (for Windows)

pandoc -f markdown --bibliography=doc.bib --latex-engine=xelatex --template=templateMK.tex --toc -o doc.pdf

pandoc -f markdown --bibliography=doc.bib --latex-engine=xelatex --template=templateMK.tex --toc -o doc.tex

pandoc -f markdown --bibliography=doc.bib -V mainfont=Ubuntu -c style.css --toc -o doc.html

pandoc -f markdown --bibliography=doc.bib --toc -V mainfont=Ubuntu -t odt -o doc.odt

pandoc -f markdown --bibliography=doc.bib --toc -V mainfont=Ubuntu -t docx -o doc.docx

XeLatex template :

\usepackage{graphicx, float, array, fancybox, tikz} % For images, tables & floats
\usepackage{amsmath, amssymb} % For math
\usepackage{verbatim, color, xcolor, wasysym}
\usepackage{lastpage, booktabs}
%\usepackage[pdftitle={TEST}, pdfauthor={That is You}, pdfkeywords={}, unicode, pdfencoding=auto]{hyperref}
%\hypersetup{colorlinks, citecolor=blue, filecolor=blue, linkcolor=black, urlcolor=blue}
\usepackage{pgfplotstable, makecell, colortbl}
% Fix for acrobat reader, cmyk and transparancy + XELATEX
\special{pdf: put @thispage <</Group << /S /Transparency /I true /CS /DeviceRGB>> >>}%

%framed mini box

%defining Pasteur official colors

% RGB 242 56 90
% RGB 245 165 3
%RGB 54 177 191
%darker blue
% RGB 74 217 217

{\normalfont\huge\bfseries\color{BlueP}}{\chaptertitlename\ \thechapter}{20pt}{\Huge}


\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\else % if luatex or xelatex
    \setmainfont{Times New Roman}
% use microtype if available
% Redefine \includegraphics so that, unless explicit options are
% given, the image width will not exceed the width of the page.
% Images get their normal width if they fit onto the page, but
% are scaled down if they would overflow the margins.
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
% Make links footnotes instead of hotlinks:
% avoid problems with \sout in headers with hyperref:
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\VerbatimFootnotes % allows verbatim text in footnotes

\author{$for(author)$$author$$sep$ \and $endfor$}








CSS template (style.css) :

** HTML elements
body {
  margin:0 auto;
  padding: 0;
  color: #000;
  background-color: #fff;
  font: 76% Verdana, Arial, Helvetica, sans-serif;
tr.dark td, tr.light td {
  padding: 0.3em;
h1, h2, h3, h4, h5, h6 {
  margin-bottom: 0.5em;
  color: #005D9C;
h1 {
  font-size: 1.3em;
h2 {
  font-size: 1.2em;
h3, h4, h5, h6 {
  font-size: 1.1em;
p {
  margin-top: 0.5em;
  margin-bottom: 0.9em;
a {
  text-decoration: none;
  font-weight: bold;
a:link {
  color: #005D9C;
a:visited {
  color: #005D9C;
a:hover {
  color: #005D9C;
  text-decoration: underline;

.title, .author {
  text-align: center;

table {

th {
  font-size: 13px;
  font-weight: bold;
  padding: 8px;
  border-bottom: 1px solid #fff;
  color: #005D9C;
td {
  padding: 8px; 
  border-bottom: 1px solid #fff;
  color: #000;
  border-top: 1px solid transparent;
tbody tr:hover td {
  color: #fff;
  background: #005D9C;

img {
  width: 70%;
  height: auto;