I want to store contents of an environment and add them to a macro or command I could easily retrieve them, but I do not want to use the collect package. Are there any alternatives?


%i want to add content to running list and later get whole contents

 text text text\\


  moretext moretext more text\\


You can print the saved environments by “name” or all of them.







Something for a

Something for b

Something with no label

\textbf{Let's print them}

This is a: \printsaved{a}

This is b: \printsaved{b}

\textbf{Print all of them}



This requires two runs (when the saved environments change), because of the usage of \label. You can save up to 1000 environments, but you can change the number in the obvious way. Don't try setting the number to much more than 30000.

enter image description here

  • how about if i want to create multiple \globtoksblk eg \savedenvtoks1{10}, need help making savedenv to take a \globtoksblk parameter and also for printallsaved to take a parameter indicating which \globtoksblk...? – Ephraim Ncory Jun 13 '14 at 7:58
  • @EphraimNcory It's not very clear. Do you want to have different classes of "saved environments"? – egreg Jun 13 '14 at 8:00
  • yeah something like that, i want to create multiple tok blocks and be able to get their toks. – Ephraim Ncory Jun 13 '14 at 8:03
  • @EphraimNcory I think you should ask a new question, with more details explaining your needs. – egreg Jun 13 '14 at 8:05
  • i asked a new question with more details, hope you find time to help. – Ephraim Ncory Jun 13 '14 at 10:12

I suggest to use newenviron package instead of environ, because it defines a \envnamebody command.

Note: Do not call your environment env, because it will collide with the implicit \envbody command always being defined for any environment by newenviron.

After changing to that, one can use the etoolbox - list commands \listgadd etc. and forlistloop do add the current content to the list and processing later on, e.g. printing it.

You need a 'printing' command, I named it \showlist.

The content is glued together without any spacing between at the end of the environment code.

Edited version -- glueing 'arbitrary(?)' texts together


\listadd{\mylist}{}% Initialize list


\noindent\textbf{\LARGE \textcolor{blue}{Environment content}}  % Remove later on!

\endgraf\bigskip\bigskip% Can be removed

% Macro showing the current list element%


\begin{content}  % Store some content%

\noindent\textbf{\LARGE \textcolor{green}{Text content outside of environment}}  % Can be removed, just for diagnosis/test



\textbf{\textcolor{red}{Even more text and now even some math: \huge \(\displaystyle\int\limits^{b}_{a} f(x) dx\)}}%


\begin{tcolorbox}[width=0.8\textwidth,title={Now the combined content of the list}]


enter image description here

  • 1
    The last version of environ allows for changing the macro the body is stored in. – egreg Jun 12 '14 at 7:44
  • @egreg: I will look into it and post another solution, eventually... – user31729 Jun 12 '14 at 9:03
  • i need to create more lists which could be different but \myexpandingcommand will only work for \mylist, help. – Ephraim Ncory Jun 13 '14 at 8:02
  • @EphraimNcory: I know, there is some problem with that, I will look after later on, but I had no idea, that you need more than one list, it was not stated in your question – user31729 Jun 13 '14 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.