Is there an easy way to make the abstract's text available in a macro, say \theabstract
? I can do this with the following code:
\documentclass{article}
\usepackage{collect}
\title{A test document}
\author{John Smith}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
\begin{collectinmacro}{\theabstract}{}{}
This is a test.
\end{collectinmacro}
\theabstract
\end{abstract}
The abstract is: \theabstract
\end{document}
However, I would prefer for the abstract code to be simple, i.e.:
\begin{abstract}
This is a test.
\end{abstract}
I have tried without success using \AtBeginEnvironment
and \AtEndEnvironment
from etoolbox
(though I don't quite understand how they work), and also redefining the abstract environment. Both return the error ! File ended while scanning use of \@tempa.
. Minimum working example:
\documentclass{article}
\usepackage{collect,etoolbox}
\title{A test document}
\author{John Smith}
\date{\today}
\AtBeginEnvironment{abstract}{\begin{collectinmacro}{\theabstract}{}{}}
\AtEndEnvironment{abstract}{\end{collectinmacro}\theabstract}
% ! File ended while scanning use of \@tempa.
%\renewenvironment{abstract}{%
%\begin{collectinmacro}{\theabstract}{}{}
%}{%
%\end{collectinmacro}
%\theabstract
%}
% ! File ended while scanning use of \@tempa.
\begin{document}
\maketitle
\begin{abstract}
This is a test.
\end{abstract}
The abstract is: \theabstract
\end{document}
While I am using the collect
package above I'm open to solutions without this package too. I typically use LuaLaTeX so a LuaTeX solution would be welcome.
(It is of course also possible to simply write \newcommand{\theabstract}{This is a test}
and then put \theabstract
in the abstract environment, but ultimately I'd like the code for the abstract environment to be the same as normal.)