In ConTeXt, \grabbufferdata
is a low-level command that is only useful to module
writers. At user level, buffers
should be used to grab and store contents. For
example, store the contents using
\startbuffer
Whatever
\stopbuffer
and retreive them using:
\getbuffer
You may also typeset the contents using
\typebuffer
which is useful when you want to include verbatim material in tables and
footnotes.
Buffers may be thought of as a clipboard for copy-pasting content; in fact, as
named clipboard, which is useful when you want to repeat material in a
document like a presentation or build metapost figures in steps. To get named
buffers, simply store content using
\startbuffer[anything]
This is a named buffer
\stopbuffer
and retrieve it using
\getbuffer[anything]
or
\typebuffer[anything]
Buffers are more robust than grabbing content using boxes because you do not
need to care about catcodes while grabbing content. (Of course, you need to
worry about them when retreiving content).
\startbuffer
A C file starts with \type{#include<stdio.h>}.
\stopbuffer
\getbuffer
works fine even though the content has a #
. For this reason, buffers are
used when you want to process some XML inline in a regular TeX document.
Buffers can also be nested. For example:
\startbuffer[one]
Buffer one
\startbuffer[two]
Buffer two
\stopbuffer
\stopbuffer
\getbuffer[one]
\getbuffer[two]
(of course, buffer two is only available after buffer one has been
retreived).
In MkIV, \startbuffer
and \stopbuffer
can be on the same line
\startbuffer[line] #line \stopbuffer
\typebuffer[line]
And finally, the contents of a buffer are available at the Lua end (as the
content is stored in memory). Use the Lua function buffers.getcontent('name')
to access the contents of the buffer named name
.
Of course, like any other ConTeXt macro, you may define your own version of
buffers.
\definebuffer
[grabcontent]
[
before=...,
after=...,
]
and then use them as regular buffers.
\startgrabcontent
A # B C
\stopgrabcontent
\typegrabcontent
The before
and after
keys are used with \getgrabcontent
.
Since buffers don't care about their content, they are
an excellent comment environment. In fact, the hiding
environment in ConTeXt
is defined as a buffer.
\setupbuffer
[\v!hiding]
[\c!before=,
\c!after=]
\verb
inside or whatever.abstract
) and (ii) situations when you want to do both: typeset and store some material for later reuse. And I wouldn't care too much about\verb
, if you need to use it, you are probably writing about TeX itself, and that means that you're not a newbie;). (\url
is a problem, though.)