I wish to copy the content of an environment into a macro (or into a temp file). Previously I use the following code:
\usepackage{environ}
\def\SavedContent{}
\NewEnviron{savecontent}{%
\BODY%
% \global\let\SavedContent\BODY%
\expandafter\gdef\expandafter\SavedContent\expandafter{\BODY}
}
However, this method doesn't work if there's \verb or \lstinline inside the environment.
Later I discovered this question. An answer describes a working way as:
... implement an environment that reads its body verbatimized and then within a macro definition wraps things ...
Unfortunately, the answer is too complicated for me to understand. Thus I would like to ask: how should one define the savecontent environment correctly?
Add: The content doesn't have to be stored into a macro. It would also work if one can save the content into a file and read it later. How could one achieve this?
The motivation of this question is that I want to save the content of the abstract and show it later.
Below is a MWE:
\documentclass{article}
\usepackage{environ}
\def\SavedContent{}
\NewEnviron{savecontent}{%
\BODY%
% \global\let\SavedContent\BODY%
\expandafter\gdef\expandafter\SavedContent\expandafter{\BODY}
}
\begin{document}
\begin{savecontent}
Some text
\end{savecontent}
\SavedContent
% \begin{savecontent}
% \verb|code|
% \end{savecontent}
% \SavedContent
\end{document}
