I am trying to convert my document from Markdown to PDF using Pandoc. At the beginning of my Markdown file, I have included an YAML header. Every parameters seems to be processed, except header-includes
.
The subject has already been addressed here : Adding headers and footers using Pandoc
I can't make it work the way it is explained on this post (or some other posts I have seen on internet, though, or even after reading Pandoc's documentation ).
I don't see what I did wrong.
Setup:
- Mac OS 10.11
- Texlive 2015
- Pandoc 1.15
Beginning of markdown file:
---
title: Anonymise agents datas on MySQL for EQualOne
author: Adrien Desprez
abstract: This script is able to anonymise agents datas stored in MySQL portal.
date: July 14th 2016
geometry: margin=2cm
numbersections: yes
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy}
- \fancyfoot[CO,CE]{So is this}
- \fancyfoot[LE,RO]{\thepage}
---
# Prerequisites
* Linux distribution; tested on CentOS 6.7 and Fedora 23
* Python 2.6 or 2.7
* Python modules: yaml, MySQLdb
On the default latex template I can see that header-includes
parameter should be processed:
adrien@datmachine ☻ pandoc -D latex|grep -C 2 "header-includes"
$endif$
\date{$date$}
$for(header-includes)$
$header-includes$
$endfor$
Then I run the following pandoc
command:
pandoc -f markdown -t latex --standalone --listings -H ~/Documents/listings-setup.tex -o ~/Documents/readme.pdf ~/git/pro/exploit/scripts/offline/data/anonymise_agents_datas/README.md
The PDF does not contains any header or footer.
If I run in verbose mode and inspect the TeX file produced, there is no mention of usepackage{fancyhdr}
on ~/Documents/readme.tex
:
pandoc --verbose -f markdown -t latex --standalone --listings -H ~/Documents/listings-setup.tex -o ~/Documents/readme.tex ~/git/pro/exploit/scripts/offline/data/anonymise_agents_datas/README.md > output.log
The output.log
file does not include any useful information for that matter.
What surprise me, is that pandoc
process correctly every parameters I give him on the YAML header but the one called header-includes
, despite the fact that this parameter is present on the latex default template.
What I am missing ?
Best Answer
I finally need to create a latex custom template. I have other customization needs that can be filled easily with the a custom template.
So, in order to create a latex custom template:
Then, edit
custom-template.tex
file.To add headers with a condition, you can do this:
On the header of your Markdown file:
Then, generate your PDF using your latex custom template:
You can go further and report the content of the headers using the latex parameters and YAML meta-data.
In your Markdown file:
I have not tested this last possibility, though. May be you have to protect the string passed from the Markdown's YAML header to LaTeX. To be tested.