Changes

Jump to navigation Jump to search
2,273 bytes added ,  16:57, 26 December 2006
cleanup, list of included languages, how to make a new formatter
<cmd>starttyping</cmd>,
<cmd>typebuffer</cmd>
 
Unlike LaTeX's <code>verbatim</code> environment, ConTeXt's <code>typing</code> environments have quite a range of built-in options for formatting the verbatim text, see below.
=In-line text=
Source: [http://archive.contextgarden.net/thread/20050907.093522.baf795f5.en.html]
=Interesting features= Unlike LaTeX's <code>verbatim</code> environment, ConTeXt's typing environments have quite a range of built-in options for formatting the verbatim text. == Embedded formatting commands ==
The <tt>option=commands</tt> setting allows the usage of ConTeXt commands inside verbatim text, as in this example:
</context>
== Included Formatters == There are already some formatters for several programming languages in the ConTeXt distribution: {| ! Code !! Language |- | [[source:verb-c.tex|C]] || C |- | [[source:verb-eif.tex|EIF]] || Eiffel |- | [[source:verb-js.tex|JS]] || JavaScript |- | [[source:verb-jv.tex|JV]] || Java |- | [[source:verb-mp.tex|MP]] || MetaPost & MetaFont |- | [[source:verb-pas.tex|PAS]] || Pascal & Modula |- | [[source:verb-pl.tex|PL]] || Perl 5 |- | [[source:verb-sql.tex|SQL]] || SQL |- | [[source:verb-tex.tex|TEX]] || TeX |- | [[source:verb-xml.tex|XML]] || XML |-|} == 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: === Where should i put my file? === # Possibly the best place is: In the context distribution, but that depends a bit on what language it is, precisely (you can email me the completed file, in that case).# Second best place: http://modules.contextgarden.net, so it can be included in cont-ext.zip (third-party addons that are distributed by Pragma-Ade alongside the normal distribution).# Third best: The directory <$HOME/texmf/tex/context/base> (the place where your TeX installation finds local files).# Final option: Same directory as the file to be processed === Do I have to do anything else to get ConTeXt to recognise and use it? === Your file has to have a name like <tt>verb-xxxx.tex</tt>, with <tt>xxxx</tt> a lowercase short identifier (example: verb-php.tex), and then you have to use one or two commands to make ConTeXt use the file. First:<texcode>\installprettytype [PHP] [PHP]</texcode>This maps the command <code>\starttyping[option=PHP]</code> to <tt>verb-php.tex</tt>. The first argument is the option as passed to \starttyping, the second argument is an uppercase version of <tt>xxxx</tt> (thus allowing ConTeXt to find the file), And you probably also want:<texcode>\definetyping[PHP] [option=PHP]</texcode>Because that allows <code>\startPHP ... \stopPHP</code> as a shortcut to <tt>\setuptyping[option=PHP]</tt>  = Tabbing ==
The tab character normally corresponds to one character, as can be seen above. That value can be adjusted, using the following code (available in the 2005.06.01 version and later):
</context>
== Syntax highlighting in color ==
<texcode>
</context>
== Line numbering ==
In technical documents it can be required to display some code listings with the line numbers. You can do this with ConTeXt, and even more. All the features shown here are also available when displaying external files with <cmd>typefile</cmd>.
=== Preliminary setting ===
Let's define our own typing style, named "code". The typing is put in a framedtext, to demonstrate the wrapping feature in a next section.
</texcode>
=== Default line numbering ===
With the defined typing, every line is numbered, and the number goes in the margin. The option to have the line numbers displayed is <tt>numbering=line</tt>.
</context>
=== Line numbers in the text ===
To have the line numbers in the text, change the linenumbering setup like this:
</context>
=== Continuing the numbering ===
Another handy feature is the ability to continue the numbering from one portion of code to another. Use the option <tt>continue</tt> for this.
</context>
=== Arbitrary starting line number ===
You can also decide what the starting line number is. Use the option <tt>start=number</tt> for this.
</context>
=== Line number steps ===
You want to print a number every two lines? Ok, just use the option <tt>step=number</tt> for this.

Navigation menu