I am trying to adapt this question/answer on how to do mail merge to work with the letter
document class.
The linked answer works great for me, but when I try to change the document class to letter
I keep getting an error| Argument on \@tempc has an extra }
, but it seems that my braces are balanced. Are letter
and datatool
incompatible? Here is my example. How can I better understand this error? Thanks.
\documentclass{letter}
\usepackage{datatool}
\usepackage{parskip}
\signature{Richard Herron}
\address{New York, NY}
\makeatletter
% Blank/missing fields commands
% \skipblank adds \\ to filled field
% * version adds \space instead of newline
\newcommand\skipblank{\@ifstar\@spskip\@nlskip}
\newcommand\@nlskip[1]{\ifthenelse{\DTLiseq{#1}{}}{\relax}{#1\\}}
\newcommand\@spskip[1]{\ifthenelse{\DTLiseq{#1}{}}{\relax}{#1\space}}
% \checkblank replaces blank fields with ***
\newcommand\checkblank[1]{\ifthenelse{\DTLiseq{#1}{}}{***}{#1}}
\makeatother
\begin{document}
\DTLloaddb{addresses}{mail-merge-addresses.csv}
\DTLforeach*{addresses}{%
\addtitle=Title,
\firstname=FirstName,
\lastname=LastName,
\position=Position,
\addressi=Address1,
\addressii=Address2,
\addressiii=Address3,
\city=City,
\state=State,
\zip=Zip,
\country=Country}
{%
\begin{letter}{\checkblank{\addtitle}\ \firstname\ \lastname\\
\skipblank{\position}
\skipblank{\addressi}
\skipblank{\addressii}
\skipblank{\addressiii}
\city, \state\ \zip\\
\skipblank*{\country}
}
\opening{Dear \checkblank{\addtitle}\ \lastname,}
This is the text of the letter.
\closing{Sincerely,}
\end{letter}
}
\end{document}
Edit: I should add that I'm using the same .csv file database that the linked answer uses, but I get the same results if I remove the blank entries.
Title, LastName, FirstName, Position, Address1, Address2, Address3, City, State, Zip, Country
Dr., Smith, James, Chair, Dept. of Physics, University of Somewhere, 434 East Hall, Cambridge, MA, 02139,
Mr., Jones, Bill, Director of Human Resources, , University of Nowhere, A203 King St., Stanford, CA, 94305,
, Brown, Sally, , Firstline, , 3rdline, East Lansing, MI, , USA