Changes

Jump to navigation Jump to search
2,395 bytes added ,  21:17, 10 May 2006
no edit summary
\stopXML
\stoptext
</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 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>
\defineframedtext
[framedcode]
[strut=yes,
offset=2mm,
width=7cm,
align=right]
 
\definetyping[code][numbering=line,
bodyfont=small,
before={\startframedcode},
after={\stopframedcode}]
</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>.
 
<texcode>
\startcode
This is the first line
This is a rather long line that is wrapped, so look how the line numbering is done
Another line
 
Last line after an empty line
\stopcode
</texcode>
 
It is rendered as:
 
<context>
\defineframedtext
[framedcode]
[strut=yes,
offset=2mm,
width=7cm,
align=right]
 
\definetyping[code][numbering=line,
bodyfont=small,
before={\startframedcode},
after={\stopframedcode}]
 
\startcode
This is the first line
This is a rather long line that is wrapped, so look how the line numbering is done
Another line
 
Last line after an empty line
\stopcode
</context>
 
=== Line numbers in the text ===
To have the line numbers in the text, change the linenumbering setup like this:
 
<texcode>
\setuplinenumbering[location=intext]
\startcode
This is the first line
This is a rather long line that is wrapped, so look how the line numbering is done
Another line
 
Last line after an empty line
\stopcode
</texcode>
 
<context>
\defineframedtext
[framedcode]
[strut=yes,
offset=2mm,
width=7cm,
align=right]
 
\definetyping[code][numbering=line,
bodyfont=small,
before={\startframedcode},
after={\stopframedcode}]
 
\setuplinenumbering[location=intext]
\startcode
This is the first line
This is a rather long line that is wrapped, so look how the line numbering is done
Another line
 
Last line after an empty line
\stopcode
</context>
Anonymous user

Navigation menu