[NTG-context] How can I remove a blank leading line from a buffer

Aditya Mahajan adityam at umich.edu
Mon Aug 13 05:44:56 CEST 2018


On Sun, 12 Aug 2018, Rik Kabel wrote:

> %% How can one remove blank lines at the start of a buffer so that
> %%   commands that grab a buffer can be used in the same way as, for
> %%   example, \startparagraph...\stopparagraph, which allow blank
> %%   lines around the content?
> %%
> %% The problem appears when an optional argument is allowed but none
> %%   is provided. Adding \relax does not help; adding empty brackets
> %%   does. I see no way to distinguish between a buffer without
> %%   leading blank lines and a buffer that was created when brackets
> %%   are provided.
> %%
> %% \inlinebuffer handles the leading blank lines when there is
> %%   nothing prepended, but I need to prepend. (It also handles the
> %%   unwanted trailing line, but that is not an issue here).
> %%
> %% How can I unpack the buffer, apply the equivalent functions of
> %%   ignorespaspaces and removeunwantedspaces to it, and repack it?
> %%   The buffer may contain internal blank lines and macros, and
> %%   those should be retained. Or, is there already a function to
> %%   strip a buffer in the manner that string.strip does a string?
>
> \setupwhitespace[none]
> \setupindenting[none]
> \define\Mark{\color[middlegray]{\itb¿\ }}
> \define\First{nothing yet}
> \define\Arg{nothing yet}
> \setuplanguage[en][spacing=packed]
>
> \starttexdefinition unexpanded startBufTest
>   \bgroup
>   \dosingleempty\dostartBufTest
> \stoptexdefinition
>
> \starttexdefinition dostartBufTest [#SETUPS]
>   \doifsomethingelse{#{SETUPS}}
>                     {\define\Arg{yes}}
>                     {\define\Arg{no}}
>   \iffirstargument
>     \define\First{yes}
>   \else
>     \define\First{no}
>   \fi
>   \relax
>   \getrawparameters[BufTest][xx=yy,#SETUPS]
>   \grabbufferdata[TestBuffer][startBufTest][stopBufTest]
> \stoptexdefinition
>
> \starttexdefinition stopBufTest
>
>   \startparagraph
>
>     \dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer]
>     \ (first: \First, arg: \Arg)
>
>   \stopparagraph
>
>   \egroup
> \stoptexdefinition
>
> \starttext
>
> \startparagraph
>
>   A starting paragraph.
>
> \stopparagraph
>
> \startBufTest
>   Buffer without blank lines.
> \stopBufTest
>
> \startparagraph
>
>   An intervening paragraph.
>
> \stopparagraph
>
> \startBufTest
>
>   Buffer with blank lines.
>
> \stopBufTest
>
> \startparagraph
>
>   An intervening paragraph.
>
> \stopparagraph
>
> \startBufTest\relax
>
>   Buffer with \tex{relax}.
>
> \stopBufTest
>
> \startparagraph
>
>   An intervening paragraph.
>
> \stopparagraph
>
> \startBufTest[]
>
>   Buffer with \type{[]}.
>
> \stopBufTest
>
> \startparagraph
>
>   An intervening paragraph.
>
> \stopparagraph
>
> \startBufTest[key=value]
>
>   Buffer with \type{[key=value]}.
>
> \stopBufTest
>
> \startparagraph
>
>   A closing paragraph.
>
> \stopparagraph
>
> \stoptext
>
> \stopmode

Perhaps \ignorespaces might work, but I often find that the conceptually 
simplest solution is to post-process the buffer at the lua end. See
http://wiki.contextgarden.net/Programming_in_LuaTeX#Manipulating_verbatim_text
for an example.

Aditya


More information about the ntg-context mailing list