我需要寄送大量普通信件,并希望将地址/回邮标签直接打印在信封上。我之前遵循此方法制作信件,因此 csv 文件中已经有地址。
这个帖子然后向我指出了 envlab 包,mlabel 命令似乎完全按照我的要求执行,但与用于邮件合并的第一种方法的数据工具配合得不太好。
然后我发现此方法将 datatools 与 letter/envlab 包一起使用。但是,它被设置为启动 letter 文档,而我想将其用于 mlabel 命令。
我尝试了几个选项;请参阅下面的代码。如果我尝试第二种方法,并将 mlabel 命令注释掉,它将正确打印地址块,但不是以信封格式打印。至少,这意味着我的文本命令是可以的,但 mlabel 函数/宏似乎不接受它?
谢谢你尽你所能的帮助。 :)
\documentclass{letter}
\usepackage{geometry}
\usepackage{datatool}
\geometry{paperheight=162mm,paperwidth=114mm}
\usepackage[c6envelope,noprintbarcodes,rightenvelopes,printreturnaddress]{envlab}
\makeatletter
\newtoks\address@toks
\newcommand\addto@address[1]{%
\address@toks=\expandafter{\the\expandafter\address@toks#1}%
}
%attempt #1
\newcommand\makeaddress{%
\address@toks={}%
\addto@address{\firstnamei\ }%
\ifthenelse{\DTLiseq{\lastnamei}{}}{}{\addto@address{\lastnamei}}
\ifthenelse{\DTLiseq{\firstnameii}{}}{}{\addto@address{\& \firstnameii}}
\ifthenelse{\DTLiseq{\lastnameii}{}}{}{\addto@address{\lastnameii}}
\addto@address{\noexpand\\}
\ifthenelse{\DTLiseq{\addressi}{}}{}{\addto@address{\addressi\\}}
\addto@address{\city, \province}
\addto@address{\noexpand\\}
\addto@address{\postal}
\begingroup
\edef\x{\endgroup\noexpand\mlabel{\the\address@toks}}\x
}
%attempt #2
\newcommand\makeaddressii{%
\address=\firstnamei\ \ifthenelse{\DTLiseq{\lastnamei}{}}{\relax}{\lastnamei}\ifthenelse{\DTLiseq{\firstnameii}{}}{\relax}{\& \firstnameii} \ifthenelse{\DTLiseq{\lastnameii}{}}{\relax}{\lastnameii} \\ \ifthenelse{\DTLiseq{\addressi}{}}{\relax}{\addressi\\} \city, \province \\ \postal \\
\mlabel{%
my address\\someplace\\somewhere\\}{%
\address\\}
}
\makeatother
\makelabels
\begin{document}
\startlabels
\DTLloaddb{addresses}{mail-merge.csv}
\DTLforeach*{addresses}{%
\firstnamei=FirstName1,
\lastnamei=LastName1,
\firstnameii=FirstName2,
\lastnameii=LastName2,
\addressi=Address1,
\city=City,
\province=Province,
\postal=Postal}
{%
\makeaddress %attempt#1
\makeaddressii %attempt#2
}
\end{document}