Tuesday, 20 August 2013

Datatool and expansion issues

Datatool and expansion issues

I am having some problems when using datatool. Here is my minimal (not)
working example:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{datatool}
\def\one{Type 1: \itemtitle}
\def\two{Type 2: \itemtitle}
\def\three#1{Type 3: \itemtitle\ #1}
\begin{document}
\DTLloaddb{db}{test.csv}
\DTLforeach{db}{\itemtitle=Title,\itemtype=Type}{\itemtype\par}
\end{document}
This is my test.csv:
"Title","Type"
"Bla","\one"
"Blu","\two"
"Blag","\two"
"Bleg","\three{(test)}"
"Blog","Arbitrary Code: \itemtitle \textbf{(blah!)}"
As you can see I want to create a report from a database, but want to stay
fully flexible by allowing LaTeX code in the database. There will be very
generic cases (types 1 and 2), cases with parameters (case 3), and also
cases that don't fit in any predefined framework, that is why I want to
allow TeX code.
When I run the code, LaTeX complains about the definitions of \one, \two
and \three, because obviously \itemtitle only gets filled with the
relevant values much later.
I assume I have to tell LaTeX to expand these commands at the very end,
but I do not know how.
The mysterious thing is that this code (or rather the real world version
of it) has compiled without any issues before a computer re-install. Also,
the real world version shows more error messages now, that the minimal
example above; but maybe that will go away once this central problem is
solved. Also, when I choose to ignore all the error messages in the
command line compiler, the PDF actually produces what I want (for the
minimal example, not for the real world version).
Any help would be very much apreciated!

No comments:

Post a Comment