Changes

Jump to navigation Jump to search
1,290 bytes added ,  09:27, 30 June 2009
no edit summary
Note that this does not currently (2009.06.30) seem to work in MkIV.
= Pretty printing =
The context distribution includes a number of formatters (or pretty
printers), that can apply some nice formatting to your verbatim text.
Each formatter knows how to handle a specific file format or programming
language and applies syntax highlighting or other fancy displaying.
 
ConTeXt includes a number of predefined formatters, but it is also
possible to define your own. Pretty printing has been completely
redesigned in MkIV, so there are a few differences between MkII and
MkIV. In particular, MkII commonly refers to "formatters", while MkIV
often uses "pretty printers".
 
== Included Formatters ==
There are already some formatters for several programming languages inthe ConTeXt distributionr. The following list is for MkII, MkIV definesa subset of these (look for files called <tt>pret-*.lua</tt> in<tt>texmf/tex/context/base</tt> in the ConTeXt distribution:).
{|
== Your own formatter ==
 
(from a ML answer by Taco, 2006-12-25, "Making a verbatim file for another language")
You should start from the definition that is closest to the language you want to define (especially wrt comment and string syntax) and can probably have a go at making a version of this. Some
questions occur:
 
=== How should I name my file? ===
; MkII: <tt>verb-xxxx.tex</tt>, where <tt>xxxx</tt> is the lowercase name of the formatter.
; MkIV: <tt>pret-xxxx.lua</tt>, where <tt>xxxx</tt> is the lowercase name of the pretty printer.
=== Where should i put my file? ===
=== Do I have to do anything else to get ConTeXt to recognise and use it? ===
Your file has You refer to have a pretty printer using its name like (''e.g.'', the<tt>xxxx</tt> in <tt>verb-xxxx.tex</tt>, with or <tt>pret-xxxx.lua</tt> a ),which should be in lowercase short identifier (example: verb-php.tex)Before you can use a pretty printer, and then you have to use one or two commands to make should let ConTeXt use know about it (this has already been done for the fileincluded formatters).
First:
<texcode>
\installprettytype [PHP] [PHP]
</texcode>
This maps the command <code>\starttyping[option=PHP]</code> to <tt>verb-php.tex</tt>.
This maps the command <code>\starttyping[option=PHP]</code> to the<tt>php</tt> pretty printer. The first argument is the option as passed to \starttyping, the second argument is an uppercase version of the pretty printer name(''e.g.'' <tt>xxxx</tt> ) (thus allowing ConTeXt to find the file),.
And you probably also want:
\definetyping[PHP] [option=PHP]
</texcode>
Because that allows <code>\startPHP ... \stopPHP</code> as a shortcut to <tt>\setuptypingstarttyping[option=PHP]... \stoptyping</tt>.
=== Wait for LuaTeX How to write the pretty printer? ===For MkII, there seems to be no real documentation here. You should takea good look at the existing formatters and base your work off those.However, if you really need custom pretty printing, you might be betterof to look at MkIV instead, since that allows you to write a prettyprinter in lua, which is a lot less painful than writing them in plainTeX.
Unless For MkIV, you need should simply write a lua script that highlighting urgently, I would wait for LuaTeX processes each lineof input and write it in lua then (which is certainly less painful than writing it in plain TeX). But it's up to youproduces tex output. I found those TeX definitions too complicated to even try to understand, I would never dare to try writing one by myselfThe details about this are discussedat [[Custom_pretty_printer]]. -- Mojca
= Tabbing =
14

edits

Navigation menu