ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How to check if buffer or block has content
@ 2021-08-02 14:19 Benjamin Buchmuller via ntg-context
  2021-08-02 14:43 ` Aditya Mahajan via ntg-context
  0 siblings, 1 reply; 11+ messages in thread
From: Benjamin Buchmuller via ntg-context @ 2021-08-02 14:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Benjamin Buchmuller

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.

Thanks!


Benjamin
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  2021-08-02 14:19 How to check if buffer or block has content 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
  0 siblings, 1 reply; 11+ messages in thread
From: Aditya Mahajan via ntg-context @ 2021-08-02 14:43 UTC (permalink / raw)
  To: Benjamin Buchmuller via ntg-context; +Cc: Aditya Mahajan

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.

Aditya
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  2021-08-02 14:43 ` Aditya Mahajan via ntg-context
@ 2021-08-02 15:17   ` Hans Hagen via ntg-context
  2021-08-02 16:21     ` Hans van der Meer via ntg-context
  2021-08-02 16:31     ` Wolfgang Schuster via ntg-context
  0 siblings, 2 replies; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2021-08-02 15:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  2021-08-02 15:17   ` Hans Hagen via ntg-context
@ 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
  1 sibling, 1 reply; 11+ messages in thread
From: Hans van der Meer via ntg-context @ 2021-08-02 16:21 UTC (permalink / raw)
  To: NTG ConTeXt; +Cc: Hans van der Meer


[-- Attachment #1.1: Type: text/plain, Size: 2344 bytes --]

And in pathological cases where even this does not work (as I encountered a few days ago): 
\setbox\scratchbox=\vboxx{content}\ifdim\wd\scratchbox>\zeropoint .. \else .. \fi
dr. Hans van der Meer


> On 2 Aug 2021, at 17:17, Hans Hagen via ntg-context <ntg-context@ntg.nl> wrote:
> 
> 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
> ___________________________________________________________________________________


[-- Attachment #1.2: Type: text/html, Size: 5046 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  2021-08-02 16:21     ` Hans van der Meer via ntg-context
@ 2021-08-02 16:28       ` Wolfgang Schuster via ntg-context
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2021-08-02 16:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Wolfgang Schuster


[-- Attachment #1.1: Type: text/plain, Size: 310 bytes --]

Hans van der Meer via ntg-context schrieb am 02.08.2021 um 18:21:
> And in pathological cases where even this does not work (as I 
> encountered a few days ago):
> \setbox\scratchbox=\vboxx{content}\ifdim\wd\scratchbox>\zeropoint .. 
> \else .. \fi

This is how \doiftext works but it uses a \hbox.

Wolfgang


[-- Attachment #1.2: Type: text/html, Size: 845 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  2021-08-02 15:17   ` Hans Hagen via ntg-context
  2021-08-02 16:21     ` Hans van der Meer via ntg-context
@ 2021-08-02 16:31     ` Wolfgang Schuster via ntg-context
  2021-08-03  7:35       ` Hans Hagen via ntg-context
  1 sibling, 1 reply; 11+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2021-08-02 16:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Wolfgang Schuster

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  2021-08-02 16:31     ` Wolfgang Schuster via ntg-context
@ 2021-08-03  7:35       ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2021-08-03  7:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

On 8/2/2021 6:31 PM, Wolfgang Schuster via ntg-context wrote:

> \doifelsebufferempty

i go for that one (mkiv and lmtx0 ; btw, \doifelsebuffer is expandable 
but the empty test not)

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  2021-08-03 15:02   ` Hans Hagen via ntg-context
@ 2021-08-03 17:51     ` Benjamin Buchmuller via ntg-context
  0 siblings, 0 replies; 11+ messages in thread
From: Benjamin Buchmuller via ntg-context @ 2021-08-03 17:51 UTC (permalink / raw)
  To: Hans Hagen; +Cc: Benjamin Buchmuller, mailing list for ConTeXt users

Wow, that's powerful!

I'll add the wiki entries later tonight. 

Thanks a lot!

> On Aug 3, 2021, at 17:02, Hans Hagen <j.hagen@xs4all.nl> wrote:
> 
> On 8/2/2021 8:54 PM, Benjamin Buchmuller via ntg-context wrote:
>> That's great, I wikified a Note for testing if a buffer exists or has content (using the \getbuffer[…] approach for the moment).
>> If I was asked, I'd opt for \doifelseemptybuffer (doifemptyelse?) since one could think of similar commands that test for empty "objects".
>> Is there an option for testing blocks? (I actually use blocks quite frequently …)
>> I just realized they are probably handled very differently during the typesetting. Basically I would just need to test if during the first run any of \beginBLOCK … \endBLOCK was invoked (but if one gets a test for some content in-between that's even better).
>> As an alternative solution, is there a way to add content to buffers? Unfortunately, I can't use \getbuffer[first,second], but \startbuffer[first][add=yes] … \stopbuffer would be nice.
> just for fun I made this:
> 
> \starttext
> 
> \startbuffer[test]
>    test
> \stopbuffer
> 
> \startbuffer[oeps]
>    oeps
> \stopbuffer
> 
> \typebuffer[test] \getbuffer[test]
> 
> \startbuffer[test = * + test]
>    prepend
> \stopbuffer
> 
> \typebuffer[test] \getbuffer[test]
> 
> \startbuffer[test = test + *]
>    append
> \stopbuffer
> 
> \typebuffer[test] \getbuffer[test]
> 
> \startbuffer[test = * +++ test]
>    before
> \stopbuffer
> 
> \typebuffer[test] \getbuffer[test]
> 
> \startbuffer[test = test +++ *]
>    after
> \stopbuffer
> 
> \typebuffer[test] \getbuffer[test]
> 
> \startbuffer[test = * + oeps + test + oeps + * ]
>    DONE
> \stopbuffer
> 
> \typebuffer[test] \getbuffer[test]
> 
> \stoptext
> 
> which results in
> 
> test
> test
> prependtest
> prependtest
> prependtestappend
> prependtestappend
> before
> prependtestappend
> before
> prependtestappend
> before
> prependtestappend
> after
> before
> prependtestappend
> after
> DONEoepsbefore
> prependtestappend
> afteroepsDONE
> DONEoepsbefore
> prependtestappend
> afteroepsDONE
> 
> so basically one can combine buffers any way
> 
> +   : nothing in between
> ++  : space in between
> +++ : empty line in between
> 
> 
> -----------------------------------------------------------------
>                                          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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2021-08-03 15:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen, Benjamin Buchmuller

On 8/2/2021 8:54 PM, Benjamin Buchmuller via ntg-context wrote:
> That's great, I wikified a Note for testing if a buffer exists or has content (using the \getbuffer[…] approach for the moment).
> 
> If I was asked, I'd opt for \doifelseemptybuffer (doifemptyelse?) since one could think of similar commands that test for empty "objects".
> 
> Is there an option for testing blocks? (I actually use blocks quite frequently …)
> 
> I just realized they are probably handled very differently during the typesetting. Basically I would just need to test if during the first run any of \beginBLOCK … \endBLOCK was invoked (but if one gets a test for some content in-between that's even better).
> 
> As an alternative solution, is there a way to add content to buffers? Unfortunately, I can't use \getbuffer[first,second], but \startbuffer[first][add=yes] … \stopbuffer would be nice.
just for fun I made this:

\starttext

\startbuffer[test]
     test
\stopbuffer

\startbuffer[oeps]
     oeps
\stopbuffer

\typebuffer[test] \getbuffer[test]

\startbuffer[test = * + test]
     prepend
\stopbuffer

\typebuffer[test] \getbuffer[test]

\startbuffer[test = test + *]
     append
\stopbuffer

\typebuffer[test] \getbuffer[test]

\startbuffer[test = * +++ test]
     before
\stopbuffer

\typebuffer[test] \getbuffer[test]

\startbuffer[test = test +++ *]
     after
\stopbuffer

\typebuffer[test] \getbuffer[test]

\startbuffer[test = * + oeps + test + oeps + * ]
     DONE
\stopbuffer

\typebuffer[test] \getbuffer[test]

\stoptext

which results in

test
test
prependtest
prependtest
prependtestappend
prependtestappend
before
prependtestappend
before
prependtestappend
before
prependtestappend
after
before
prependtestappend
after
DONEoepsbefore
prependtestappend
afteroepsDONE
DONEoepsbefore
prependtestappend
afteroepsDONE

so basically one can combine buffers any way

+   : nothing in between
++  : space in between
+++ : empty line in between


-----------------------------------------------------------------
                                           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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
  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
  1 sibling, 0 replies; 11+ messages in thread
From: Hans Hagen via ntg-context @ 2021-08-03 12:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen, Benjamin Buchmuller

On 8/2/2021 8:54 PM, Benjamin Buchmuller via ntg-context wrote:
> That's great, I wikified a Note for testing if a buffer exists or has content (using the \getbuffer[…] approach for the moment).
> 
> If I was asked, I'd opt for \doifelseemptybuffer (doifemptyelse?) since one could think of similar commands that test for empty "objects".
> 
> Is there an option for testing blocks? (I actually use blocks quite frequently …)
> 
> I just realized they are probably handled very differently during the typesetting. Basically I would just need to test if during the first run any of \beginBLOCK … \endBLOCK was invoked (but if one gets a test for some content in-between that's even better)

indeed, multiple axis ... so then we need three arguments instead of one 
for the test

\defineblock[testa]
\defineblock[testb]

\starttext

\begintesta
     oeps
\endtesta

\doifelseblocksempty {testa}{}{} {YES} {NOP} % {name}{tag}{criterium}
\doifelseblocksempty {testb}{}{} {YES} {NOP} % {name}{tag}{criterium}

\stoptext

but you have to wikify it

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to check if buffer or block has content
       [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
  0 siblings, 2 replies; 11+ messages in thread
From: Benjamin Buchmuller via ntg-context @ 2021-08-02 18:54 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Benjamin Buchmuller

That's great, I wikified a Note for testing if a buffer exists or has content (using the \getbuffer[…] approach for the moment). 

If I was asked, I'd opt for \doifelseemptybuffer (doifemptyelse?) since one could think of similar commands that test for empty "objects".

Is there an option for testing blocks? (I actually use blocks quite frequently …) 

I just realized they are probably handled very differently during the typesetting. Basically I would just need to test if during the first run any of \beginBLOCK … \endBLOCK was invoked (but if one gets a test for some content in-between that's even better).

As an alternative solution, is there a way to add content to buffers? Unfortunately, I can't use \getbuffer[first,second], but \startbuffer[first][add=yes] … \stopbuffer would be nice.

Thanks!


Benjamin

> On Aug 2, 2021, at 17:17, ntg-context-request@ntg.nl wrote:
> 
> \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 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-08-03 17:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 14:19 How to check if buffer or block has content 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
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

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).