[NTG-context] Syntax highlighting for C-code
schuster.wolfgang at googlemail.com
Sun Jan 15 12:06:03 CET 2012
Am 13.01.2012 um 12:00 schrieb Richard Weickelt:
> I've tried to include some C-code into my document, but failed to enable syntax highlighting.
> Tested on: linux-64, context-2011.05.18 (same with the beta) stand-alone mkIV
> 1) \starttyping[option=C] just prints verbatim text. There seems to be no formatter for C out of the box.
There is no formatter for C code in MkIV but when you write one send the file to Hans and he can include it in the distribution.
> 2) t-vim did not work. It failed somewhere (unknown command sequence \installspacehandler) on loading (\usemodule[vim])
> 3) http://wiki.contextgarden.net/Verbatim_text
> I tried to download pret-c and put it into the modules folder, but writing \installprettytype[C][C] failed, because it's not known (in mkIV).
MkII and MkIV have different implementation to format source code.
> 4) mkII does not complain to exec \installprettytype[C][C], but this does not change anything either. \starttyping[option=C] seems to call a (maybe builtin?) formatter, but I could not get colors to work.
The following is MkII only. There are two ways to have formatted C code, the first is to define a C environment with \definetype[C][option=C] and then you can put the code between \startC and \stopC, the second is to use the normal typing environment and pass “option=C” as argument. To get colors in your code you have to enable them first with \setupcolors[state=start].
More information about the ntg-context