![使用存储在变量中的部分文本](https://linux22.com/image/275786/%E4%BD%BF%E7%94%A8%E5%AD%98%E5%82%A8%E5%9C%A8%E5%8F%98%E9%87%8F%E4%B8%AD%E7%9A%84%E9%83%A8%E5%88%86%E6%96%87%E6%9C%AC.png)
有没有办法从变量中仅获取部分文本?
我的具体用例是与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}