[Tex/LaTex] verbatim text with C code

contextcontext-mkivverbatim

I'm trying to typeset a lot of C code in the latest ConTeXt (MKIV). It tried:

 \startC
    printf("Hello, world\n");
 \stopC

only to find that \startC macro is undefined. It is defined in verb-c.mkii.
I even tried to put

\input verb-c.mkii

before using \startC but it fails on another undefined macros. What is the proper way to typeset C? The manual recommends \startC but it doesn't state how to switch it on except of \definetyping (which doesn't hightlight the syntax).

It actually works in MKII version of ConTeXt but it fails in MKIV.

Best Answer

This ConTeXt Garden page lists the pret-c module. So the following should work.

\installprettytype[C][C]
\definetyping[C][option=C, tab=4] % defines \startC as shortcut for \starttyping[option=C]
\definetype[typeC][option=C, tab=4, style=tt] % defines \typeC
\definecolor[Ccomment][darkblue]

\starttext
bla bla \typeC{int main(){}} bla bla
\startC
int foo = 42;
\stopC
\stoptext

Maybe you need to install the module first:

tlmgr install context-C-Pretty-Printing
Related Question