Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\DTLloadrawdb{testdb}{testdb.csv}

\begin{document}
    \DTLforeach*{testdb}{\addFieldi=field1}{%
        \DTLifnumeq{\DTLcurrentindex}{1}{%
            \begin{textblock}{3}(1,1)
              \addFieldi
              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}
\DTLloadrawdb{testdb}{testdb.csv}

\begin{document}
    \DTLforeach*{testdb}{\addFieldi=field1}{%
        \DTLifnumeq{\DTLcurrentindex}{1}{%
            \begin{textblock}{3}(1,1)
              \addFieldi

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

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

Thanks a lot for your help!

share|improve this question
    
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

1 Answer 1

up vote 3 down vote accepted

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

\DTLloadrawdb{testdb}{testdb.csv}

Now your macros will be happy with \par and empty lines.


TeXnical explanation
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.

share|improve this answer
    
Thanks a lot, that works! –  Frank Jun 19 '12 at 11:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.