To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
To LUGNET News Traffic PageSign In (Members)
 Publishing / FTX / Tutorial / code

Displaying computer code

Word mode

Once in a while you’ll want to express something in a computer-ish typeface, for example to describe a key on the keyboard or something you would like a reader to type. Using a pair of vertical bar characters around words, you can switch into HTML’s <TT> (teletype) font. Thus, if you wrote:

Press the |Enter| key.

then it displays as “Press the Enter key.”

Note: If you need to display a real vertical bar character, use a backtick just as you would for {, }, [, ], <, and >:

I can write |teletype| stuff and I can write vertical bars `|.

and this displays as “I can write teletype stuff and I can write vertical bars |.”


Block mode

You can also express entire blocks of text as pre-formatted text in the teletype font by using a vertical bar (followed by a space) at the beginning of each such line. For example, if you wrote:

| int main(int argc, char *argv[])
| {
|    ...

then it displays as:
int main(int argc, char *argv[])
{
   ...

Double block mode

Alternatively, you can use two vertical bars (followed by a space) at the beginning of each line in a paragraph to show that block in a lightly shaded background with a thin border.

For example, if you wrote:

|| int main(int argc, char *argv[])
|| {
||    ...

then it displays as:

int main(int argc, char *argv[])
{
   ...

(This tutorial uses double-block mode judiciously.)


Subtleties

Note: Teletype mode behaves slightly differently between block-mode and word-mode. In block-mode (where the first two characters of the line are a vertical bar and a space character), you can safely use any other characters on the line. In word-mode, however, even though {, }, [, ], <, >, and _ are protected from interpretation, you’ll still need to use a backtick character for ` and |. For example,

The size is given by |$foo_bar->{zot}|, if present.

displays nicely as “The size is given by $foo_bar->{zot}, if present.” But

The vector |$C| is computed as |$A | $B|.

will not display as “The vector $C is computed as $A | $B.” To get that, the backtick character ` still needs to be used, like this:

The vector |$C| is computed as |$A `| $B|.
All text, images, or trademarks in this document are the intellectual property of their respective owners.


©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR