AsciiDoc Frequently Asked Questions

JavaScript must be enabled in your browser to display the table of contents.

New FAQs are appended to the bottom of this document.

1. How do you handle spaces in included file names?

Spaces are not allowed in macro targets so this include macro will not
be processed:

include::my document.txt[]

The work-around is to replace the spaces with the {sp} (space
character) attribute, for example:

include::my{sp}document.txt[]

2. How do I number all paragraphs?

Some documents such as specifications and legalese require all
paragraphs to be sequentially numbered through the document, and to be
able to reference these numbers.

This can be achieved by using the DocBook toolchain but numbering the
paragraphs with AsciiDoc using a custom config file containing the
following (see http://asciidoc.org/userguide.html#X27
for ways to include such a file):

References to the paragraphs operate in the normal way, you label the
paragraph:

[[some_label_you_understand]]
paragraph contents

and reference it in the normal manner:

<<some_label_you_understand>>

The text of the reference will be the paragraph number.

For this to work for HTML you have to generate it via the DocBook
toolchain.

3. Sources of information on configuring DocBook toolchains

DocBook is a content and structure markup language, therefore
AsciiDoc generated DocBook markup is also limited to content and
structure. Layout and formatting definition is specific to the
DocBook toolchain.

The True Type Font mimetype had to be declared explicitly with the
--resource .ttf=application/x-font-ttf option because it wasn’t
registered on my Linux system.

In the above example the font file is in the same directory as the
AsciiDoc source file and is installed to the same relative location
in the EPUB archive OEBPS directory — if your font file resides in
a different location you’ll need to adjust the --resource option
accordingly (see the RESOURCES section in the a2x(1) man page
for details).

The URL value of the CSS src property is set to the destination
font file relative to the CSS file.

The --resource option allows you to inject any file (not just font
files) into the EPUB output document.

Using the CSS @font-face rule is a complex subject and is outside
the scope of this FAQ.

Inline passthrough macros are processed before any other inline
substitutions e.g. all of the following line will be processed as a
single inline passthrough and rendered as monospaced text (which is
not the intended result):

`single quoted text' and `monospaced quoted text`

This line works as expected:

`single quoted text' and +monospaced quoted text+

Backtick quoted text is rendered literally i.e. no substitutions
are performed on the enclosed text. Here are some examples that
would have to be escaped if plus quoting were used (see also):

The `++i` and `++j` auto-increments.
Paths `~/.vim` and `~/docs`.
The `__init__` method.
The `{id}` attribute.

6. Why is the generated HTML title element text invalid?

Probably because your document title contains formatting that has
generated HTML title markup. You can resolve this by explicitly
defining the title attribute in your document’s header.

7. AsciiDoc sometimes generates invalid output markup, why?

AsciiDoc is backend agnostic, the asciidoc command has no knowledge
of the syntax or structure of the backend format that it generates.
Output document validation (syntactic and structural) should be
performed separately by external validation tools. For example,
AsciiDoc’s a2x toolchain command automatically performs validation
checks using xmllint.

8. The AsciiDoc toclevels attribute does not work with DocBook outputs, why?

DocBook has no provision for specifying table of contents levels but
you can set the TOC level further down the toolchain by passing the
DocBook XSL Stylesheets
toc.section.depth
parameter to dblatex (using the --param option) or xsltproc
(using the --stringparam option). For example to show only chapter
titles in the TOC of a book document set toc.section.depth to 0.
Increment the toc.section.depth value to show more sub-section
titles. If you are using a2x you can set the options in the source
file, for example:

If the document is of type article use the value 1 to show only
top level section titles in the TOC, use the value 2 for two levels
etc.

9. How can I include chapter and section tables of contents?

DocBook outputs processed by DocBook XSL Stylesheets (either manually
or via a2x) can generate additional separate section and chapter
tables of contents using combinations of the
TOC parameters.
Here are some examples using combinations of the
generate.section.toc.level and toc.section.depth DocBook XSL
Stylesheets parameters:

generate.section.toc.level

toc.section.depth

1

Single level book chapter TOCs or article section TOCs

1

3

Article section TOCs with two levels

1

2

Book chapter TOCs with two levels

10. How can I customize the appearance of XHTML and EPUB documents generated by a2x?

The AsciiDoc reftext attribute has been used to explicitly set the
link text to 2nd section for Section Two.

13. Can I define my own table styles?

In addition to the built-in styles you can define your own. This
(simplified) example for HTML backends defines a table style called
red which sets the background cell color to red. First put the
definition in a configuration file:

15. What is the preferred file name extension for AsciiDoc files?

The .txttext file extension
is preferred, but it’s just a convention and it’s not enforced by the
software.

AsciiDoc source files are human readable
plain text files which is
what the .txt extension is for. All text editors recognize and open
files with a .txt extension. The .txt extension is universally
recognized and unambiguous — you are not left asking questions like
“What on earth is this file with the funny extension?”, “How do I
open it?” and “Is it safe to open?”.

16. How can I generate numbered bibliographic entries?

If your outputs are DocBook generated then adding the following inline
macro to a custom configuration file will result in auto-incrementing
bibliography entry numbers (instead of displaying the bibliographic
identifiers):

18. How can I customize PDF files generated by dblatex?

There are a number of dblatex XSL parameters that can be used to
customize PDF output. You can set them globally in the AsciiDoc
./dblatex/asciidoc-dblatex.xsl configuration file or you can also
pass them on the a2x(1) command-line. Here are some examples:

19. How can I add lists of figures and tables to PDFs created by dblatex?

20. How can I stop the document title being displayed?

You could simply omit the document title, but this will result in a
blank title element in HTML outputs. If you want the HTML title
element to contain the document title then define the notitle
attribute (this will just suppress displaying the title), for example:

My document title
=================
:no title:

21. Why am I having trouble getting nested macros to work?

The following example expands the image inline macro, but the
expansion contains double-quote characters which confuses the ensuing
footnoteref macro expansion:

footnoteref:["F1","A footnote, with an image image:smallnew.png[]"]

The solution is to use unquoted attribute values, replacing embedded
commas with the comma character entity (&#44;):

footnoteref:[F1,A footnote&#44; with an image image:smallnew.png[]]

Similarly, you can embed double-quote characters in unquoted attribute
values using the &#34; character entity.

22. Why am I getting DocBook validation errors?

Not all valid AsciiDoc source generates valid DocBook, for example
special sections (abstract, preface, colophon, dedication,
bibliography, glossary, appendix, index, synopsis) have different
DocBook schema’s to normal document sections. For example, a paragraph
is illegal in a bibliography.

Don’t forget if your document is a book you need to specify the
asciidoc -d book command option, if you don’t an article DocBook
document will be generated, possibly containing book specific
sections, resulting in validation errors.

23. How can I disable special section titles?

For example, you want to use References as a normal section name but
AsciiDoc is auto-magically generating a DocBook bibliography
section. All you need to do is explicitly specify the section template
name, for example:

[sect1]
References
----------

24. How can I insert XML processing instructions into output documents?

Use an inline or block passthrough macros. This example inserts
<?dblatex bgcolor="#cceeff"?> into the DocBook output generated by
AsciiDoc:

pass::[<?dblatex bgcolor="#cceeff"?>]

XML processing instructions are specific to the application that
processes the XML (the previous dblatex processing instruction is
recognized by dblatex(1) when it processes the DocBook XML generated
by Asciidoc).

25. How do I prevent double-quoted text being mistaken for an inline literal?

Mixing doubled-quoted text with inline literal passthroughs can
produce undesired results, for example, all of the following line is
interpreted as an inline literal passthrough:

``XXX'' `YYY`

In this case the solution is to use monospace quoting instead of the
inline literal:

``XXX'' +YYY+

Use the pass:[] macro if it’s necessary to suppress
substitutions in the monospaced text, for example:

``XXX'' +pass:[don't `quote` me]+

26. How can I generate a single HTML document file containing images and CSS styles?

With the advent of Internet Explorer 8 all major web browsers now
support the
data URI scheme for
embedded images. The AsciiDoc xhtml11 and html5 backends supports
the data URI scheme for embedded images and by default it embeds the
CSS stylesheet. For example the following command will generate a
single article.html file containing embedded images, admonition
icons and the CSS stylesheet:

asciidoc -a data-uri -a icons article.txt

27. Are there any tools to help me understand what’s going on inside AsciiDoc?

AsciiDoc has a built-in trace mechanism which is controlled by the
trace attribute; there is also the --verbose command-line option.
These features are detailed in
Appendix G of the
User Guide.

28. One-liner ifdef::[]'s are disproportionately verbose can they shortened?

This is the response to a question posted on the AsciiDoc discussion
list, it illustrates a number of useful techniques. The question arose
because the source highlight filter language identifier for the C++
language is c++ when generating PDFs via dblatex (LaTeX listings
package) or cpp when generating HTML (GNU source-highlight).

29. Some of my inline passthroughs are not passed through, why?

Most likely the passthrough encloses another passthrough with a higher
precedence. For example trying to render this pass:[] with this
`pass:[]` results in a blank string because the pass:[]
passthrough evaluates first, instead use monospaced quoting and escape
the passthrough i.e. +\pass:[]+

30. How can I place an anchor (link target) on a list item?

You can’t use a BlockId block element inside a list but you can use
the syntactically identical anchor inline macro. For example:

one:: Item one.
[[X2]]two:: Item two.
three:: Item three.

This will not work:

one:: Item one.
[[X2]]
two:: Item two.
three:: Item three.

31. How can I stop lists from nesting?

If you place two lists with different syntax hard up against each
other then the second list will be nested in the first. If you don’t
want the second list to be nested separate them with a comment line
block macro. For example:

1. List 1.
2. List 1.
//
a. List 2.
b. List 2.

32. Is it possible to include charts in AsciiDoc documents?

There are a number of programs available that generate presentation
charts from textual specification, for example
Pychart is a library for writing chart
scripts in Python. Here’s an example from the Pychart documentation:

If you have included the custom CSS in a separate stylesheet you
will need to specify the stylesheet file name (along with the
default docbook-xsl.css stylesheet file name) with the
html.stylesheet XSL parameter. If you are using a2x(1) use the
--stylesheet option (it sets the html.stylesheet XSL parameter),
for example: --stylesheet "docbook-xsl.css mycss.css".

This applies to HTML outputs not PDF. To achieve the same
results with PDF outputs you will need to customize the DocBook XSL
Stylesheets to render indented paragraphs from DocBook simpara
elements containing the the role="indented" attribute.

34. Is there a way to set default table grid and frame attributes?

You can set the grid and frame attributes globally in your
document header with Attribute Entries or from the command-line using
the --attribute option. In the following example tables that don’t
explicitly set the grid and frame values will default to all and
topbot respectively:

:grid: all
:frame: topbot

This technique can be applied to any block element attribute
(just beware of possible ambiguity, for example, table and image
blocks both have a width attribute).

35. How can I place a backslash character in front of an attribute reference without escaping the reference?

Use the predefined {backslash} attribute reference instead of an
actual backslash, for example if the {projectname} attribute has
the value foobar then:

d:\data{backslash}{projectname}

would be rendered as:

d:\data\foobar

36. How can I escape AsciiDoc markup?

Most AsciiDoc inline elements can be suppressed by preceding them with
a backslash character. These elements include:

Attribute references.

Text formatting.

Quoting,

Macros.

Replacements.

Special words.

Table cell separators.

But there are exceptions — see the next question.

37. Some elements can’t be escaped with a single backslash

There are a number of exceptions to the usual single backslash rule — mostly relating to URL macros that have two syntaxes or quoting
ambiguity. Here are some non-standard escape examples:

The source of this problem is ambiguity across substitution types — the first match unescapes allowing the second to substitute. A
work-around for difficult cases is to side-step the problem using the
pass:[] passthrough inline macro.

40. Why do I get a filter non-zero exit code error?

An error was returned when AsciiDoc tried to execute an external
filter command. The most common reason for this is that the filter
command could not be found by the command shell. To figure out what
the problem is run AsciiDoc with the --verbose option to determine
the command that is failing and then try to run the command manually
from the command-line.

41. Are there any DocBook viewers?

Yelp, the GNOME help viewer, does a
creditable job of displaying DocBook XML files directly.

42. Can you create ODF and PDF files using LibreOffice?

LibreOffice can convert HTML produced by
AsciiDoc to ODF text format and PDF format (I used LibreOffice 3.5 at
the time of writing, the fidelity is very good but it’s not perfect):

Create the HTML file using AsciiDoc, for example:

asciidoc -a icons -a numbered -a disable-javascript article.txt

JavaScript is disabled because LibreOffice does not execute
JavaScript, this means that AsciiDoc table of contents and footnotes
will not be rendered into ODF (if you want the table of contents and
footnotes you could manually cut and paste them from a Web browser).

Convert the HTML file to an ODF text file using LibreOffice:

lowriter --invisible --convert-to odt article.html

The images imported from an HTML file will be linked, if your document
contains images you should convert them to embedded images:

Open the document in LibreOffice Writer.

Run the Edit→Links… menu command.

Select all links and press the Break Link button.

Some images may also have been resized. To restore an image to its
original size:

Right-click on the image and select the Picture… menu item.

Click on the Crop tab.

Press the Original Size button.

Convert the ODF file to an PDF text file using LibreOffice:

lowriter --invisible --convert-to pdf article.odt

A PDF index is automatically created using the section headings.

Alternatively you could manually copy-and-paste the entire document
from a Web browser into a blank ODF document in LibreOffice — this
technique will bring through the table of contents and footnotes.

This tip was originally contributed by Bernard Amade.

43. How can I suppress cell separators in included table data files?

Use the {include:} system attribute instead of the include::[]
macro (the former is not expanded until after the table data has been
parsed into cells, whereas the latter is included before the table is
processed.

44. How can I preserve paragraph line boundaries?

Apply the The verse paragraph style, the rendered text preserves
line boundaries and is useful for lyrics and poems. For example:

If you are generating DocBook then a more flexible approach is to
create a docinfo file containing a DocBook authorgroup element
(search the User Guide for docinfo for more details).

51. How can I selectively disable a quoted text substitution?

Omitting the tag name will disable quoting. For example, if you don’t
want superscripts or subscripts then put the following in a custom
configuration file or edit the global asciidoc.conf configuration
file:

[quotes]
^=
~=

Alternatively you can set the configuration entries from within your
document, the above examples are equivalent to:

:quotes.^:
:quotes.~:

52. How can I customize the {localdate} format?

The default format for the {localdate} attribute is the ISO 8601
yyyy-mm-dd format. You can change this format by explicitly setting
the {localdate} attribute. For example by setting it using the
asciidoc(1)-a command-line option:

asciidoc -a localdate=`date +%d-%m-%Y` mydoc.txt

You could also set it by adding an Attribute Entry to your source
document, for example:

:localdate: {sys: date +%Y-%m-%d}

53. Where can I find examples of commands used to build output documents?

The User Guide has some. You could also look at ./doc/main.aap and
./examples/website/main.aap in the AsciiDoc distribution, they have
all the commands used to build the AsciiDoc documentation and the
AsciiDoc website (even if you don’t use A-A-P you’ll still find it
useful).

54. Why have you used the DocBook <simpara> element instead of <para>?

<simpara> is really the same as <para> except it can’t contain
block elements — this matches, more closely, the AsciiDoc paragraph
semantics.

55. How can I format text inside a listing block?

By default only specialcharacters and callouts are substituted in
listing blocks; you can add quotes substitutions by explicitly setting
the block subs attribute, for example:

Alternative, if the lines are contiguous, you could use the literal
paragraph style:

["literal",subs="quotes"]
$ ls *-al*

56. Why doesn’t the include1::[] macro work?

Internally the include1 macro is translated to the include1 system
attribute which means it must be evaluated in a region where attribute
substitution is enabled. include1 won’t work, for example, in a
ListingBlock (unless attribute substitution is enabled). include1
is intended for use in configuration files, use the include macro
and set the attribute depth=1 instead, for example:

57. How can I make the mailto macro work with multiple email addresses?

For the AsciiDoc mailto macro to work with multiple email addresses
(as per RFC2368) you need to URL encode the @ characters (replace
them with %40), if you don’t the individual addresses will be
rendered as separate links. You also need to replace spaces with %20.

You can apply the unbreakable option globally to all block
elements by defining the unbreakable-option attribute in your
document header.

Finally, the most powerful technique is to create custom CSS
containing paged media properties. For example this asciidoc(1)
command:

asciidoc --attribute stylesheet=article.css article.txt

Will include the following article.css file in the output document:

div#toc, div.sect1 { page-break-before: always; }

Which will ensure the table of contents and all top level sections
start on a new printed page.

60. Is it possible to reposition the Table of Contents in HTML outputs?

By default the xhtml11 and html5 backends auto-position the TOC
after the header. You can manually position the TOC by setting the
toc-placement attribute value to manual and then inserting the
toc::[] block macro where you want the TOC to appear. For example,
put this in the document header:

:toc:
:toc-placement: manual

The put this where you want the TOC to appear:

toc::[]

61. HTML generated by AsciiDoc fills the width of the browser, how can I limit it to a more readable book width?

You can set the maximum with for outputs generated by html5,
xhtml11 and slidy backends by assigning the
max-width attribute (either from the
command-line or with an attribute entry in the document header). For
example:

asciidoc -a max-width=55em article.txt

62. Using roles to select fonts for PDF

Some applications require mixing fonts beyond the set of faces
normally provided by default (normal, monospace, italic etc.) for
example mixed language text where the font used for the majority of
text does not contain suitable glyphs in the minority language.

As AsciiDoc can not provide presentation markup since it is not
provided by Docbook this is achieved by marking text which should use
a different font with a custom role which can be rendered by the the
docbook toolchain.

For XHTML outputs AsciiDoc translates the role attribute to a
class which can be selected and styled by CSS as described in the
AsciiDoc users guide.

The Docbook toolchains will have to be configured to render the text
that you mark with the custom role.

For FOP a small XSL wrapper is needed, say a file called my_fo.xsl
containing:

64. How can I convert documents from other formats to AsciiDoc?

65. How can I insert raw HTML in a document processed by a2x?

a2x generates HTML via DocBook (DocBook XSL Stylesheets) so if you
use a passthrough block it must contain DocBook (not HTML).
Fortunately DocBook XSL Stylesheets has a
dbhtml-include
processing instruction which will inlcude a file containing raw HTML
into the generated HTML output. For example:

++++
<?dbhtml-include href="snippet.html"?>
++++

66. Why is there a period after the block title in the PDF output?

If your document has blocks that have block titles, you may notice in
the PDF output (generated by a2x(1) using the --fop flag) that a
period gets added to the end of the block title.

You will not see the period in the intermediary DocBook XML that’s
generated when creating a PDF — it’s added by the DocBook XSL
templates when the DocBook XML is converted to FO XML.

The DocBook XSL attribute that controls what character is added after
a block title is
runinhead.default.title.end.punct. You can override it and eliminate
the default period value by adding the following line to the
./docbook-xsl/common.xsl file that ships with AsciiDoc: