TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for an example for using the mailmerge package to write a cover letter, with names and addresses on a spreadsheet. The package comes with an example, but you have to manually enter all the data.

share|improve this question
Have you looked at the datatool (ctan.org/tex-archive/macros/latex/contrib/datatool) package? I've done what you're talking about with it and a database in .csv file. – jon Nov 8 '11 at 21:19
You might be interested in the UK-TUG templates page, which includes a mail merge demo amongst other things. – Joseph Wright Nov 8 '11 at 21:29
up vote 13 down vote accepted

I use the datatool package. I don't use the letter document class, since I use my own letterhead package plus the article class. But the basics of how to do this should be clear, and adaptable to letter class. It's important to do checks for empty fields in address lines, otherwise you will get blank lines.

I use the parskip package with letters, which sets the \parindent to 0 and uses blank lines to separate paragraphs. If you don't like this, then you may want to set the address lines in a {tabular}{@{}l} environment instead.


% Blank/missing fields commands
% \skipblank adds \\ to filled field; * version adds \space instead of newline
% \checkblank replaces blank fields with ***
\DTLloaddb{addresses}{mail-merge-addresses.csv} % use your actual address database here
\checkblank{\addtitle}\ \firstname\ \lastname,\\
\city, \state\ \zip\\

Dear \checkblank{\addtitle}\ \lastname:

This is the text of the letter.



The mail-merge-addresses.csv file is the following: (It deliberately has blank fields to illustrate the field checking.)

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

Your Answer


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.