[texhax] How to accumulate TeX input for later use?

Heiko Oberdiek heiko.oberdiek at googlemail.com
Thu Oct 13 22:38:46 CEST 2011


On Thu, Oct 13, 2011 at 03:45:58PM -0300, Pablo Mayckon wrote:

> I would like to have macros that would allow me to accumulate (La)TeX input
> for later use, just like
> 
> \addtomycode{This is just bare text.}
> \addtomycode{ \begin{center} This is more complex. \end{center}}
> \mycode % Should produce "This is ... text. \begin{center} ... \end{center}"
> 
> What is then the best way to accomplish this? Should I "\def\mycode{}" and
> then define "\addtomycode" so as to accumulate the provided arguments? (If so,
> how?)

\makeatletter
\newcommand*{\mycode}{}
\newcommand{\addtomycode}[1]{%
  \g at addto@macro\mycode{#1}%
}
\makeatother

\addtomycode{This is just bare text.}
\addtomycode{ \begin{center} This is more complex. \end{center}}
\mycode % Should produce "This is ... text. \begin{center} ... \end{center}"

Yours sincerely
  Heiko Oberdiek


More information about the texhax mailing list