Changes

Jump to navigation Jump to search
2,035 bytes added ,  10:15, 15 February 2012
Describe the buffers.* commmands
== A bit about buffers ==

Buffers are named chunks of text, saved by ConTeXt to be retrieved by the user later. They are usually defined as follows:
<texcode>
% Start a buffer with a custom name
\startbuffer[Marie]
This is the text in the buffer 'Marie'
\stopbuffer

% Define the \start...\stopPierre environment
\def\startPierre
{\dostartbuffer[Pierre][startPierre][stopPierre]}

% Give \stopPierre some meaning if you want to do something with the buffer right away.
%\def\stopPierre
% {\getbuffer[Pierre]}}

\startPierre
This is the text in the buffer 'Pierre'.
\stopPierre
\getbuffer[Pierre] % Print typeset contents

\startPierre
Now this is the text in the buffer 'Pierre', instead.
\stopPierre
\typebuffer[Pierre] % Print verbatim contents
</texcode>

== The LuaTeX buffers.* commands ==

These commands were all found in the source code: [http://source.contextgarden.net/buff-ini.lua buff-ini.lua]

* <code>buffers.getcontent(b)</code>: Get the contents of the buffer <code>b</code>, or the empty string if the buffer does not exist.
* <code>buffers.raw(b)</code>: Synonym for <code>buffers.getcontent(b)</code>.
* <code>buffers.getlines(b)</code>: Equivalent to <code>splitlines(buffers.getcontent(b))</code>.
* <code>buffers.erase(b)</code>: Delete the buffer <code>b</code> (not just its contents).
* <code>buffers.assign(b, text, catcodes)</code>: Set the contents of buffer <code>b</code> to <code>text</code>, using catcodetable <code>catcodes</code>
* <code>buffers.append(b, text)</code>: Append <code>text</code> to buffer <code>b</code>.
* <code>buffers.exists(b)</code>: Returns the name of the buffer if it exists, or else <code>nil</code>.
* <code>buffers.collectcontent(names, seperator)</code>: Returns the contents of the buffers in <code>names</code>, seperated by <code>seperator</code> (<code>'\n'</code> by default). Names can be either a table, or a comma-seperated string (surrounding braces are automatically removed &mdash; see <code>parsers.settings_to_array</code> in <code>util-prs.lua</code>.

Navigation menu