如何渲染 ConTeXt 源代码示例以及 ConTeXt 中的渲染结果

如何渲染 ConTeXt 源代码示例以及 ConTeXt 中的渲染结果

我需要将源代码示例ConTeXt与编译结果放在一起。

code:
  ConTeXt code example 
result:
  compiled result

我可以这样做:

\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

但是代码重复不太方便。

我尝试过这个:

\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

这是我在启动时看到的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
))))
*

什么也没有发生。

答案1

以下是如何使用缓冲区来排版 ConTeXt 源。要自定义类型缓冲区的布局,请使用\setuptyping[buffer][...=...]

\starttext

\startbuffer[logo]
\ConTeXt
\stopbuffer

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

\stoptext

在此处输入图片描述

答案2

我能够获得这样的最低必要配置

\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]},
]

在此处输入图片描述

相关内容