ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] buffers and comments
@ 2026-02-17 20:36 Henning Hraban Ramm
  2026-02-17 21:18 ` [NTG-context] " Wolfgang Schuster
  0 siblings, 1 reply; 4+ messages in thread
From: Henning Hraban Ramm @ 2026-02-17 20:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,
Pablo and I were discussing possibilities for code examples.

We’d like to copy a code example to a comment (annotation) because it’s 
easier to copy from there, esp. if line numbers are involved.

The example tries 3 ways, but only the first works, i.e. using a named 
buffer and calling it by name.

I don’t understand why the version with a defined buffer doesn’t work. 
Isn’t “CodeExample” the name of the buffer?

In the third case, I tried to hook the comment in typing; here I don’t 
know the name of the buffer. I tried \currenttype and \currentbuffer, 
but that didn’t work.


"""
\setupinteraction[state=start,]

% this works:
\protected\def\CodeBuffer[#1]{%
\comment[location=inmargin,space=yes,buffer=#1]{}%
\typebuffer[#1]\blank\getbuffer[#1]}

% comment is empty:
\definebuffer[CodeExample]
\define\stopCodeExample{%
\comment[buffer=CodeExample,location=inmargin,space=yes,color=orange]{}%
\typeCodeExample[option=tex,lines=yes,numbering=line]\blank
\getCodeExample%
}

% comment is empty, what should be the name of the buffer?
\protected\def\CodeComment#1{%
\comment[location=inmargin,spce=yes,buffer=#1]{}}

\setuptyping[TEX][before=\CodeComment]



\starttext
\startbuffer[this-buffer]
\color[red]{Buffer!}
\stopbuffer
\CodeBuffer[this-buffer]


\startTEX
\color[red]{Buffer!}
\stopTEX


\startCodeExample
\color[red]{Buffer!}
\stopCodeExample

\stoptext
"""

Hraban

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

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: buffers and comments
  2026-02-17 20:36 [NTG-context] buffers and comments Henning Hraban Ramm
@ 2026-02-17 21:18 ` Wolfgang Schuster
  2026-02-18  7:12   ` Henning Hraban Ramm
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Schuster @ 2026-02-17 21:18 UTC (permalink / raw)
  To: ntg-context

Am 17.02.2026 um 21:36 schrieb Henning Hraban Ramm:
> Hi,
> Pablo and I were discussing possibilities for code examples.
> 
> We’d like to copy a code example to a comment (annotation) because it’s 
> easier to copy from there, esp. if line numbers are involved.
> 
> The example tries 3 ways, but only the first works, i.e. using a named 
> buffer and calling it by name.
> 
> I don’t understand why the version with a defined buffer doesn’t work. 
> Isn’t “CodeExample” the name of the buffer?
> 
> In the third case, I tried to hook the comment in typing; here I don’t 
> know the name of the buffer. I tried \currenttype and \currentbuffer, 
> but that didn’t work.
> 
> 
> """
> \setupinteraction[state=start,]
> 
> % this works:
> \protected\def\CodeBuffer[#1]{%
> \comment[location=inmargin,space=yes,buffer=#1]{}%
> \typebuffer[#1]\blank\getbuffer[#1]}
> 
> % comment is empty:
> \definebuffer[CodeExample]
> \define\stopCodeExample{%
> \comment[buffer=CodeExample,location=inmargin,space=yes,color=orange]{}%

\comment[buffer=\thedefinedbuffer{CodeExample},...]{}

Wolfgang

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

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: buffers and comments
  2026-02-17 21:18 ` [NTG-context] " Wolfgang Schuster
@ 2026-02-18  7:12   ` Henning Hraban Ramm
  2026-02-18 12:54     ` Henning Hraban Ramm
  0 siblings, 1 reply; 4+ messages in thread
From: Henning Hraban Ramm @ 2026-02-18  7:12 UTC (permalink / raw)
  To: ntg-context

Am 17.02.26 um 22:18 schrieb Wolfgang Schuster:
> Am 17.02.2026 um 21:36 schrieb Henning Hraban Ramm:
>> Hi,
>> Pablo and I were discussing possibilities for code examples.
>>
>> We’d like to copy a code example to a comment (annotation) because 
>> it’s easier to copy from there, esp. if line numbers are involved.
>>
>> The example tries 3 ways, but only the first works, i.e. using a named 
>> buffer and calling it by name.
>>
>> I don’t understand why the version with a defined buffer doesn’t work. 
>> Isn’t “CodeExample” the name of the buffer?
>>
>> In the third case, I tried to hook the comment in typing; here I don’t 
>> know the name of the buffer. I tried \currenttype and \currentbuffer, 
>> but that didn’t work.
>>
>>
>> """
>> \setupinteraction[state=start,]
>>
>> % this works:
>> \protected\def\CodeBuffer[#1]{%
>> \comment[location=inmargin,space=yes,buffer=#1]{}%
>> \typebuffer[#1]\blank\getbuffer[#1]}
>>
>> % comment is empty:
>> \definebuffer[CodeExample]
>> \define\stopCodeExample{%
>> \comment[buffer=CodeExample,location=inmargin,space=yes,color=orange]{}%
> 
> \comment[buffer=\thedefinedbuffer{CodeExample},...]{}

Thank you!

Do you also know a solution how to hook the comment into a typing 
environment, for this case:

"""
% comment is empty, what should be the name of the buffer?
\protected\def\CodeComment#1{%
\comment[location=inmargin,space=yes,buffer=#1]{}}

\setuptyping[TEX][before=\CodeComment] % or after or whatever
"""

Typing uses buffers internally, but I don’t understand enough of the code.

Hraban


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

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: buffers and comments
  2026-02-18  7:12   ` Henning Hraban Ramm
@ 2026-02-18 12:54     ` Henning Hraban Ramm
  0 siblings, 0 replies; 4+ messages in thread
From: Henning Hraban Ramm @ 2026-02-18 12:54 UTC (permalink / raw)
  To: ntg-context

Am 18.02.26 um 08:12 schrieb Henning Hraban Ramm:
> Do you also know a solution how to hook the comment into a typing 
> environment, for this case:
> 
> """
> % comment is empty, what should be the name of the buffer?
> \protected\def\CodeComment#1{%
> \comment[location=inmargin,space=yes,buffer=#1]{}}
> 
> \setuptyping[TEX][before=\CodeComment] % or after or whatever
> """

I solved it with another defined buffer “TEXbuffer”, so that I can 
simply change \startTEX to \startTEXbuffer.

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

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2026-02-18 12:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-17 20:36 [NTG-context] buffers and comments Henning Hraban Ramm
2026-02-17 21:18 ` [NTG-context] " Wolfgang Schuster
2026-02-18  7:12   ` Henning Hraban Ramm
2026-02-18 12:54     ` Henning Hraban Ramm

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