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...
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 |
www.pragma-ade.nl |
www.pragma-pod.nl-----------------------------------------------------------------
___________________________________________________________________________________
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-contextwebpage :
http://www.pragma-ade.nl /
http://context.aanhet.netarchive :
https://bitbucket.org/phg/context-mirror/commits/wiki :
http://contextgarden.net___________________________________________________________________________________