Monospace

In AsciiDoc, a span of text enclosed in a single pair of backticks (`) is displayed using a fixed-width (i.e., monospaced) font. Monospace text formatting is typically used to represent text shown in computer terminals or code editors (often referred to as a codespan).

Constrained

Here’s an example:

Example 1. Constrained monospace syntax
"`Wait!`" Indigo plucked a small vial from her desk's top drawer
and held it toward us.
The vial's label read: `E=mc^2^`; the `E` represents _energy_,
but also pure _genius!_

The result of Example 1 is rendered below.

“Wait!” Indigo plucked a small vial from her desk’s top drawer and held it toward us. The vial’s label read: E=mc2; the E represents energy, but also pure genius!

Unconstrained

As with other types of text formatting, if the text is bounded by word characters on either side, it must be enclosed in a double pair of backtick characters (``) in order for the formatting to be applied.

Here’s an example:

The command will re``link`` all packages.

Mixed Formatting

Monospaced text can also be formatted in bold or italic or both, as long as the markup pairs are entered in the right order. The monospace markup must be the outermost formatting mark, then the bold marks, then the italic marks.

Example 2. Order of inline formatting syntax
`*_monospaced bold italic_*`

The result of Example 2 is rendered below.

monospaced bold italic

Literal Monospace

Unlike other markup languages, monospaced text in AsciiDoc is not synonymous with literal text. Instead, it gets interpreted just like normal text. In other words, it’s subject to all text substitutions by default.

This might be surprising at first. But there’s good reason for this difference. In AsciiDoc, you can take advantage of attribute references and inline macros inside of a monospaced text span. The drawback, of course, is that you have to be careful to escape these special characters if you intend to output them without special formatting (i.e., as literal text).

One way to prevent the processor from interpreting special characters in monospaced text is to escape them using backslash characters, just as you would with normal text. However, escaping individual occurrences that way can be tedious. That’s why AsciiDoc offers a special type of monospace formatting called the literal monospace.

To make a true literal codespan in AsciiDoc, you must enclose the monospaced text in a passthrough. Rather than using a single pair of backtick characters, you’ll use the combination of the backtick and plus characters, where the plus characters fall on the inside of the backtick characters (e.g., `+text+`). The plus characters are a shorthand for the pass:c[] enclosure.

Example 3 contains literal, monospaced text.

Example 3. Literal monospace syntax
You can reference the value of a document attribute using
the syntax `+{name}+`, where `name` is the attribute name.

This shorthand syntax can accommodate most of the literal monospace cases. The main exception is when the text itself contains plus characters. To avoid confusing the processor, you’ll need to switch to using the more formal passthrough macro to handle these cases.

Example 4 shows literal, monospaced text that contains plus characters.

Example 4. Literal monospace syntax with + characters
`pass:[++]` is the increment operator in C.

Passthroughs are a general purpose utility in AsciiDoc. You can learn about the various passthrough options in Inline Passthroughs.