Hans Hagen via ntg-context schrieb am 02.08.2021 um 17:17:
On 8/2/2021 4:43 PM, Aditya Mahajan via ntg-context wrote:
On Mon, 2 Aug 2021, Benjamin Buchmuller via ntg-context wrote:

Hi,

How can I check if a buffer or block has content (or is empty) before a \useblocks or \getbuffer statement?

I would like to typeset a headline only if the buffer/block has been used in a particular section and want to avoid headlines with empty sections.

There may be more efficient ways to do it (since buffers are stored at the lua end), but you can always do \doiftextelse(\getbuffer[...]} to test it buffer creates any output.
indeed you know there is a way ...

\starttext

\startbuffer[test]
test
\stopbuffer

\doifelsebuffer{test} {YES} {NOP}

\permanent\protected\def\doifelsebuffercontent#1%
  {\doifelse{\luaexpr{(string.strip(buffers.getcontent("#1")) ~= "" and "yes")}}{yes}}

\startbuffer[test]
\stopbuffer

\doifelsebuffercontent{test} {YES} {NOP}

\startbuffer[test]

\stopbuffer

\doifelsebuffercontent{test} {YES} {NOP}

\stoptext

if we can agree on a proper name then i can add a (more efficient) \doifelse...

To follow the existing commands we can use

\doifelsebufferempty
\doifelsebuffersomething
\doifelsebuffernothing

or (we already have \xmldoif... and \btxdoif...)

\bufferdoifelseempty
\bufferdoifelsesomething
\bufferdoifelsenothing

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to