In a document describing a computer programming language, it is
common to include excerpt of programs. Program code is typically
typeset in a specific font, with no justification, and with a precise
indentation. Indentation is important because it helps
understand the code; it is thus desirable to preserve
indentation in program text. The
pre text layout
already allows indentation to be preserved. This chapter presents two
new functions that complement it:
source, both of which are specially designed to represent computer
programs in text.
prog function call preserves the indentation of the
program. It may automatically introduce line numbers.
Ex. 33: A program
";!"] [:linedigit] [:line
|:ident||html lout latex context info xml ||The node identifier.|
|:class||html lout latex context info xml ||The node class.|
|:line||html lout latex context info xml ||Enables/disables automatic line numbering. An integer
value enables the line number and specifies the number of
the first line of the program. A value of |
the line numbering.
|:linedigit||html lout latex context info xml ||The number of digit for representing line
|:mark||html lout latex context info xml ||A string or the boolean |
#f. If this option
is a string, that string is the prefix
of line marks. These marks can be used in the
ref reference. A mark
identifier is defined by the regular expression:
[_a-zA-Z][_a-zA-Z0-9]*. The prefix and the mark are removed from the output program.
The main goal is specified on line 12.
7.2 Source Code
Ex. 34: The source markup
source function extracts part of the source code and
enables fontification. That is, some words of the program
can be rendered using different colors or faces.
The Fibonacci function is defined on line 1.
Here is the source of the frame above:
Note that even awful programming languages of the C family can be
highlighted!Ex. 35: The source markup for C
You would highlight Java™ code in a similar way, i.e.,
with :language java.
Files passed as the :file argument of
are searched in the current source path, which is defined by the
*source-path* SRFI-39 parameter. This parameter contains
a list of directories and its value can be obtained using
(*source-path*). Its value can be altered using the -S
command-line option of the skribilo compiler (see Chapter 14 for details).
The :language parameter of
source takes a
language object, which performs the actual source highlighting.
Several programming languages are currently supported: the (skribilo source lisp) module provides skribe, scheme,
stklos, bigloo and lisp, which implement source
highlighting for the corresponding lispy dialects, while the (skribilo source c) module provides c and java.
Thus, you need to import the relevant module to get the right language,
for instance by adding
(use-modules (skribilo source c)) at
the beginning of your document. Additional languages can be created
language function (see below).
language function builds a language that can be used
source function call.