From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@xs4all.nl>
Subject: Re: How to check if buffer or block has content
Date: Mon, 2 Aug 2021 17:17:29 +0200 [thread overview]
Message-ID: <60ef1c00-becc-0f97-151e-95f77a07a955@xs4all.nl> (raw)
In-Reply-To: <nycvar.YAK.7.78.908.2108021042120.297391@nqv-guvaxcnq>
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-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2021-08-02 15:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-02 14:19 Benjamin Buchmuller via ntg-context
2021-08-02 14:43 ` Aditya Mahajan via ntg-context
2021-08-02 15:17 ` Hans Hagen via ntg-context [this message]
2021-08-02 16:21 ` Hans van der Meer via ntg-context
2021-08-02 16:28 ` Wolfgang Schuster via ntg-context
2021-08-02 16:31 ` Wolfgang Schuster via ntg-context
2021-08-03 7:35 ` Hans Hagen via ntg-context
[not found] <mailman.1176.1627917453.1143.ntg-context@ntg.nl>
2021-08-02 18:54 ` Benjamin Buchmuller via ntg-context
2021-08-03 12:26 ` Hans Hagen via ntg-context
2021-08-03 15:02 ` Hans Hagen via ntg-context
2021-08-03 17:51 ` Benjamin Buchmuller via ntg-context
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=60ef1c00-becc-0f97-151e-95f77a07a955@xs4all.nl \
--to=ntg-context@ntg.nl \
--cc=j.hagen@xs4all.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).