3

I need to place source code example in ConTeXt with compiled result.

code:
  ConTeXt code example 
result:
  compiled result

I can do it like that:

\mainlanguage[ru]

\usemodule  [simplefonts][size=12pt]
\setmainfont[dejavusans][expansion=quality,protrusion=quality]
\setmonofont[monaco][expansion=quality,protrusion=quality]

\usemodule [vim]
\defineframedtext [CODEBLOCK][background=color,backgroundcolor=lightgray,
                              width=\dimexpr(\textwidth-1cm),frame=off,offset=2mm]
\definevimtyping[TEX][syntax=context,before=\startCODEBLOCK,after=\stopCODEBLOCK]
\defineframedtext [CODERESULT][width=\textwidth,frame=off,offset=2mm]
\definedescription[descr][indenting=1cm,indentnext=yes,location=right,
  width=\textwidth,distance=\dimexpr(1cm-\textwidth),align={width,stretch}]

\starttext


\startdescr{code:} \hfill
\startTEX
\ConTeXt
\stopTEX
\stopdescr

\startdescr{result:} \hfill
\startCODERESULT
\ConTeXt
\stopCODERESULT
\stopdescr

\stoptext

but code duplication is not very convenient.

I tried this:

\mainlanguage[ru]

\usemodule  [simplefonts][size=12pt]
\setmainfont[dejavusans][expansion=quality,protrusion=quality]
\setmonofont[monaco][expansion=quality,protrusion=quality]

\usemodule [vim]
\defineframedtext [CODEBLOCK][background=color,backgroundcolor=lightgray,
                              width=\dimexpr(\textwidth-1cm),frame=off,offset=2mm]
\definevimtyping[TEX][syntax=context,before=\startCODEBLOCK,after=\stopCODEBLOCK]
\defineframedtext [CODERESULT][width=\textwidth,frame=off,offset=2mm]
\definedescription[descr][indenting=1cm,indentnext=yes,location=right,
  width=\textwidth,distance=\dimexpr(1cm-\textwidth),align={width,stretch}]

\def\texsample#1{
\startdescr{code:} \hfill
\startTEX
#1
\stopTEX
\stopdescr

\startdescr{result:} \hfill
\startCODERESULT
#1
\stopCODERESULT
\stopdescr
}


\starttext

\texsample{
\ConTeXt
}

\stoptext

and this is what I see when launch ConTeXt

(/usr/share/texmf-dist/tex/context/third/filter/t-filter.mkiv
loading         > Filter (ver: 2013.04.15)
resolvers       > modules > 'module-catcodes' is loaded
(/usr/share/texmf-dist/tex/context/third/filter/t-module-catcodes.tex
loading         > Module Catcodes (ver: 2011.12.17)
))
resolvers       > modules > 'syntax-highlight' is loaded
(/usr/share/texmf-dist/tex/context/third/vim/t-syntax-highlight.mkiv
loading         > Code syntax highlighting (ver: 2012.08.01)
resolvers       > modules > 'syntax-groups' is loaded
(/usr/share/texmf-dist/tex/context/third/vim/t-syntax-groups.tex
loading         > Syntax highlighting groups (ver: 2012.05.06)
resolvers       > modules > 'module-catcodes' is already loaded
)
resolvers       > modules > 'filter' is already loaded
))))
*

and nothing happens.

2
  • 2
    The standard way to do this is to use buffers. \startbuffer ... \stopbuffer to store content, \typebuffer to type it, and \getbuffer to process it. The vim module also allows you to typeset buffers (see documentation).
    – Aditya
    Commented Jan 17, 2014 at 6:42
  • Did not understand how \startbuffer can help.
    – s9gf4ult
    Commented Jan 17, 2014 at 6:54

2 Answers 2

3

Here is how to use buffers to typeset ConTeXt source. To customize the layout of the typed buffer use \setuptyping[buffer][...=...].

\starttext

\startbuffer[logo]
\ConTeXt
\stopbuffer

To typeset the \ConTeXt\ logo use
\typebuffer[logo][option=context]
\getbuffer[logo]

\stoptext

enter image description here

1
  • This is a great start. How did you get the color green? It is not specified. How can I change the font size? spacing? etc?
    – meh
    Commented Apr 16 at 13:26
0

I was able to get the minimum necessary configuration like this

\startbuffer[comprehensions]
for i, val in #Components
let component = val {
  "\(component)": {
    extraEnv?: [...corev1.#EnvVar]
    resources?: corev1.#ResourceRequirements
    tolerations?: [...corev1.#Toleration]
    nodeSelector?: [string]: string
  }
}
\stopbuffer

\typebuffer[comprehensions][
    style={\switchtobodyfont[9pt,tt]},
]

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .