2

I would like automaticaly write 5 letter with \documentclass[10pt]{lettre}. I 've a CSV file with all my recipient information in mail_bd2.csv like :

Titre,Apostrophe,Prenom,Nom,Organisme,Rue,Ville
Monsieur,Cher,machin, truc, lala,13 rue du Four, 15478 LALA

and my .tex document is :

\documentclass[10pt]{lettre}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}


\usepackage{datatool}

% Adjust margins for aesthetics
\addtolength{\voffset}{4cm}


\makeatletter
\newcommand*{\NoRule}{\renewcommand*{\rule@length}{0}}
\makeatother

\date{\today} % Date of the letter

\begin{document}

\DTLloaddb{adresses}{mail_bd2.csv} 
% Initialisation des variables à utiliser par champ
\DTLforeach{adresses}{
  \titre=Titre,
  \apo=Apostrophe,
  \prenom=Prenom,
  \nom=Nom,
  \org=Organisme,
  \rue=Rue,
  \ville=Ville,
  %\mail=Email
}{


\begin{letter}{\titre{} \prenom{} \textsc{\nom}\\
               \org\\
               \rue\\
               \textsc{\ville}}
\NoRule


\opening{\apo{} \prenom{},}

blablablabalbalbab

\closing{Veuillez agréer, \MakeLowercase{\apo{}} \prenom{}, l'expression de mes
sentiments les meilleurs.}

\end{lettre}
}
\end{document}

It work for 3 of 5 lettres ... and I'm not able to understand the error in the log file :

l.66 }

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Too many }'s.
<argument> ...db@row@elt@end@ }{\@dtl@after }\fi }
                                                  {}\csname @dtl@endhook@\th...
l.66 }

You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.

! Extra \else.
\@iwhilesw ...i ->#1\expandafter \@iwhilesw \else 
                                                  \@gobbletwo \fi {#1}\fi 
l.66 }

I'm ignoring this; it doesn't match any \if.

! Extra \else.
\@iwhilesw ...i ->#1\expandafter \@iwhilesw \else 
                                                  \@gobbletwo \fi {#1}\fi 
l.66 }

I'm ignoring this; it doesn't match any \if.

Runaway argument?
\@nil \@@ {adresses}\fi \ifthenelse {\boolean {true}}{\refstepcounter \ETC.
! Paragraph ended before \@dtl@next was complete.
<to be read again> 
                   \par 
l.66 }

I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.


Class lettre Message: Lettre 3.

[1

] (/usr/local/texlive/2014/texmf-dist/tex/latex/lettre/default.ins

Class lettre Message: Adresse precisee.


Class lettre Message: Numero de telephone precise.


Class lettre Message: Numero de fax precise.


Class lettre Message: Lieu precise.

)

Class lettre Message: Adresse precisee.


Class lettre Message: Numero de telephone precise.


Class lettre Message: Numero de fax supprime.


Class lettre Message: Numero d'E-Mail precise.


Class lettre Message: Lieu precise.


Class lettre Message: Signature simple.


! LaTeX Error: \begin{letter} on input line 66 ended by \end{lettre}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.66 }

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Too many }'s.
\@iwhilesw ...@iwhilesw \else \@gobbletwo \fi {#1}
                                                  \fi 
l.66 }

You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.


Class lettre Message: Nombre de lettres :3.


Class lettre Message: Nombre de telefax :0.

[2

] (./test_lettre.aux) )
(\end occurred when \ifnum on line 66 was incomplete)
(\end occurred when \ifnum on line 66 was incomplete)
(\end occurred when \ifnum on line 66 was incomplete) 
Here is how much of TeX's memory you used:
 5938 strings out of 493108
 78082 string characters out of 6134853
 189754 words of memory out of 5000000
 9273 multiletter control sequences out of 15000+600000
 6529 words of font info for 20 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 46i,7n,38p,798b,439s stack positions out of 5000i,500n,10000p,200000b,80000s
{/usr/local/texlive/2014/t
exmf-dist/fonts/enc/dvips/cm-super/cm-super-t1.enc}</usr/local/texlive/2014/tex
mf-dist/fonts/type1/public/cm-super/sfcc1000.pfb></usr/local/texlive/2014/texmf
-dist/fonts/type1/public/cm-super/sfrm1000.pfb></usr/local/texlive/2014/texmf-d
ist/fonts/type1/public/cm-super/sfti1000.pfb></usr/local/texlive/2014/texmf-dis
t/fonts/type1/public/cm-super/sftt1000.pfb>
Output written on test_lettre.pdf (3 pages, 81465 bytes).
PDF statistics:
 31 PDF objects out of 1000 (max. 8388607)
 21 compressed objects within 1 object stream
 0 named destinations out of 1000 (max. 500000)
 1 words of extra memory for PDF output out of 10000 (max. 10000000)

someone can help ?

1
  • I suspect that this bit is the critical part: ! LaTeX Error: \begin{letter} on input line 66 ended by \end{lettre}.
    – Thruston
    Apr 28 '15 at 17:04
3

You have three problems:

  1. There is no \fromname defined;
  2. You start with \begin{letter} and end with \end{lettre};
  3. Since you're excluding an email address, you should remove the last comma in the list of fields specified for \DTLforeach{<db>}{<list>}{..}, otherwise datatool expects something. And that something can't be blank.

So this is what your document should look like:

\documentclass[10pt]{lettre}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}

\usepackage{datatool}

% Adjust margins for aesthetics
\addtolength{\voffset}{4cm}

\makeatletter
\newcommand*{\NoRule}{\renewcommand*{\rule@length}{0}}
\makeatother

\date{\today} % Date of the letter

\begin{document}

\newcommand*\fromname{Someone Special}

\DTLloaddb{adresses}{mail_bd2.csv} 
% Initialisation des variables à utiliser par champ
\DTLforeach{adresses}{
  \titre=Titre,
  \apo=Apostrophe,
  \prenom=Prenom,
  \nom=Nom,
  \org=Organisme,
  \rue=Rue,
  \ville=Ville%,
  %\mail=Email
}{
  \begin{letter}{\titre{} \prenom{} \textsc{\nom}\\
                 \org\\
                 \rue\\
                 \textsc{\ville}}
    \NoRule

    \opening{\apo{} \prenom{},}

    blablablabalbalbab

    \closing{Veuillez agréer, \MakeLowercase{\apo{}} \prenom{}, l'expression de mes
    sentiments les meilleurs.}

  \end{letter}
}
\end{document}

This is what the letter should look like if you don't use datatool (just for a visual):

enter image description here

Here is the same document reproduced without the lettre class, but using the default article instead (and datatool):

enter image description here

\documentclass[10pt]{article}

\usepackage{filecontents}
\begin{filecontents*}{mail_bd2.csv}
Titre,Apostrophe,Prenom,Nom,Organisme,Rue,Ville
Monsieur,Cher,machin, truc, lala,13 rue du Four, 15478 LALA
\end{filecontents*}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}

\usepackage{datatool}

% Adjust margins for aesthetics
\usepackage{geometry}
\geometry{%
  margin=1.875in,
  top=3in
}

\setlength{\parindent}{0pt}% No paragraph indent
\begin{document}

\newcommand*\fromname{Someone Special}

\DTLloaddb{adresses}{mail_bd2.csv} 
% Initialisation des variables à utiliser par champ
\DTLforeach{adresses}{
  \titre=Titre,
  \apo=Apostrophe,
  \prenom=Prenom,
  \nom=Nom,
  \org=Organisme,
  \rue=Rue,
  \ville=Ville%
}{
  \clearpage\thispagestyle{empty}%
  \hspace*{-1.25in}%
  \begin{tabular}[t]{@{}l}
    B.I.D.O.N \\
    Rue Des Mots \\
    80886 Sassonne-le-Creux \\[\normalbaselineskip]
    Tél.: 987.64.20 \\
    Fax.: 987.75.31
  \end{tabular}
  \hfill
  \begin{tabular}[t]{l@{}}
    Sassonne-le-Creux, \today
  \end{tabular}

  \bigskip

  \mbox{}\hfill
  \begin{tabular}{l@{}}
    \phantom{Sassonne-le-Creux, \today} \\[-\normalbaselineskip]
    \titre{} \prenom{} \textsc{\nom} \\
    \org \\
    \rue \\
    \textsc{\ville}
  \end{tabular}

  \vspace{2in}

  \apo{} \prenom{},

  \medskip

  blablablabalbalbab

  \bigskip\bigskip

  Veuillez agréer, \MakeLowercase{\apo{}} \prenom{}, l'expression de mes sentiments les meilleurs.

  \vspace{1.25in}

  \hfill
  \fromname
}
\end{document}

It's fairly straight-forward to replicate the lettre behaviour using something that doesn't require the somewhat awkward interface (in my opinion).

6
  • Much better then my answer....:( But I cannot compile it... Apr 28 '15 at 17:46
  • Your solution gives me an error Can't assign \ville there os no key Ville in database adresses.... Apr 28 '15 at 17:57
  • @PeterEbelsberger: Yes, sorry. I had a missing %...
    – Werner
    Apr 28 '15 at 17:57
  • No Problem. But you are an expert, can you see whats wrong with the solution below (which was sent from my) why is the \closing command failing but if I remove it it is working as expected? Apr 28 '15 at 18:00
  • 1
    @delaye as you can see at the other answerpost the \newcommand*\fromname{Someone Special} was missing at my origin solution. If you add this command in your preamble, than the solution (both solutions) work as expected. Apr 29 '15 at 9:36
1
\documentclass[10pt]{lettre}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}

\usepackage{datatool}

% Adjust margins for aesthetics
\addtolength{\voffset}{4cm}


\makeatletter
\newcommand*{\NoRule}{\renewcommand*{\rule@length}{0}}
\makeatother

\date{\today} % Date of the letter
\providecommand{\mclosing}[1]{
\protect #1
}
\begin{document}
\DTLsetseparator{,}
% \DTLloadrawdb{adresses}{mail-bd2.csv} 
\DTLloadrawdb[keys={Titre,Apostrophe,Prenom,Nom,Organisme,Rue,Ville}]{adresses}{mail-bd2.csv} %took more robost loaddb
\DTLforeach{adresses}{\Titre=Titre,\Apostrophe=Apostrophe,\Prenom=Prenom,\Nom=Nom,\Organisme=Organisme,\Rue=Rue,\Ville=Ville}
        {%
\begin{letter}{\Titre \Prenom \textsc{\Nom}\\ %Some spellingerrors
               \Organisme \\
               \Rue\\
               \textsc{\Ville}}    
\NoRule
\opening{\Apostrophe \Prenom,}
blablablabalbalbab
% \closing{Veuillez agréer, \MakeLowercase{\Apostrophe} \Prenom, l'expression de messentiments les meilleurs.} % here is the problem
\mclosing{Veuillez agréer, \MakeLowercase{\Apostrophe} \Prenom, l'expression de messentiments les meilleurs.}
\end{letter} \newpage  %Some spellingerrors
        }%
\end{document}

The problem is the \closing command, I do not know why. This is a workaround, a bad one...

2
  • You'll see I mention in my answer that there is a missing \fromname not defined by the OP. The same is required in yours...
    – Werner
    Apr 28 '15 at 18:11
  • Oh, what a mess. Thank you for your hint. :( Apr 28 '15 at 18:16

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.