2

Attempting to compile the following file gives the following error:

! Misplaced \noalign.
\pagebreak ->\noalign 
                      {\ifnum `}=0\fi \@testopt {\LT@no@pgbk -}4
l.47 \end{letter}

I don't understand why. Making minor changes to the csv file xx.csv makes this error go away. For example, change mm to m. Alternatively, change mm to 11.

Alternatively, adding a comma to the end of the string 2014.02.26,26,2014.11.12.tm in

\PrintDocTableParekh[2014.02.26,26,2014.11.12.tm]{newbDB}{Documents}

thus changing it to 2014.02.26,26,2014.11.12.tm, also makes the error go away.

\documentclass[12pt]{letter}
\usepackage{longtable}
\usepackage[verbose]{datatool}
\usepackage{array}
\usepackage{url}

\newcounter{tabenum}\setcounter{tabenum}{0}
\newcommand{\colhead}[1]{\multicolumn{1}{>{\bfseries}l}{#1}}
\newcommand{\nextnuml}[1]{\refstepcounter{tabenum}\thetabenum.\label{#1}}
\newcommand*{\checkmissing}[1]{\DTLifnull{#1}{}{#1}}
\signature{Someone}
\newcommand{\PrintDocTableParekh}[3][]{%
 % #1 = list of rowIDs
 % #2 = database to search
 % #3 =caption
  \begin{longtable}{r l p{1.5in} c c p{2.5in}}
    \caption{#3}\\
   & \colhead{Date} & \colhead{Filename} & \colhead{From} & \colhead{To} & \colhead{Subject}\\\hline\endhead
    \DTLforeach
    [\ifblank{#1}{\boolean{true}}{\DTLisSubString{#1}{\RowID}}]
    {#2}{%
      \RowID=RowID,%
      \Date=Date,%
      \Filename=Filename,%
      \From=From,%
      \To=To,%
      \Subject=Subject%
    }{%
      \nextnuml{\RowID} & \Date & {\bfseries\expandafter\url\expandafter{\Filename} } & \checkmissing{\From} & \checkmissing{\To} & \Subject \\
    }%
  \end{longtable}
}%

\begin{filecontents*}{xx.csv}
2014.02.26,       26 Feb 2014      , something.txt     ,      ,    ,    ,subject
2014.11.12.tm,    12 Nov 2014      , something.txt     , XXX  , YY ,    , subject
mm, date, ,,,, subject
\end{filecontents*}

\begin{document}
\begin{letter}{}
  \opening{xx,}
  \closing{Yours Sincerely,}
  \DTLloaddb[noheader,keys={RowID,Date,Filename,From,To,Email,Subject}]{newbDB}{xx.csv}
  \PrintDocTableParekh[2014.02.26,26,2014.11.12.tm]{newbDB}{Documents}

\end{letter}
\end{document}
6
  • no time to look now but you never finish the longtable Feb 18 '15 at 9:27
  • @DavidCarlisle I'm not sure what you mean. Is there something wrong with the syntax I am using? Feb 18 '15 at 13:20
  • I was out all day, may look later but the reason you get that error is that after the command you are still inside the longtable, so it's as if you had \end{letter} inside the table. Feb 18 '15 at 19:08
  • @DavidCarlisle Well, you should know, certainly. But I have \end{longtable} right there. What more could I do to end it? Feb 18 '15 at 22:55
  • putting \endgroup\end{longtable} before \end{letter} makes the document complete (with some warnings) showing that in this document the \end{longtable} in your macro was never executed and you have to close the table by hand. I'm not sure I know datatool well enough to trace this just now, may look another day. Feb 18 '15 at 22:58
2

There seems to be a problem with \DTLifSubString when used within \DTLforeach. (This includes using \DTLisSubString in the conditional argument.) The use of letter and longtable are obfuscating matters, so here's a trimmed down version:

\documentclass{article}

\usepackage{datatool}

\begin{filecontents*}{xx.csv}
2014.02.26
2014.11.12.tm
mm
\end{filecontents*}

\newcommand*{\ifcontainsrowid}[2]{%
 \ifblank{#1}{#2}%
 {%
   \DTLifSubString{#1}{\RowID}{#2}{}%
 }%
}    

\begin{document}

\DTLloaddb[noheader,keys={RowID}]{newbDB}{xx.csv}

\DTLforeach*{newbDB}{\RowID=RowID}%
{%
   \ifcontainsrowid{2014.02.26,26,2014.11.12.tm}%
   {%
      \RowID
   }
}%

\end{document}

This causes a different error message:

Runaway argument?
\expandafter \dtl@ifsingle \expandafter {\dtl@first }{\expandafter \@dtl@testif
substring \ETC.
! Paragraph ended before \dtl@getfirst was complete.
<to be read again> 
                   \par

But it stems from the same problem. I haven't worked out what's causing it yet, but I've been away for a week and need to catch up on things so I haven't had much of a chance to investigate yet. You can get around it by using a different command, for example \IfSubStr from the xstring package:

\documentclass{article}

\usepackage{datatool}
\usepackage{xstring}

\begin{filecontents*}{xx.csv}
2014.02.26
2014.11.12.tm
mm
\end{filecontents*}

\newcommand*{\ifcontainsrowid}[2]{%
 \ifblank{#1}{#2}%
 {%
   %\DTLifSubString{#1}{\RowID}{#2}{}%
   \IfSubStr{#1}{\RowID}{#2}{}%
 }%
}


\begin{document}

\DTLloaddb[noheader,keys={RowID}]{newbDB}{xx.csv}

\DTLforeach*{newbDB}{\RowID=RowID}%
{%
   \ifcontainsrowid{2014.02.26,26,2014.11.12.tm}%
   {%
      \RowID
   }
}%

\end{document}

Update: This bug has been fixed in v2.23.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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