About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-09-23: new blog post "Tales for Our Times: Raising Funds and Awareness for St Martins Housing Trust".

Mail Merging with letter.cls and envlab.sty

\documentclass{letter}

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

\usepackage[a4paper]{geometry}
\usepackage[british]{babel}
\usepackage{datatool}
\usepackage{graphicx}

\usepackage[nocapaddress]{envlab}

\DTLloaddb{people}{people.csv}
\DTLloaddb{countries}{country-codes.csv}

\SetBigLabel{101mm}{139mm}{9mm}{3mm}{2mm}{2}{2}

\renewcommand{\PrintBigLabel}[2]{%
  \begin{minipage}[t][\LabelHeight]{\LabelWidth}%
    \vfill
    \hspace*{1em}%
    \rotatebox[origin=l]{90}{\PrintReturnAddress{#1}}\hfill
    \rule{0.1pt}{\ToAddressWidth}\space
    \rotatebox[origin=l]{90}{\PrintAddress{#2}}%
    \hspace*{1em}%
    \vfill
  \end{minipage}%
}

\makelabels

\name{Mr Big Head}
\signature{Big Head}
\location{Secret Lab of Experimental Stuff}
\address{University of Somewhere\\Some City\\AB3 4YZ}
\telephone{0123456789}

\begin{document}

\DTLforeach*{people}% data
{% assignments
  \Id=id,%
  \Surname=surname,%
  \Forenames=forenames,%
  \Title=title,%
  \AddressI=address1,%
  \AddressII=address2,%
  \Town=town,%
  \County=county,%
  \Postcode=postcode,%
  \CountryCode=country%
}
{%
  \xDTLassignfirstmatch{countries}{code}{\CountryCode}{\CountryName=name}

  \begin{letter}{\DTLifnullorempty{\Title}{}{\Title\ }%
  \Forenames\ \Surname\\\AddressI\\
  \DTLifnullorempty{\AddressII}{}{\AddressII\\}\Town\\
  \DTLifnullorempty{\County}{}{\County\\}\Postcode\\\CountryName}

  \opening{Dear \DTLifnullorempty{\Title}{\Forenames}{\Title} \Surname}

  \thispagestyle{firstpage}
  This is an imaginary letter.

  This is the second paragraph of the letter.

  \closing{Yours sincerely}

  \ps PS: this is a postscript.

  \encl{Photocopy of something interesting\\
   Photocopy of something rather dull}

  \cc{Prof Important Person\\Dr Bor Ing}
  \end{letter}
}

\end{document}

Download mail-merging-letter-labels.tex or mail-merging-letter-labels.pdf.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs