Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to make stickers for envelopes. Each sticker would contain data about one recipient of the letter. I would like to be able to have this data in some text format (CSV) and that LaTeX would take it and format it for printing, of multiple stickers on one page. Is there a package for something like this? Is there some other efficient way to do it?

share|improve this question

1 Answer 1

up vote 11 down vote accepted

The envlab package is perhaps the best choice for labels themselves. In combination with datatool this can be very powerful. I've written a demo on this for the UK-TUG pages: summarising here, the LaTeX file is

\documentclass[12pt,a4paper]{letter}
\usepackage[T1]{fontenc}
\usepackage[english,UKenglish]{babel}
\usepackage{lmodern}
\usepackage{datatool}
\usepackage[nocapaddress]{envlab}
\DTLloaddb{mailing-list}{example.csv}
\SetLabel 
  {63.5mm}  % width
  {38.1mm}  % height
  {15.15mm} % top margin
  {7.75mm}  % left margin
  {2mm}     % inter-label gap
  {3}       % columns
  {7}       % rows
\makelabels % Tell envlab to make labels in the document.
\makeatletter % We need to access some internal commands
\newcommand*{\IfDataT}[1]{% Create a macro taking one argument
  \ifx#1\empty
    \expandafter\@gobble % Empty input: ignore the next thing
  \else
    \ifx#1\DTLstringnull
      \expandafter\expandafter\expandafter
        \@gobble % NULL input: ignore the next thing
    \else
      \expandafter\expandafter\expandafter
        \@firstofone % Use the next thing unchanged
    \fi
  \fi
} 
\newcommand*{\IfDataTF}[1]{% Create a macro taking one argument
  \ifx#1\empty
    \expandafter\@secondoftwo % Empty value: use the False branch
  \else
    \ifx#1\DTLstringnull
      \expandafter\expandafter\expandafter
        \@secondoftwo % NULL value: use the False branch
    \else
      \expandafter\expandafter\expandafter
        \@firstoftwo % A real value: use the True branch
    \fi
  \fi
} 
\makeatother

\begin{document}

\startlabels
\DTLforeach{mailing-list}{%
  \title=Title,%
  \firstname=Firstname,%
  \lastname=Surname,%
  \addressI=AddressI,%
  \addressII=AddressII,%
  \addressIII=AddressIII,%
  \town=Town,%
  \postcode=Postcode,%
  \country=Country%
}{%
  \mlabel{}{%
    \title\IfDataT\title{~}\firstname\unskip\ \lastname\\
    \addressI \\ 
    \addressII \IfDataT\addressII\\
    \addressIII \IfDataT\addressIII\\
    \IfDataTF\country{%
      \postcode \IfDataT\postcode{~}\town\\
      \country
    }{%
      \town \\
      \postcode \\        
    }%
  }%
} %
\end{document}

with a database such as

Title,Firstname,Surname,AddressI,AddressII,AddressIII,Town,Postcode,Country,Email
Miss,Alison,Smith,1 The Street,,,SomeTown,AB1 2XY,,smitha@some.com
Mr,Ben,Jones,2 The Close,SmallVillage,,OtherTown,AB2 4XY,,Ben_Jones@email247.org
Mr,Chris,Brown,Housename,The Main Street,OddVillage,BigTown,AB3 6XY,,rt543syt@univ.ac.uk
Dr,From,Abroad,456 Foreign Stra{\ss}e,Place-en-Conti\'nent,,Townii,2341R,NotInUK,f.abroad@some.place.else

The code I've added on top of the basics here is used to 'pretty print' addresses: you might not need all of it.

share|improve this answer

Your Answer

 
discard

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.