Next: , Previous: , Up: Quotations and Examples   [Contents][Index]


7.4 @example: Example Text

The @example environment is used to indicate computer input or output that is not part of the running text. If you want to embed code fragments within sentences, use the @code command or its relatives instead (see @code{sample-code}).

Write an @example command at the beginning of a line by itself. Mark the end of the block with @end example. For example,

@example
cp foo @var{dest1}; \
 cp foo @var{dest2}
@end example

produces

cp foo dest1; \
 cp foo dest2

The output uses a fixed-width font and is indented. Each line in the input file is a line in the output; that is, the source text is not filled. Extra spaces and blank lines are significant. Texinfo commands are expanded; if you want the output to be the input verbatim, use the @verbatim environment instead (see @verbatim: Literal Text).

Examples are often, logically speaking, “in the middle” of a paragraph, and the text that continues afterwards should not be indented, as in the example above. The @noindent command prevents a piece of text from being indented as if it were a new paragraph (see @noindent: Omitting Indentation).

If you wish to use the normal roman font for a code comment, you can use the @r command (see Fonts for Printing).

You may optionally give arguments to the @example command, separated by commas if there is more than one. In the HTML output, any such arguments are output as class names. This may be useful for adding syntax highlighting to manuals for code samples. We recommend that when you give multiple arguments to @example, you use the first argument to specify the language of the code (e.g. ‘C’, ‘lisp’, ‘Cplusplus’). You may find uses for other arguments, such as providing a formatting hint or marking code samples for extraction and further processing, but for now nothing definitive is recommended. Perhaps this will change in future Texinfo releases.

Caution: Do not use tabs in the lines of an example! (Or anywhere else in Texinfo, except in verbatim environments.) TeX treats tabs as single spaces, and that is not what they look like.


Next: @verbatim: Literal Text, Previous: @indentedblock: Indented text blocks, Up: Quotations and Examples   [Contents][Index]