Hello, I'd like to introduce new code by highlighting it with a background. For instance the following snippet of code does what I want: ----- \starttext \input tufte \setupcolors[state=start] \startbackground \startJV import java.io.IOException ; import org.xml.sax.SAXException ; \stopJV \stopbackground \input tufte \stoptext ----- I'd like to get the two nested environments startbackground/startJV, grouped together under a single concept, in this case the single concept startNewCode. I thought I'd just slurp up the argument nested between the keywords \startNewCode and \stopNewCode into memory and then process the argument. This is my attempt: ----- \definetype [typeJV] [option=JV,palet=graypretty] \def\startNewCode{\blank[medium] \begingroup \catcode`\\=12 \STARTNewCode} { \catcode`\|=0 \catcode`\\=12 |long|gdef|STARTNewCode#1\stopNewCode{% |startbackground |typeJV{#1} |stopbackground |blank[medium] |endgroup}} \starttext \input tufte \startNewCode import java.io.IOException ; import org.xml.sax.SAXException ; \stopNewCode \input tufte \stoptext ----- This unfortunately doesn't work. It gets rid of blank lines and doesn't pretty-print. I realize my attempt is naive, but I've run out of ideas of how to combine a background with a verbatim argument.
Guy Worthington
I'd like to get the two nested environments startbackground/startJV, grouped together under a single concept, in this case the single concept startNewCode.
what about this? \starttext \input tufte \setupcolors[state=start] \definetyping[NewCode][before=\startbackground, after=\stopbackground, option=JV] \startNewCode import java.io.IOException ; import org.xml.sax.SAXException ; \stopNewCode \input tufte \stoptext
I thought I'd just slurp up the argument nested between the keywords \startNewCode and \stopNewCode into memory and then process the argument. This is my attempt:
... too complicated for me :) If the above does not do what you need, say so. Perhaps I will look closer. But verbatim code look rather tricky to me, all those 1000 options for prettyprinting are confusing me. Patrick
Patrick wrote
Guy wrote:
[a convoluted method to combine a background with pretty-printing environment]
what about this?
\definetyping[NewCode][before=\startbackground, after=\stopbackground, option=JV]
That's the effect I'm after. It looks so obvious, now I've seen the answer. Thanks Patrick
Guy Worthington
That's the effect I'm after. It looks so obvious, now I've seen the answer.
It's simple, isn't it? I was trying some low level ConTeXt hacking and after a while I came across this commmand, and I said to myself: Lucky me that I did not post some of this ugly TeX hack to the list... It happens to me so often that I do some ugly stuff in ConTeXt and after a while I find out that there is already some high level interface for it. Patrick
participants (2)
-
Guy Worthington
-
Patrick Gundlach