1

I'm trying to use datatool and envlab to print to and from addresses on a biglabel. Currently my code is close, but not quite there. It will print one combination of to/from on a page and with drastically incorrect margins etc. The MW code is,

\documentclass[12pt]{letter}

% Generates the correct label sheet size
\usepackage[paperwidth=5in, paperheight=7in]{geometry}

\usepackage{datatool}
% loads the csv addr.csv, one row per dest
\DTLloaddb{mailing-list}{addr.csv}

\usepackage[nocapaddress,printbarcodes]{envlab}
%\SetBigLabel{W}{H}{t}{l}{r}{Nc}{Nr}
\SetBigLabel{5in}{7in}{0.25in}{0.25in}{0.25in}{1}{3}
\makelabels

\begin{document}
\startlabels

\DTLforeach{mailing-list}{%
  \name=Name,%
  \street=Street,%
  \suite=Suite,%
  \town=City,%
  \state=State,%
  \zip=Zip,%
  \country=Country%,
}{%
\mlabel{%
Joe Casanova\\1 Lambda Street\\Anyplace, NY 12345}{%
\name\\\street\\\town, \state, \zip}}
\end{document}

As I understand it, envlab and datatool are at odds in this example but I don't understand how to make each aware of the other. If I make three \mlabel environments it will print the same information from datatool. Tricking datatool by trying to increment it will work but is a dirty patch b/c I would need the same number of \mlabel environments defined in the code as there are labels on one individual sheet which is kludgy.

Can anyone provide insight? The setup I would like is a 5in x 7in label sheet consisting of 3 vertical labels with 0.25in separation and margins. On each label should be the return address in the upper left and the destination address in the lower right.

1

1 Answer 1

1

I don't know much about envlab but I'm guessing it first gathers the information from \mlabel and then processes all the labels at the end of the document, but it's gathering the label information without expansion, which means that all the labels are using commands like \name, but by the time the labels are typeset \name etc has the value of the last row of the csv file. I think the simplest way to get around this is to define a command that expands the information before passing it to \mlabel. Like this:

\documentclass[12pt]{letter}

\usepackage{etoolbox}
\usepackage{datatool}

\begin{filecontents}{addr.csv}
Name,Street,Suite,City,State,Zip,Country
name1,street1,suite1,city1,state1,zip1,country1
name2,street2,suite2,city2,state2,zip2,country2
\end{filecontents}

\DTLloaddb{mailing-list}{addr.csv}

\usepackage[nocapaddress,printbarcodes]{envlab}

\SetBigLabel{5in}{7in}{0.25in}{0.25in}{0.25in}{1}{3}
\makelabels

\newcommand{\xmlabel}[2]{%
 \edef\domlabel{\noexpand\mlabel{\expandonce{#1}}{\expandonce{#2}}}%
 \domlabel
}

\begin{document}
\startlabels

\DTLforeach{mailing-list}{%
  \name=Name,%
  \street=Street,%
  \suite=Suite,%
  \town=City,%
  \state=State,%
  \zip=Zip,%
  \country=Country%,
}{%
\xmlabel{%
Joe Casanova\\1 Lambda Street\\Anyplace, NY 12345}{%
\name\\\street\\\town, 
\state, \zip}%
}
\end{document}
1
  • The main issue is that when \mlabel is called it refers back to see how many labels to create and the parameters. When this happens all it has is the info in the template so it collects the variables in \name etc and makes the label. This means I get three labels which are identical b/c datatool isn't being asked to increment until after the label is done. Changing settings in envlab makes the label print incorrectly (like printing one label at a time).
    – Joshua
    Apr 25, 2013 at 21:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .