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
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{newenviron}
\usepackage{blindtext}
\usepackage{etoolbox}
\def\mylist{}%
\listadd{\mylist}{}% Initialize list
\newrobustcmd{\myexpandingcommand}[1]{%
\listgadd{\mylist}{#1}%
}%
\newenviron{content}{%
}{%
\noindent\textbf{\LARGE \textcolor{blue}{Environment content}} % Remove later on!
\noindent\envbody%
\expandafter\myexpandingcommand\expandafter{\envbody}%
\endgraf\bigskip\bigskip% Can be removed
}%
% Macro showing the current list element%
\newrobustcmd{\showlist}[1]{%
#1%
}%
\begin{document}
\begin{content} % Store some content%
\blindtext%
\end{content}
\noindent\textbf{\LARGE \textcolor{green}{Text content outside of environment}} % Can be removed, just for diagnosis/test
\noindent\blindtext
\endgraf\bigskip
\begin{content}
\textbf{\textcolor{red}{Even more text and now even some math: \huge \(\displaystyle\int\limits^{b}_{a} f(x) dx\)}}%
\end{content}
\begin{center}
\begin{tcolorbox}[width=0.8\textwidth,title={Now the combined content of the list}]
\forlistloop{\showlist}{\mylist}%
\end{tcolorbox}%
\end{center}
\end{document}
tcolorbox
is just for eye-catching, nothing more, to show the combined content more nicely.