Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
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 Jan 17 at 6:42
    
Did not understand how \startbuffer can help. –  s9gf4ult Jan 17 at 6:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.