使用存储在变量中的部分文本

使用存储在变量中的部分文本

有没有办法从变量中仅获取部分文本?

我的具体用例是与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}

在此处输入图片描述

相关内容