Subsection 4.15.1 Content and Placement of Programs and Consoles
A
<program>
will be treated as verbatim text (see Section 3.16), subject to all the exceptions for exceptional characters (see Section 3.14). Indentation will be preserved, though an equal amount of leading whitespace will be stripped from every line, so as to keep the code shifted left as far as possible. So you can indent your code consistently along with your XML indentation. For this reason it is best to indent with spaces, and not tabs. A mix will almost surely end badly, and in some programming languages tabs are discouraged (e.g. Python).A
<console>
is a transcript of an interactive session in a terminal or console at a command-line. It is a sequence of the following elements, in this order, possibly repeated many times as a group: <input>
, and <output>
. The <output>
is optional. The content of these two elements is treated as verbatim text (see Section 3.16), subject to all the exceptions for exceptional characters (see Section 3.14). A @prompt
attribute on the <input>
can be supplied to provide a system prompt distinct from the actual commands. The default prompt is a dollar sign followed by a space. If it is more convenient @prompt
may be supplied on the <console>
, to be used in each enclosed <input>
. If you do not want any prompts at all, just use an empty value for @prompt
.A
<program>
or <console>
may be wrapped in a <listing>
, see Section 4.19. This will behave similar to a <figure>
, with the <caption>
displayed below, and a number assigned. So, in particular, if your program or console is important enough to cross-reference, it is an enclosing <listing>
that serves as the target.The
@language
attribute may be used to get some degree of language-specific syntax highlighting and/or interactive behavior. We will eventually provide a table of attribute values here. They are always lowercase, and a good first guess is likely to succeed.In some output formats, notably HTML, the syntax highlighter can add lines or highlight individual lines of code. Highlighting lines is not supported for LaTeX output. To display line numbers, set the
@line-numbers
attribute to yes
. To highlight particular lines, set @highlight-lines
to a comma-separated list consisting of individual lines and/or ranges indicated with dashes. Some examples are: 5
, 2,5
, 2,5-8,10-15,15
.For interactive versions hosted on Runestone servers, the
@label
attribute is critical, just like for interactive exercises. So be certain to read Best Practice 4.12.0.26.