# No paragraph in datatool's DTLforeach possible when using a textblock from textpos

I'd like to print labels using the datatool and the textpos packages.

Yet as soon as I insert a paragraph inside the textbox which is inside the \DTLforeach loop, I get the "Paragraph ended before \DTLifnumeq was complete." error message.

The following example compiles without error:

File testdb.csv:

field1,field2,field3
row11,row12,row13
row21,row22,row23


File example01.tex:

\documentclass[11pt,a4paper]{article}
\usepackage[absolute]{textpos}
\usepackage{datatool}

\begin{document}
\DTLifnumeq{\DTLcurrentindex}{1}{%
\begin{textblock}{3}(1,1)
more text.
\end{textblock}%
}{}%
}
\end{document}


After inserting a paragraph after the \addFieldi command, the example (called example02.tex) does not compile anymore:

File example02.tex:

\documentclass[11pt,a4paper]{article}
\usepackage[absolute]{textpos}
\usepackage{datatool}

\begin{document}
\DTLifnumeq{\DTLcurrentindex}{1}{%
\begin{textblock}{3}(1,1)

more text.
\end{textblock}%
}{}%
}
\end{document}


I couldn't find a solution on how to circumvent the error.

Thanks a lot for your help!

-
Use \\ to terminate a line, or \endgraf; no empty lines. – egreg Jun 19 '12 at 10:18
I'd like to use floating text from another file inside the textblocks. I would have to replace all newlines with the \endgraf command. Is there another solution without the need for inserting the \endgraf commands? – Frank Jun 19 '12 at 10:52

The problem is that the macro \DTLifnumeq doesn't accept \par (or empty lines) in its arguments. In TeXnical terms, it is not \long. You can modify it adapting the trick I used in this answer of mine:

\usepackage{datatool}

\begingroup
\toks0=\expandafter{\DTLifnumeq{#1}{#2}{#3}{#4}}
\edef\x{\endgroup
\long\def\noexpand\DTLifnumeq##1##2##3##4{\the\toks0 }}\x


Now your macros will be happy with \par and empty lines.
We store in \toks0 the first level expansion of \DTLifnumeq and redefine it as a \long macro with the same number of parameters and the same replacement text as the original.