1

In the code below I want to define a new environment that stores its contents in order to use it later several times with different formats

\documentclass{article}
  \newtoks\environmentcontents
   \newenvironment{myenv}{%
      %\environmentcontents=\bgroup
      }
     {%
      %\egroup
      }

\begin{document}
   \begin{myenv}
      some tokens here
    \end {myenv}


  % {\tiny \environmentcontents}

  Some text in between the same content

 % {\Large \environmentcontents}

\end{document}

1 Answers1

1

I am not exactly sure why you want tokens, rather than, for example, just \long\defing the desired content. However, the tokcycle package is for collecting and operating on tokens. In this case, the operation is merely passing through the tokens unchanged. So as long as you haven't directed the package to process the tokens in a different fashion, the myenv pseudo-environment will collect your tokens in the token register \cytoks. The last thing I do in the MWE is to regurgitate the detokenized \cytoks, so that you can verify that, yes indeed, it has collected the original (unexpanded) tokens.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tokcycle}
\def\myenv{\begingroup\let\endmyenv\endtokcycraw
  \aftertokcycle{\expandafter\endgroup\expandafter\tcenvscope
  \expandafter{\the\cytoks}}\tokcycrawxpress}
\begin{document}
   \myenv
      some tokens \textit{here}, \today
    \endmyenv

   {\tiny \the\cytoks}

  Some text in between the same content

  {\Large \the\cytoks}

\detokenize\expandafter{\the\cytoks}
\end{document}

enter image description here