有没有办法从变量中仅获取部分文本?
我的具体用例是与envlab
包有关的:我希望\returnaddress
命令省略变量的最后两行\fromaddress
(来自letter.cls
)。
就像是:
\documentclass[10pt]{letter}
\usepackage[businessenvelope]{envlab}
\renewcommand{\returnaddress}{
%string processing magic such that the output is
%22 Goat Town\\State of Goats
}
\address{22 Goat Town\\State of Goats\\me@privateemail\\1-900-IDENTITYTHEFT}
\makelabels % this command prints envelope labels on the final page of the document
\begin{document}
\begin{letter}{Addressee}
This is my letter.
\end{letter}
\end{document}
我在 xelatex 工作。
答案1
我们定义一个\computereturnaddress
宏,分离地址的最后两段并将其添加到工作的末尾\address
。
\documentclass[10pt]{letter}
\usepackage[businessenvelope]{envlab}
\usepackage{xparse,xpatch}
\ExplSyntaxOn
\NewDocumentCommand{\computereturnaddress}{}
{
\seq_set_split:NnV \l_marcin_address_seq { \\ } \fromaddress
\seq_pop_right:NN \l_marcin_address_seq \l_tmpa_tl
\seq_pop_right:NN \l_marcin_address_seq \l_tmpa_tl
}
\DeclareExpandableDocumentCommand{\returnaddress}{}
{
\seq_use:Nn \l_marcin_address_seq { \\ }
}
\ExplSyntaxOff
\xapptocmd{\address}{\computereturnaddress}{}{}
\address{22 Goat Town\\State of Goats\\me@privateemail\\1-900-IDENTITYTHEFT}
\makelabels % this command prints envelope labels on the final page of the document
\begin{document}
\begin{letter}{Addressee}
This is my letter.
\end{letter}
\end{document}