Skip to content

Expansion with Data

Fabian Wenzelmann edited this page Oct 9, 2018 · 1 revision

Adding data to a template can be achieved by providing a csv file that contains the data. First create the following template.tex:

\documentclass[a4paper]{scrartcl}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\title{Template File}

\begin{document}

\maketitle

Hello REPL-NAME,

this is a gummibaum template that creates dynamic content from a csv file.
%begin gummibaum repeat
Next token is REPL-TOKEN and next value is REPL-VALUE.\\
%end gummibaum repeat
\end{document}

The first thing we see is that new lines %begin gummibaum repeat and %end gummibaum repeat have been added to the template. These lines are mandatory and must contain the block that gets repeated for each column of the csv file. Only one such block is allowed. Then create a file data.csv:

token,value
A,21
B,42
C,84

Now we want to replace the occurrences of REPL-TOKEN and REPL-VALUE by the values from the csv files. The block will be evaluated several times. Of course we can still use constant values:

/gummibaum expand --file template.tex --row "REPL-TOKEN=token" --row "REPL-VALUE=value" --const "REPL-NAME=John" --csv data.csv

Again you can use --no-escape and --out.

Different Files

It is also possible to create a different file for each iteration, that is the head (everything before %begin gummibaum repeat) and the foot (everything after %end gummibaum repeat) are repeated with each iteration of the data and the result is written to a separate file. In this case --out must be set and must point to a directory:

./gummibaum expand --file template.tex --row "REPL-TOKEN=token" --row "REPL-VALUE=value" --const "REPL-NAME=John" --csv data.csv --single-file=false --out out/

--single-file=false is used to signal that separate files should be created. The directory out will now contain three files: out1.tex, out2.tex and out3.tex.

Clone this wiki locally