[Tex/LaTex] Ways to grab and store larger amount of text

macros

A standard way to grab and store a short text (say, a title of a document) is to use something like

\def\title#1{\def\@title{#1}}.

But if the content to be stored is longer (say, an abstract}, I guess it is considered more elegant to specify it by something like

\begin{abstract}
  ...
\end{abstract}

on the user side.

So, the question is: what techniques are available to do something like this? (Some that spring to my mind immediately are: use a \vbox, use delimited arguments, use the environ LaTeX package, use ConTeXt \grabbufferdata (if I am not mistaken as to the name of that macro)…)

I'd be delighted to see all kinds of answers, for various engines (Knuthian vanilla TeX, eTeX, luaTeX) and formats (plain TeX, LaTeX2e, LaTeX3, ConTeXt).

Best Answer

The collect package; a little example (defining an environment to collect text and format it between rules and using \section):

\documentclass{article}
\usepackage{collect}
\usepackage{lipsum}

\definecollection{test}
\makeatletter
\newenvironment{atest}[1]
  {\@nameuse{collect}{test}{\par\nobreak\noindent\hrulefill}
    {\par\nobreak\noindent\hrulefill\par\bigskip}
    {\section{#1}}
    {}%
  }
{\@nameuse{endcollect}}
\makeatother

\begin{document}

\begin{atest}{example one}
\lipsum[2-3]
\end{atest}

\begin{atest}{example two}
\lipsum[2]
\end{atest}

\lipsum[1-6]

\includecollection{test}

\end{document}

enter image description here

Related Question