Changes

Jump to navigation Jump to search
69 bytes added ,  11:47, 17 May 2007
== Writing a parser/formatter ==
It is not difficult at all fairly simple to write a little parser which takes as its input your source file and gives in output a .tex file containing the code plus the opportune commands for colorization. You can then include the resulting .tex file in the global ConTeXt document file.As an example, [http://www.cirma.unito.it/andrea/sw/sc/scToConTeXt.py this] is a Python script for the SuperCollider language, which has a striclty Smalltalk-like syntax.
Fed with this source code contained in example.sc file:
 
<context>
/BTEX{\color[SCgrey] "this is a string"}/ETEX .postln ;
/BTEX{\color[SCgreen] \type{\}letterbackslash aSymbol}/ETEX ;
/BTEX{\color[SCblue] ThisClassDoesNotExistThisClassDoesNotExists}/ETEX ;
\stopSC
</texcode>
Basically, the idea is to envelope each item to be colorized inside a /BTEX /ETEX block.
Note that inside the block the text is no more verbatim, so you have to define some string replacement for special characters (e.g. _, %, $ , \, etc). The As an example, the problem of the slash is solved here by wrapping replacing it with \letterbackslash the character within a type command. The example uses some definitions (explained before) which have to be put in the global ConTeXt file
<texcode>
</texcode>
also, example.tex requires color definitions, which are created following SuperCollider colorization interpreter scheme and have to be inserted in the global ConTeXt file:
<texcode>
89

edits

Navigation menu