如何将 \cytoks 添加到 \tokencyclexpress?

如何将 \cytoks 添加到 \tokencyclexpress?

这就是我正在做的事情:

\documentclass{article}
\usepackage{tokcycle}
\begin{document}
\tokencyclexpress
Hello1
\endtokencyclexpress % Hello1 is in \cytoks
\tokencyclexpress % We start a new buffer
\the\cytoks % Print the old buffer into it (Hello1)
Hello2
\endtokencyclexpress % Close the new buffer
\the\cytoks % Print "Hello1Hello2"
\end{document}

上述代码不起作用。我该如何修复?

答案1

因为\tokencyclexpress重新初始化\cytoks,您必须将的内容保存在\cytoks某处,并将保存的副本输入到令牌循环中。

\documentclass{article}
\usepackage{tokcycle}
\newtoks\cumtoks
\begin{document}
\tokencyclexpress
Hello1
\endtokencyclexpress % Hello1 is in \cytoks
\cumtoks\expandafter{\the\cytoks}

\tokencyclexpress % We start a new buffer
\the\cumtoks % Print the old buffer into it (Hello1)
Hello2
\endtokencyclexpress % Close the new buffer

\the\cytoks % Print "Hello1Hello2"
\end{document}

在此处输入图片描述

按照上一个问题的方式,下面是如何实现自动化。像以前一样\cytoks保存来自当前环境的令牌,但\cumtoks保存来自所有环境的令牌累积。

\documentclass{article}
\usepackage{tokcycle}
\newtoks\cumtoks
\xtokcycleenvironment\accumstart
  {\whennotprocessingparameter##1{\addcytoks{##1}}}
  {\processtoks{##1}}
  {\addcytoks{##1}}
  {\addcytoks{##1}}
  {\let\stop\endaccumstart}
  {\tcafterenv{\cumtoks\expandafter\expandafter\expandafter{%
    \expandafter\the\expandafter\cumtoks\the\cytoks}\def\print{\the\cumtoks}}}
\begin{document}
\accumstart
Hello1
\stop % Hello1 is in \cytoks

\print

\accumstart % We start a new buffer
Hello2
\stop % Close the new buffer

\print % Print "Hello1Hello2"

\accumstart % We start a new buffer
Hello3
\stop % Close the new buffer

\print % Print "Hello1Hello2"
\end{document}

在此处输入图片描述

相关内容