Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write conditional statements in a pandoc template based on variable values?

Tags:

pandoc

The default.beamer pandoc default template for LaTex beamer has this line:

$if(theme)$
\usetheme{$theme$}
$endif$

Does the test for a specific theme work as well? Something like:

$if(theme)$
   \usetheme{$theme$}
   $if(Berlin)$
     \setbeamertemplate{headline}
     {}
   $endif$
 $endif$

In the Pandoc - Pandoc User Guide, I've found this:

$if(variable)$
X
$else$
Y
$endif$

This will include X in the template if variable has a non-null value; otherwise it will include Y. X and Y are placeholders for any valid template text, and may include interpolated variables or other conditionals. The $else$ section may be omitted.

And more info on looping over variables with multiple values, however I can't seem to find information on how to test for a specific variable value - not true or false, but Darmstadt or Berlin in the specific example of a LaTex Beamer Theme.

Can this work somehow?

like image 231
tmaric Avatar asked Mar 10 '15 12:03

tmaric


Video Answer


2 Answers

You could simply use a LaTeX conditional like

\usepackage{ifthen}

$if(theme)$
   \usetheme{$theme$}
   \expandafter\ifstrequal\expandafter{$theme$}{Berlin}{%
   \setbeamertemplate{headline}}{%
   % if false
   }}%
$endif$
like image 164
Martin Schmelzer Avatar answered Oct 23 '22 12:10

Martin Schmelzer


Pandoc itself does not allow this out of the box.

There are two ways to solve this:

  1. Writing custom filter or looking for it. Pandoc filters have document serialized to JSON on both input and output. Having such a filter, you can mark sections using custom heading attributes.
  2. Preprocess Pandoc input using any preprocessor like mentioned here.

For me, second approach is preferred, because:

  • not everything in Pandoc can be annotated with custom attributes;
  • headings model is flat, e.g. heading is not an attribute of something like section, but only a place in the text.
like image 41
dluciv Avatar answered Oct 23 '22 11:10

dluciv