The following code works well enough:
envelopea.tex
\documentclass[12pt]{letter}
\usepackage[businessenvelope,customenvelopes]{envlab}
\SetEnvelope[2.0in]{240mm}{145mm}
\setlength{\EnvelopeTopMargin}{0.75in} % 0.5
\setlength{\EnvelopeLeftMargin}{1.25in} % 2.0
\begin{document}
\startlabels
\mlabel{%
1234 Center Lane \\
Long Mile Village \\
92319%
}%
{%
239 Mill Lake Rd \\
Centreville \\
78392%
}%
\end{document}
I would, however, like to use the catchfile package in order to retrieve the addresses from an external file. An implementation might look something like this.
addressa.tex
1234 Center Lane \\%
Long Mile Village \\%
92319%
addressb.tex
239 Mill Lake Rd \\%
Centreville \\%
78392%
letterb.tex
\documentclass[12pt]{letter}
\usepackage[businessenvelope,customenvelopes]{envlab}
\usepackage{catchfile}
\newcommand{\getfromaddress}[1]{\CatchFileDef{\thefromaddress}{#1}{}}
\newcommand{\gettoaddress}[1]{\CatchFileDef{\thetoaddress}{#1}{}}
\providecommand{\expandonce}{\unexpanded\expandafter}
\getfromaddress{addressa.tex}
\gettoaddress{addressb.tex}
\SetEnvelope[2.0in]{240mm}{145mm}
\setlength{\EnvelopeTopMargin}{0.75in} % 0.5
\setlength{\EnvelopeLeftMargin}{1.25in} % 2.0
\begin{document}
\startlabels
\mlabel{%
\expandonce{\thefromaddress}%
}%
{%
\expandonce{\thetoaddress}%
}%
\end{document}
When I compile this code I receive an error message which complains of unbalanced curly brackets. At first glance, things appear to be balanced. I'm not too familiar with the use of \expandafter
and \expandonce
. I figure that someone might be able to make this work quite easily. Any comments/suggestions are greatly appreciated.
I have incorporated code presented in this post together with code suggested by egreg in order to yield a .cls file for letters which can be called by specifying the following info:
- File in which from address resides
- File in which to address resides
- Letter opening/salutation
- Letter closing
- Letter post script
- Letter signature
- Envelope dimensions
I have included the code below:
theletter.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{theletterb}[]
\LoadClass[]{letter}
\RequirePackage{lipsum}
\RequirePackage{catchfile}
\RequirePackage[businessenvelope,customenvelopes]{envlab}
\RequirePackage{xparse}
\RequirePackage[textwidth=345.0pt,%
top=2in,
headheight=1.0in,
headsep=0.20in]{geometry}
\newcommand{\getfromaddress}[1]{\CatchFileDef{\thefromaddress}{#1}{}}
\newcommand{\gettoaddress}[1]{\CatchFileDef{\thetoaddress}{#1}{}}
\providecommand{\expandonce}{\unexpanded\expandafter}
\ExplSyntaxOn
\NewDocumentCommand{\MLABEL}{ }
{
\johnchris_mlabel:oo { \thefromaddress } { \thetoaddress }
}
\cs_set_eq:NN \johnchris_mlabel:nn \mlabel
\cs_generate_variant:Nn \johnchris_mlabel:nn { oo }
\ExplSyntaxOff
\AtBeginDocument{%
\pagestyle{empty}
\let\ps@firstpage\ps@plain
\begingroup\edef\x{\endgroup
\noexpand\begin{letter}{\expandonce{\thetoaddress}}
{\expandonce{\thefromaddress}}}\x
\opening{\theopening}
}%
\AtEndDocument{%
\closing{\theclosing}
\ps{\thepostscript}
\newpage
\startlabels
\MLABEL
\end{letter}
}
letter.tex
\documentclass{theletter}
\getfromaddress{addressa.tex}
\gettoaddress{addressb.tex}
\newcommand{\theopening}{Dear Recipient}
\newcommand{\theclosing}{Sincerely,}
\newcommand{\thepostscript}{}
\signature{Mae L. Mann}
\SetEnvelope[2.0in]{240mm}{145mm}
\setlength{\EnvelopeTopMargin}{0.75in}
\setlength{\EnvelopeLeftMargin}{1.25in}
\begin{document}
\input{body.tex}
\end{document}
And again, the supporting files are:
addressa.tex
1234 Center Lane \\%
Long Mile Village \\%
92319%
addressb.tex
239 Mill Lake Rd \\%
Centreville \\%
78392%
body.tex
lipsum[1]