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 : [email protected] / 
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
___________________________________________________________________________________

Reply via email to