Search code examples
latexpandoc

Pandoc: Creating dynamic headers with Variables


In my preamble I use:

\usepackage[ngerman,english]{isodate}
\newcommand{\langMonth}{\month@ngerman}
$if(langDe)$
\renewcommand{\langMonth}{\month@ngerman}
$endif$
$if(langEn)$
\renewcommand{\langMonth}{\month@english}
$endif$

\usepackage{tikz}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[CO,CE]{\thepage}
%\setlength\headheight{100pt}

\rhead{\begin{tikzpicture}\node[above right, opacity=.5] { $if(Beschreibung)$$Beschreibung$$endif$ };  
\node[below right, opacity=.5]{\langMonth \, \the\year };
\end{tikzpicture}}

\lhead{\begin{tikzpicture}
\node[opacity=.5] {\includegraphics[width=0.25\textwidth]{images/Logo.png}};
\end{tikzpicture} }

With that I want basically two things: Write the month dependending on language, however with that, I get the LaTeX Error: Missing \begin{document}. The other thing I would like to have, is to set some description dynamically in the header, however the variable Beschreibung just gets ignored. I call pandoc by:

pandoc -o doc.pdf test.md --template mytemplate.latex --pdf-engine lualatex --verbose -V Beschreibung=dynamicDescription

Any suggestions? Thank you very much.


Solution

  • Instead of reinventing the wheel, you can use the babel and datetime2 package to automatically print the months in the language of your document.

    \documentclass[ngerman]{book}
    
    \usepackage{babel}
    \usepackage[calc]{datetime2}
    
    \usepackage{tikz}
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot[CO,CE]{\thepage}
    \setlength\headheight{100pt}
    
    \rhead{\begin{tikzpicture}
    \node[below right, opacity=.5]{\DTMmonthname{\the\month}
     \, \the\year };
    \end{tikzpicture}}
    
    \lhead{\begin{tikzpicture}
    \node[opacity=.5] {\includegraphics[width=0.25\textwidth]{example-image-duck}};
    \end{tikzpicture} }
    
    
    \begin{document}
    
    test
    
    \end{document}