source: rtems-tools/doc/asciidoc/examples/website/faq.txt @ f91e023

4.104.115
Last change on this file since f91e023 was f91e023, checked in by Chris Johns <chrisj@…>, on 02/17/14 at 07:04:46

Add the documentation.

  • Property mode set to 100644
File size: 44.4 KB
Line 
1AsciiDoc Frequently Asked Questions
2===================================
3
4
5NOTE: New FAQs are appended to the bottom of this document.
6
7/////////////////////////////////////////////////////////////////
8ADD NEW FAQS TO THE BOTTOM OF THIS DOCUMENT TO MAINTAIN NUMBERING
9/////////////////////////////////////////////////////////////////
10
11== How do you handle spaces in included file names?
12Spaces are not allowed in macro targets so this include macro will not
13be processed:
14
15  include::my document.txt[]
16
17The work-around is to replace the spaces with the `{sp}` (space
18character) attribute, for example:
19
20  include::my{sp}document.txt[]
21
22
23== How do I number all paragraphs?
24Some documents such as specifications and legalese require all
25paragraphs to be sequentially numbered through the document, and to be
26able to reference these numbers.
27
28This can be achieved by using the DocBook toolchain but numbering the
29paragraphs with AsciiDoc using a custom config file containing the
30following (see http://www.methods.co.nz/asciidoc/userguide.html#X27
31for ways to include such a file):
32
33---------------------------------------------------------------------
34[paragraph]
35<formalpara{id? id="{id}"}{role? role="{role}"}{id? xreflabel="{paracounter}"}><title>{title}</title><para>
36{title%}<simpara{id? id="{id}"}{role? role="{role}"}{id? xreflabel="{paracounter}"}>
37{paracounter} |
38{title%}</simpara>
39{title#}</para></formalpara>
40{counter2:paracounter}
41{empty}
42---------------------------------------------------------------------
43
44References to the paragraphs operate in the normal way, you label the
45paragraph:
46
47-----------------------------
48[[some_label_you_understand]]
49paragraph contents
50-----------------------------
51
52and reference it in the normal manner:
53
54-----------------------------
55<<some_label_you_understand>>
56-----------------------------
57
58The text of the reference will be the paragraph number.
59
60For this to work for HTML you have to generate it via the DocBook
61toolchain.
62
63
64== Sources of information on configuring DocBook toolchains
65DocBook is a content and structure markup language, therefore
66AsciiDoc generated DocBook markup is also limited to content and
67structure.  Layout and formatting definition is specific to the
68DocBook toolchain.
69
70The dblatex toolchain can be configured by setting parameters defined
71at http://dblatex.sourceforge.net/doc/manual/sec-params.html or for
72more complex styling by custom Latex stylesheets described at
73http://dblatex.sourceforge.net/doc/manual/sec-custom-latex.html.
74
75Similarly FOP can be configured by parameters described at
76http://sagehill.net/docbookxsl/OptionsPart.html and with custom xsl
77stylesheets generating formatting objects as described at
78http://sagehill.net/docbookxsl/CustomizingPart.html.
79
80
81[[X5]]
82== How can I include embedded fonts in an EPUB document?
83This is a two step process:
84
851. Declare the font files and their use in your document's CSS
86   stylesheet. For example:
87+
88[listing]
89.........................................
90@font-face {
91  font-family : LiberationSerif-Regular;
92  font-weight : normal;
93  font-style: normal;
94  src : url(LiberationSerif-Regular.ttf);
95}
96
97body {
98  font-family: LiberationSerif-Regular, serif;
99}
100.........................................
101
1022. Declare the font file as resource when you use `a2x(1)` to
103   compile the EPUB. For example:
104
105  a2x -f epub -d book --epubcheck --stylesheet epubtest.css --resource .ttf=application/x-font-ttf --resource LiberationSerif-Regular.ttf epubtest.txt
106
107[NOTE]
108======
109- Requires AsciiDoc 8.6.5 or better.
110- The True Type Font mimetype had to be declared explicitly with the
111  `--resource .ttf=application/x-font-ttf` option because it wasn't
112  registered on my Linux system.
113- In the above example the font file is in the same directory as the
114  AsciiDoc source file and is installed to the same relative location
115  in the EPUB archive OEBPS directory -- if your font file resides in
116  a different location you'll need to adjust the `--resource` option
117  accordingly (see the 'RESOURCES' section in the `a2x(1)` man page
118  for details).
119- The URL value of the CSS 'src' property is set to the destination
120  font file relative to the CSS file.
121- The `--resource` option allows you to inject any file (not just font
122  files) into the EPUB output document.
123- Using the CSS '@font-face' rule is a complex subject and is outside
124  the scope of this FAQ.
125- Many EPUB readers do not process embedded fonts.
126======
127
128
129== What's the difference between + quoted text and ` quoted monospaced text?
130`+` (plus) quoted text is implemented as an AsciiDoc 'quotes' whereas
131+`+ (grave accent or backtick) quoted text is implemented as an
132AsciiDoc 'inline literal' passthrough macro. The semantics are
133different:
134
1351. Inline passthrough macros are processed before any other inline
136   substitutions e.g. all of the following line will be processed as a
137   single inline passthrough and rendered as monospaced text (which is
138   not the intended result):
139+
140--
141  `single quoted text' and `monospaced quoted text`
142
143This line works as expected:
144
145  `single quoted text' and +monospaced quoted text+
146--
147
1482. Backtick quoted text is rendered literally i.e. no substitutions
149   are performed on the enclosed text.  Here are some examples that
150   would have to be escaped if plus quoting were used (<<X4,see
151   also>>):
152
153  The `++i` and `++j` auto-increments.
154  Paths `~/.vim` and `~/docs`.
155  The `__init__` method.
156  The `{id}` attribute.
157
158
159== Why is the generated HTML title element text invalid?
160Probably because your document title contains formatting that has
161generated HTML title markup. You can resolve this by explicitly
162defining the 'title' attribute in your document's header.
163
164
165== AsciiDoc sometimes generates invalid output markup, why?
166AsciiDoc is backend agnostic, the 'asciidoc' command has no knowledge
167of the syntax or structure of the backend format that it generates.
168Output document validation (syntactic and structural) should be
169performed separately by external validation tools. For example,
170AsciiDoc's 'a2x' toolchain command automatically performs validation
171checks using 'xmllint'.
172
173
174== The AsciiDoc toclevels attribute does not work with DocBook outputs, why?
175DocBook has no provision for specifying table of contents levels but
176you can set the TOC level further down the toolchain by passing the
177DocBook XSL Stylesheets
178http://docbook.sourceforge.net/release/xsl/current/doc/html/toc.section.depth.html[toc.section.depth]
179parameter to 'dblatex' (using the `--param` option) or 'xsltproc'
180(using the `--stringparam` option).  For example to show only chapter
181titles in the TOC of a 'book' document set 'toc.section.depth' to '0'.
182Increment the 'toc.section.depth' value to show more sub-section
183titles. If you are using 'a2x' you can set the options in the source
184file, for example:
185
186  // a2x: --xsltproc-opts "--stringparam toc.section.depth 0"
187  // a2x: --dblatex-opts "--param toc.section.depth=0"
188
189If the document is of type 'article' use the value '1' to show only
190top level section titles in the TOC, use the value '2' for two levels
191etc.
192
193
194== How can I include chapter and section tables of contents?
195DocBook outputs processed by DocBook XSL Stylesheets (either manually
196or via 'a2x') can generate additional separate section and chapter
197tables of contents using combinations of the
198http://www.sagehill.net/docbookxsl/TOCcontrol.html[TOC parameters].
199Here are some examples using combinations of the
200`generate.section.toc.level` and `toc.section.depth` DocBook XSL
201Stylesheets parameters:
202
203[cols="2*l,4",width="90%",frame="topbot",options="header"]
204|======================================================
205|generate.section.toc.level |toc.section.depth |
206|1 |
207|Single level book chapter TOCs or article section TOCs
208
209|1 | 3
210|Article section TOCs with two levels
211
212|1 | 2
213|Book chapter TOCs with two levels
214|======================================================
215
216
217== How can I customize the appearance of XHTML and EPUB documents generated by a2x?
218You can customize the appearance of an EPUB document with CSS.  See
219the link:publishing-ebooks-with-asciidoc.html[Sherlock Holmes eBook
220example] on the AsciiDoc website.
221
222
223== DocBook has many elements for document meta-data -- how can I use them from AsciiDoc?
224The 'docinfo', 'docinfo1' and 'docinfo2' attributes allow you include
225link:userguide.html#X97[document information files] containing DocBook
226XML into the header of the output file.
227
228
229== Do element titles automatically generate link captions?
230If you go the DocBook route then yes -- just omit the caption from the
231AsciiDoc 'xref' (`<<...>>`) macro. Both dblatex and DocBook XSL will
232use the target element's title text. Examples:
233
234[listing]
235..................................................................
236[[X1]]
237Section One
238-----------
239Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas
240ultrices justo porttitor augue. Vestibulum pretium. Donec porta
241
242See also <<X3>> (this link displays the text 'A titled paragraph').
243
244[id="X2",reftext="2nd section"]
245Section Two
246-----------
247See also <<X1>> (this link displays the text 'Section One').
248
249[[X3]]
250.A titled paragraph
251Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
252
253See also <<X2>> (this link displays the text '2nd section').
254..................................................................
255
256The AsciiDoc 'reftext' attribute has been used to explicitly set the
257link text to '2nd section' for 'Section Two'.
258
259
260== Can I define my own table styles?
261In addition to the built-in styles you can define your own. This
262(simplified) example for HTML backends defines a table style called
263'red' which sets the background cell color to red. First put the
264definition in a configuration file:
265
266[listing]
267.........................................
268[tabledef-default]
269red-style=tags="red"
270
271[tabletags-red]
272bodydata=<td style="background-color:red;">|</td>
273.........................................
274
275Now you can use the style name to style cells or columns (in this
276example we use an unambiguous shortened abbreviation 'r'):
277
278[listing]
279.........................................
280|==================================
281|Normal cell      r|Red cell
282|==================================
283.........................................
284
285
286== How can I add highlighted editorial comments to an AsciiDoc document?
287Both block and inline link:userguide.html#X25[comment lines] are
288displayed on the output if the 'showcomments' attribute is defined.
289Example:
290
291[listing]
292.........................................
293:showcomments:
294// A block comment line.
295
296Qui in magna commodo, est labitur dolorum an. Est ne magna primis
297// An inline comment line.
298adolescens.
299.........................................
300
301Is rendered as:
302
303:showcomments:
304// A block comment line.
305
306Qui in magna commodo, est labitur dolorum an. Est ne magna primis
307// An inline comment line.
308adolescens.
309
310NOTE: link:userguide.html#X26[Comment blocks] are never displayed.
311
312
313== What is the preferred file name extension for AsciiDoc files?
314The `.txt` http://en.wikipedia.org/wiki/Text_file[text file] extension
315is preferred, but it's just a convention and it's not enforced by the
316software.
317
318AsciiDoc source files are human readable
319http://en.wikipedia.org/wiki/Plain_text[plain text] files which is
320what the `.txt` extension is for. All text editors recognize and open
321files with a `.txt` extension. The `.txt` extension is universally
322recognized and unambiguous -- you are not left asking questions like
323``What on earth is this file with the funny extension?'', ``How do I
324open it?'' and ``Is it safe to open?''.
325
326
327== How can I generate numbered bibliographic entries?
328If your outputs are DocBook generated then adding the following inline
329macro to a custom configuration file will result in auto-incrementing
330bibliography entry numbers (instead of displaying the bibliographic
331identifiers):
332
333  [anchor3-inlinemacro]
334  <anchor id="{1}" xreflabel="[{counter:bibliography1}]"/>[{counter:bibliography2}]
335
336This FAQ submitted by Bela Hausmann.
337
338
339== How can I include lines of dashes inside a listing block?
340A line of four or more dashes will be mistaken for the ListingBlock
341terminator, one way round this problem is to use a LiteralBlock styled
342as a listing block. For example:
343
344  [listing]
345  ...........................
346  Lorum ipsum
347  -----------
348  ...........................
349
350
351== How can I customize PDF files generated by dblatex?
352
353There are a number of dblatex XSL parameters that can be used to
354customize PDF output. You can set them globally in the AsciiDoc
355`./dblatex/asciidoc-dblatex.xsl` configuration file or you can also
356pass them on the a2x(1) command-line. Here are some examples:
357
358The
359http://dblatex.sourceforge.net/doc/manual/latex.output.revhistory.html[latex.output.revhistory]
360parameter is used to suppress the revision history:
361
362  a2x -f pdf --dblatex-opts "-P latex.output.revhistory=0" doc/article.txt
363
364The
365http://dblatex.sourceforge.net/doc/manual/doc.layout.html[doc.layout]
366parameter is used to include the cover page and document body (i.e. excludes
367table of contents and index), the
368http://dblatex.sourceforge.net/doc/manual/doc.publisher.show.html[doc.publisher.show]
369parameter is used to exclude the cover page logo:
370
371  a2x -f pdf --dblatex-opts " -P doc.layout=\"coverpage mainmatter\" -P doc.publisher.show=0" doc/article.txt
372
373See also the
374http://dblatex.sourceforge.net/doc/manual/sec-params.html[dblatex XSL
375parameter reference].
376
377
378== How can I add lists of figures and tables to PDFs created by dblatex?
379Set the
380http://dblatex.sourceforge.net/doc/sec-custom.html[doc.lot.show XSL
381parameter] -- you can set it using the dblatex `--param` command-line
382option, for example:
383
384  a2x --dblatex-opts="--param=doc.lot.show=figure,table" doc/article.txt
385
386
387== How can I stop the document title being displayed?
388You could simply omit the document title, but this will result in a
389blank 'title' element in HTML outputs. If you want the HTML 'title'
390element to contain the document title then define the 'notitle'
391attribute (this will just suppress displaying the title), for example:
392
393  My document title
394  =================
395  :no title:
396
397
398== Why am I having trouble getting nested macros to work?
399The following example expands the 'image' inline macro, but the
400expansion contains double-quote characters which confuses the ensuing
401'footnoteref' macro expansion:
402
403  footnoteref:["F1","A footnote, with an image image:smallnew.png[]"]
404
405The solution is to use unquoted attribute values, replacing embedded
406commas with the comma character entity (`&#44;`):
407
408  footnoteref:[F1,A footnote&#44; with an image image:smallnew.png[]]
409
410Similarly, you can embed double-quote characters in unquoted attribute
411values using the `&#34;` character entity.
412
413
414== Why am I getting DocBook validation errors?
415Not all valid AsciiDoc source generates valid DocBook, for example
416'special sections' (abstract, preface, colophon, dedication,
417bibliography, glossary, appendix, index, synopsis) have different
418DocBook schema's to normal document sections. For example, a paragraph
419is illegal in a bibliography.
420
421Don't forget if your document is a book you need to specify the
422asciidoc `-d book` command option, if you don't an article DocBook
423document will be generated, possibly containing book specific
424sections, resulting in validation errors.
425
426
427== How can I disable special section titles?
428For example, you want to use 'References' as a normal section name but
429AsciiDoc is auto-magically generating a DocBook 'bibliography'
430section. All you need to do is explicitly specify the section template
431name, for example:
432
433  [sect1]
434  References
435  ----------
436
437
438== How can I insert XML processing instructions into output documents?
439Use an inline or block passthrough macros. This example inserts
440`<?dblatex bgcolor="#cceeff"?>` into the DocBook output generated by
441AsciiDoc:
442
443  pass::[<?dblatex bgcolor="#cceeff"?>]
444
445NOTE: XML processing instructions are specific to the application that
446processes the XML (the previous `dblatex` processing instruction is
447recognized by `dblatex(1)` when it processes the DocBook XML generated
448by Asciidoc).
449
450
451[[X4]]
452== How do I prevent double-quoted text being mistaken for an inline literal?
453Mixing doubled-quoted text with inline literal passthroughs can
454produce undesired results, for example, all of the following line is
455interpreted as an inline literal passthrough:
456
457  ``XXX'' `YYY`
458
459In this case the solution is to use monospace quoting instead of the
460inline literal:
461
462  ``XXX'' +YYY+
463
464Use the +\pass:[]+ macro if it's necessary to suppress
465substitutions in the monospaced text, for example:
466
467  ``XXX'' +pass:[don't `quote` me]+
468
469
470== How can I generate a single HTML document file containing images and CSS styles?
471With the advent of Internet Explorer 8 all major web browsers now
472support the
473http://en.wikipedia.org/wiki/Data:_URI_scheme[data URI scheme] for
474embedded images. The AsciiDoc 'xhtml11' and 'html5' backends supports
475the data URI scheme for embedded images and by default it embeds the
476CSS stylesheet. For example the following command will generate a
477single `article.html` file containing embedded images, admonition
478icons and the CSS stylesheet:
479
480  asciidoc -a data-uri -a icons article.txt
481
482
483== Are there any tools to help me understand what's going on inside AsciiDoc?
484
485AsciiDoc has a built-in trace mechanism which is controlled by the
486'trace' attribute; there is also the `--verbose` command-line option.
487These features are detailed in
488http://www.methods.co.nz/asciidoc/userguide.html#X82[Appendix G of the
489User Guide].
490
491
492== One-liner ifdef::[]'s are disproportionately verbose can they shortened?
493
494This is the response to a question posted on the AsciiDoc discussion
495list, it illustrates a number of useful techniques. The question arose
496because the source highlight filter language identifier for the C++
497language is `c++` when generating PDFs via dblatex (LaTeX listings
498package) or `cpp` when generating HTML (GNU source-highlight).
499
500Using straight `ifdef::[]` block macros we have:
501
502[listing]
503.........................................
504\ifdef::basebackend-docbook[]
505[source,c++]
506\endif::basebackend-docbook[]
507\ifdef::basebackend-html[]
508[source,cpp]
509\endif::basebackend-html[]
510-----------------------------------------
511class FooParser {
512public:
513        virtual void startDocument() = 0;
514        virtual void endDocument() = 0;
515};
516-----------------------------------------
517.........................................
518
519
520This can be shortened using the short form of the `ifdef::[]` macro:
521
522[listing]
523.........................................
524\ifdef::basebackend-docbook[[source,c++]]
525\ifdef::basebackend-html[[source,cpp]]
526-----------------------------------------
527class FooParser {
528public:
529        virtual void startDocument() = 0;
530        virtual void endDocument() = 0;
531};
532-----------------------------------------
533.........................................
534
535
536Using a conditional attribute instead of the `ifdef::[]` macro is even
537shorter:
538
539[listing]
540.........................................
541[source,{basebackend@docbook:c++:cpp}]
542-----------------------------------------
543class FooParser {
544public:
545        virtual void startDocument() = 0;
546        virtual void endDocument() = 0;
547};
548-----------------------------------------
549.........................................
550
551
552If you have a number of listings it makes sense to factor the
553conditional attribute to a normal attribute:
554
555[listing]
556.........................................
557:cpp: {basebackend@docbook:c++:cpp}
558
559[source,{cpp}]
560-----------------------------------------
561class FooParser {
562public:
563        virtual void startDocument() = 0;
564        virtual void endDocument() = 0;
565};
566-----------------------------------------
567.........................................
568
569
570Even shorter, set the default source highlight filter `language`
571attribute so you don't have to specify it every time:
572
573[listing]
574.........................................
575:language: {basebackend@docbook:c++:cpp}
576
577[source]
578-----------------------------------------
579class FooParser {
580public:
581        virtual void startDocument() = 0;
582        virtual void endDocument() = 0;
583};
584-----------------------------------------
585.........................................
586
587
588== Some of my inline passthroughs are not passed through, why?
589
590Most likely the passthrough encloses another passthrough with a higher
591precedence. For example trying to render this +\pass:[]+ with this
592+\`\pass:[]`+ results in a blank string because the +\pass:[]+
593passthrough evaluates first, instead use monospaced quoting  and escape
594the passthrough i.e. ++ \+\\pass:[]+ ++
595
596
597== How can I place an anchor (link target) on a list item?
598
599You can't use a 'BlockId' block element inside a list but you can use
600the syntactically identical 'anchor' inline macro. For example:
601
602---------------------
603one:: Item one.
604[[X2]]two:: Item two.
605three:: Item three.
606---------------------
607
608This *will not* work:
609
610---------------------
611one:: Item one.
612[[X2]]
613two:: Item two.
614three:: Item three.
615---------------------
616
617
618== How can I stop lists from nesting?
619
620If you place two lists with different syntax hard up against each
621other then the second list will be nested in the first. If you don't
622want the second list to be nested separate them with a comment line
623block macro. For example:
624
625-------------------
6261. List 1.
6272. List 1.
628
629//
630a. List 2.
631b. List 2.
632-------------------
633
634
635== Is it possible to include charts in AsciiDoc documents?
636
637There are a number of programs available that generate presentation
638charts from textual specification, for example
639http://home.gna.org/pychart/[Pychart] is a library for writing chart
640scripts in Python. Here's an example from the 'Pychart' documentation:
641
642.barchart.py
643---------------------------------------------------------------------
644#
645# Example bar chart (from Pychart documentation http://home.gna.org/pychart/).
646#
647from pychart import *
648theme.get_options()
649
650data = [(10, 20, 30, 5), (20, 65, 33, 5), (30, 55, 30, 5), (40, 45, 51, 7),
651        (50, 25, 27, 3), (60, 75, 30, 5), (70, 80, 42, 5), (80, 62, 32, 5),
652        (90, 42, 39, 5), (100, 32, 39, 4)]
653
654# The attribute y_coord=... tells that the Y axis values
655# should be taken from samples.
656# In this example, Y values will be [40,50,60,70,80].
657ar = area.T(y_coord = category_coord.T(data[3:8], 0),
658            x_grid_style=line_style.gray50_dash1,
659            x_grid_interval=20, x_range = (0,100),
660            x_axis=axis.X(label="X label"),
661            y_axis=axis.Y(label="Y label"),
662            bg_style = fill_style.gray90,
663            border_line_style = line_style.default,
664            legend = legend.T(loc=(80,10)))
665
666# Below call sets the default attributes for all bar plots.
667chart_object.set_defaults(bar_plot.T, direction="horizontal", data=data)
668
669# Attribute cluster=(0,3) tells that you are going to draw three bar
670# plots side by side.  The plot labeled "foo" will the leftmost (i.e.,
671# 0th out of 3).  Attribute hcol tells the column from which to
672# retrive sample values from.  It defaults to one.
673ar.add_plot(bar_plot.T(label="foo", cluster=(0,3)))
674ar.add_plot(bar_plot.T(label="bar", hcol=2, cluster=(1,3)))
675ar.add_plot(bar_plot.T(label="baz", hcol=3, cluster=(2,3)))
676ar.draw()
677---------------------------------------------------------------------
678
679To execute the script and include the generated chart image in your
680document add the following lines to the AsciiDoc source:
681
682---------------------------------------------------------------------
683// Generate chart image file.
684\sys2::[python "{indir}/barchart.py" --format=png --output="{outdir}/barchart.png" --scale=2]
685
686// Display chart image file.
687image::barchart.png[]
688---------------------------------------------------------------------
689
690[NOTE]
691=====================================================================
692- The `barchart.py` script is located in the same directory as the
693  AsciiDoc source file (`{indir}`).
694- The generated chart image file (`barchart.png`) is written to the
695  same directory as the output file (`{outdir}`).
696=====================================================================
697
698
699== How can I render indented paragraphs?
700
701Styling is backend dependent:
702
703[float]
704==== Create an indented paragraph style (xhtml11 and html5 backends)
705. Define an 'indented' paragraph style, for example, by putting this
706  in a custom configuration file:
707+
708---------------------------------------------------------------------
709[paradef-default]
710indented-style=template="indentedparagraph"
711
712[indentedparagraph]
713<div class="paragraph"{id? id="{id}"} style="text-indent:3em;">{title?<div class="title">{title}</div>}<p>
714|
715</p></div>
716---------------------------------------------------------------------
717
718. Now apply the 'indented' style to normal paragraphs, for example:
719+
720---------------------------------------------------------------------
721[indented]
722Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas
723ultrices justo porttitor augue. Vestibulum pretium. Donec porta
724vestibulum mi. Aliquam pede. Aenean lobortis lorem et lacus. Sed
725lacinia. Vivamus at lectus.
726---------------------------------------------------------------------
727
728[float]
729==== Use the role attribute (xhtml11 and html5 backends)
730. Add the following line to custom stylesheet:
731+
732---------------------------------------------------------------------
733div.paragraph.indented p {text-indent: 3em;}
734---------------------------------------------------------------------
735
736. Apply the 'role' attribute to indented paragraphs, for example:
737+
738---------------------------------------------------------------------
739[role="indented"]
740Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas
741ultrices justo porttitor augue. Vestibulum pretium. Donec porta
742vestibulum mi. Aliquam pede. Aenean lobortis lorem et lacus. Sed
743lacinia. Vivamus at lectus.
744---------------------------------------------------------------------
745
746. Include the custom stylesheet by setting the 'stylesheet' attribute
747  (either from the command-line or with an attribute entry in the
748  document header).
749
750[float]
751==== Use the role attribute (docbook backend)
752. Add the following line to the distributed `docbook-xsl.css`
753  stylesheet or include it in a custom stylesheet:
754+
755---------------------------------------------------------------------
756p.indented {text-indent: 3em;}
757---------------------------------------------------------------------
758
759. Apply the 'role' attribute to indented paragraphs, for example:
760+
761---------------------------------------------------------------------
762[role="indented"]
763Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas
764ultrices justo porttitor augue. Vestibulum pretium. Donec porta
765vestibulum mi. Aliquam pede. Aenean lobortis lorem et lacus. Sed
766lacinia. Vivamus at lectus.
767---------------------------------------------------------------------
768
769. If you have included the custom CSS in a separate stylesheet you
770  will need to specify the stylesheet file name (along with the
771  default `docbook-xsl.css` stylesheet file name) with the
772  `html.stylesheet` XSL parameter. If you are using 'a2x(1)' use the
773  `--stylesheet` option (it sets the `html.stylesheet` XSL parameter),
774  for example: `--stylesheet "docbook-xsl.css mycss.css"`.
775
776NOTE: This applies to HTML outputs not PDF. To achieve the same
777results with PDF outputs you will need to customize the DocBook XSL
778Stylesheets to render indented paragraphs from DocBook `simpara`
779elements containing the the `role="indented"` attribute.
780
781
782== Is there a way to set default table grid and frame attributes?
783
784You can set the 'grid' and 'frame' attributes globally in your
785document header with Attribute Entries or from the command-line using
786the `--attribute` option. In the following example tables that don't
787explicitly set the 'grid' and 'frame' values will default to 'all' and
788'topbot' respectively:
789
790---------------------------------------------------------------------
791:grid: all
792:frame: topbot
793---------------------------------------------------------------------
794
795TIP: This technique can be applied to any block element attribute
796(just beware of possible ambiguity, for example, table and image
797blocks both have a 'width' attribute).
798
799
800== How can I place a backslash character in front of an attribute reference without escaping the reference?
801
802Use the predefined `{backslash}` attribute reference instead of an
803actual backslash, for example if the `{projectname}` attribute has
804the value `foobar` then:
805
806  d:\data{backslash}{projectname}
807
808would be rendered as:
809
810  d:\data\foobar
811
812== How can I escape AsciiDoc markup?
813
814Most AsciiDoc inline elements can be suppressed by preceding them with
815a backslash character. These elements include:
816
817- Attribute references.
818- Text formatting.
819- Quoting,
820- Macros.
821- Replacements.
822- Special words.
823- Table cell separators.
824
825But there are exceptions -- see the next question.
826
827
828== Some elements can't be escaped with a single backslash
829
830There are a number of  exceptions to the usual single backslash rule
831-- mostly relating to URL macros that  have two syntaxes or quoting
832ambiguity.  Here are some non-standard escape examples:
833
834[cols="l,v",width="40%",frame="topbot",options="header"]
835|========================================
836|AsciiDoc | Renders
837
8382*|
839\srackham@methods.co.nz
840<\srackham@methods.co.nz>
841\mailto:[\srackham@methods.co.nz]
842
8432*|
844\http://www.foo1.co.nz
845\\http://www.foobar.com[]
846\\http://www.foobar.com[Foobar Limited]
847
8482*|
849A C\++ Library for C++
850\\``double-quotes''
851\*\*F**ile Open\...
852|========================================
853
854The source of this problem is ambiguity across substitution types --
855the first match unescapes allowing the second to substitute. A
856work-around for difficult cases is to side-step the problem using the
857+\pass:[]+ passthrough inline macro.
858
859NOTE: Escaping is unnecessary inside 'inline literal passthroughs'
860(backtick quoted text).
861
862
863== How can I escape a list?
864Here's how to handle situations where the first line of a paragraph is
865mistaken for a list item.
866
867[float]
868==== Numbered and bulleted lists
869Precede the bullet or index of the first list item with an `{empty}`
870attribute, for example:
871
872  {empty}- Qui in magna commodo est labitur dolorum an.  Est ne magna
873  primis adolescens.
874
875The predefined `{empty}` attribute is replaced by an empty string and
876ensures the first line is not mistaken for a bulleted list item.
877
878[float]
879==== Labeled lists
880Two colons or semicolons in a paragraph may be confused with a labeled
881list entry. Use the predefined `{two-colons}` and `{two-semicolons}`
882attributes to suppress this behavior, for example:
883
884  Qui in magna commodo{two-colons} est labitur dolorum an. Est ne
885  magna primis adolescens.
886
887Will be rendered as:
888
889Qui in magna commodo{two-colons} est labitur dolorum an. Est ne
890magna primis adolescens.
891
892
893== How can I set default list and tables styles?
894
895You can set the element's 'style' entry in a global or custom
896configuration file.
897
898This example this will horizontally style all labeled lists that don't
899have an explicit style attribute:
900
901----------------------------------
902[listdef-labeled]
903style=horizontal
904
905[listdef-labeled2]
906style=horizontal
907----------------------------------
908
909This example will put a top and bottom border on all tables that don't
910already have an explicit style attribute:
911
912----------------------------------
913[tabledef-default]
914style=topbot
915topbot-style=frame="topbot"
916----------------------------------
917
918Alternatively you can set the configuration entries from inside your
919document, the above examples are equivalent to:
920
921----------------------------------
922:listdef-labeled.style: horizontal
923:listdef-labeled2.style: horizontal
924
925:tabledef-default.topbot-style: frame="topbot"
926:tabledef-default.style: topbot
927----------------------------------
928
929
930== Why do I get a filter non-zero exit code error?
931
932An error was returned when AsciiDoc tried to execute an external
933filter command. The most common reason for this is that the filter
934command could not be found by the command shell. To figure out what
935the problem is run AsciiDoc with the `--verbose` option to determine
936the command that is failing and then try to run the command manually
937from the command-line.
938
939
940== Are there any DocBook viewers?
941
942http://live.gnome.org/Yelp[Yelp], the GNOME help viewer, does a
943creditable job of displaying DocBook XML files directly.
944
945
946== Can you create ODF and PDF files using LibreOffice?
947
948https://www.libreoffice.org/[LibreOffice] can convert HTML produced by
949AsciiDoc to ODF text format and PDF format (I used LibreOffice 3.5 at
950the time of writing, the fidelity is very good but it's not perfect):
951
952. Create the HTML file using AsciiDoc, for example:
953
954  asciidoc -a icons -a numbered -a disable-javascript article.txt
955+
956JavaScript is disabled because LibreOffice does not execute
957JavaScript, this means that AsciiDoc table of contents and footnotes
958will not be rendered into ODF (if you want the table of contents and
959footnotes you could manually cut and paste them from a Web browser).
960
961. Convert the HTML file to an ODF text file using LibreOffice:
962
963  lowriter --invisible --convert-to odt article.html
964+
965--
966The images imported from an HTML file will be linked, if your document
967contains images you should convert them to embedded images:
968
969[lowerroman]
970. Open the document in LibreOffice Writer.
971. Run the 'Edit->Links...' menu command.
972. Select all links and press the 'Break Link' button.
973
974Some images may also have been resized. To restore an image to its
975original size:
976
977[lowerroman]
978. Right-click on the image and select the 'Picture...' menu item.
979. Click on the 'Crop' tab.
980. Press the 'Original Size' button.
981
982--
983
984. Convert the ODF file to an PDF text file using LibreOffice:
985
986  lowriter --invisible --convert-to pdf article.odt
987+
988A PDF index is automatically created using the section headings.
989
990Alternatively you could manually copy-and-paste the entire document
991from a Web browser into a blank ODF document in LibreOffice -- this
992technique will bring through the table of contents and footnotes.
993
994This tip was originally contributed by Bernard Amade.
995
996
997== How can I suppress cell separators in included table data files?
998
999Use the `{include:}` system attribute instead of the `include::[]`
1000macro (the former is not expanded until after the table data has been
1001parsed into cells, whereas the latter is included before the table is
1002processed.
1003
1004
1005== How can I preserve paragraph line boundaries?
1006
1007Apply the The 'verse' paragraph style, the rendered text preserves
1008line boundaries and is useful for lyrics and poems.  For example:
1009
1010---------------------------------------------------------------------
1011[verse]
1012Consul *necessitatibus* per id,
1013consetetur, eu pro everti postulant
1014homero verear ea mea, qui.
1015---------------------------------------------------------------------
1016
1017Alternatively, if you are generating PDF files, you can use line
1018breaks. For example:
1019
1020---------------------------------------------------------------------
1021Consul *necessitatibus* per id, +
1022consetetur, eu pro everti postulant +
1023homero verear ea mea, qui.
1024---------------------------------------------------------------------
1025
1026
1027== How can I include non-breaking space characters?
1028
1029Use the non-breaking space character entity reference `&#160;` (see
1030the next question). You could also use the predefined `{nbsp}`
1031attribute reference.
1032
1033
1034== Can I include HTML and XML character entity references in my document?
1035
1036Yes, just enter the reference in your document. For example `&#946;`
1037will print a Greek small beta character &#946;
1038
1039
1040[[X1]]
1041== How do I include spaces in URLs?
1042
1043URL inline macro targets (addresses) cannot contain white space
1044characters. If you need spaces encode them as `%20`. For example:
1045
1046  image:large%20image.png[]
1047  http://www.foo.bar.com/an%20example%20document.html
1048
1049
1050== How can I get AsciiDoc to assign the correct DocBook language attribute?
1051
1052Set the AsciiDoc 'lang' attribute to the appropriate language code.
1053For example:
1054
1055  a2x -a lang=es doc/article.txt
1056
1057This will ensure that downstream DocBook processing will generate the
1058correct language specific document headings (things like table of
1059contents, revision history, figure and table captions, admonition
1060captions).
1061
1062
1063== How can I turn off table and image title numbering?
1064For HTML outputs set the 'caption' attribute to an empty string,
1065either globally:
1066
1067-------------------------
1068:caption:
1069-------------------------
1070
1071or on an element by element basis, for example:
1072
1073-------------------------
1074.Tiger
1075[caption=""]
1076image::images/tiger.png[]
1077-------------------------
1078
1079
1080== How can I assign multiple author names?
1081
1082A quick way to do this is put both authors in a single first name, for
1083example:
1084
1085---------------------------------------
1086My Document
1087===========
1088:Author: Bill_and_Ben_the_Flowerpot_Men
1089:Author Initials: BB & BC
1090---------------------------------------
1091
1092asciidoc(1) replaces the underscores with spaces.
1093
1094If you are generating DocBook then a  more flexible approach is to
1095create a 'docinfo' file containing a DocBook 'authorgroup' element
1096(search the 'User Guide' for 'docinfo' for more details).
1097
1098
1099== How can I selectively disable a quoted text substitution?
1100
1101Omitting the tag name will disable quoting. For example, if you don't
1102want superscripts or subscripts then put the following in a custom
1103configuration file or edit the global `asciidoc.conf` configuration
1104file:
1105
1106-------------------
1107[quotes]
1108^=
1109~=
1110-------------------
1111
1112Alternatively you can set the configuration entries from within your
1113document, the above examples are equivalent to:
1114
1115-------------------
1116:quotes.^:
1117:quotes.~:
1118-------------------
1119
1120
1121== How can I customize the \{localdate} format?
1122
1123The default format for the `{localdate}` attribute is the ISO 8601
1124`yyyy-mm-dd` format. You can change this format by explicitly setting
1125the `{localdate}` attribute. For example by setting it using the
1126asciidoc(1) `-a` command-line option:
1127
1128  asciidoc -a localdate=`date +%d-%m-%Y` mydoc.txt
1129
1130You could also set it by adding an Attribute Entry to your source
1131document, for example:
1132
1133  :localdate: {sys: date +%Y-%m-%d}
1134
1135
1136== Where can I find examples of commands used to build output documents?
1137
1138The User Guide has some. You could also look at `./doc/main.aap` and
1139`./examples/website/main.aap` in the AsciiDoc distribution, they have
1140all the commands used to build the AsciiDoc documentation and the
1141AsciiDoc website (even if you don't use A-A-P you'll still find it
1142useful).
1143
1144
1145== Why have you used the DocBook <simpara> element instead of <para>?
1146
1147`<simpara>` is really the same as `<para>` except it can't contain
1148block elements -- this matches, more closely, the AsciiDoc paragraph
1149semantics.
1150
1151
1152== How can I format text inside a listing block?
1153
1154By default only 'specialcharacters' and 'callouts' are substituted in
1155listing blocks; you can add quotes substitutions by explicitly setting
1156the block 'subs' attribute, for example:
1157
1158[listing]
1159..........................................
1160[subs="quotes"]
1161------------------------------------------
1162$ ls *-al*
1163------------------------------------------
1164..........................................
1165
1166The `-al` will rendered bold. Note that:
1167
1168- You would need to explicitly escape text you didn't want quoted.
1169- Don't do this in source code listing blocks because it modifies the
1170  source code which confuses the syntax highlighter.
1171- This only works if your DocBook processor recognizes DocBook
1172  `<emphasis>` elements inside `<screen>` elements.
1173
1174Alternative, if the lines are contiguous, you could use the 'literal'
1175paragraph style:
1176
1177------------------------------------------
1178["literal",subs="quotes"]
1179$ ls *-al*
1180------------------------------------------
1181
1182
1183== Why doesn't the include1::[] macro work?
1184
1185Internally the `include1` macro is translated to the `include1` system
1186attribute which means it must be evaluated in a region where attribute
1187substitution is enabled. `include1` won't work, for example, in a
1188ListingBlock (unless attribute substitution is enabled).  `include1`
1189is intended for use in configuration files, use the `include` macro
1190and set the attribute `depth=1` instead, for example:
1191
1192[listing]
1193................................................
1194------------------------------------------------
1195\include::blogpost_media_processing.txt[depth=1]
1196------------------------------------------------
1197................................................
1198
1199
1200== How can I make the mailto macro work with multiple email addresses?
1201
1202For the AsciiDoc 'mailto' macro to work with multiple email addresses
1203(as per RFC2368) you need to URL encode the '@' characters (replace
1204them with '%40'), if you don't the individual addresses will be
1205rendered as separate links. You also need to <<X1,replace spaces with
1206'%20'>>.
1207
1208For example, the following call won't work:
1209
1210  mailto:jb@foobar.com,jd@acme.co.nz?subject=New foofoo release[New foofoo release]
1211
1212Use this instead:
1213
1214  mailto:jb%40foobar.com,jd%40acme.co.nz?subject=New%20foofoo%20release[New foofoo release]
1215
1216
1217== How can a replacement have a trailing backslash?
1218Quote the entry name -- this nonsensical example replaces `x\` with
1219`y`:
1220
1221  "x\\"=y
1222
1223If quoting were omitted the equals character (separating the
1224entry name `x` from the value `y`) would be escaped.
1225
1226
1227== How can I control page breaks when printing HTML outputs?
1228Here are some techniques you can use to control page breaks in HTML
1229outputs produced by the 'xhtml11' and 'html5' backends:
1230
1231- You can generate a page break with the '<<<' block macro. The
1232  following example prints the 'Rats and Mice' section on a new page:
1233+
1234----------------
1235<<<
1236== Rats and Mice
1237Lorum ipsum ...
1238----------------
1239
1240- You can use the 'unbreakable' option to instruct the browser not to
1241  break a block element. The following image and it's caption will be
1242  kept together the printed page:
1243+
1244------------------------------------
1245[options="unbreakable"]
1246.Tiger block image
1247image::images/tiger.png[Tiger image]
1248------------------------------------
1249
1250- You can apply the 'unbreakable' option globally to all block
1251  elements by defining the 'unbreakable-option' attribute in your
1252  document header.
1253
1254- Finally, the most powerful technique is to create custom CSS
1255  containing paged media properties. For example this asciidoc(1)
1256  command:
1257+
1258--
1259
1260  asciidoc --attribute stylesheet=article.css article.txt
1261
1262Will include the following `article.css` file in the output document:
1263
1264-------------------------------------------------
1265div#toc, div.sect1 { page-break-before: always; }
1266-------------------------------------------------
1267
1268Which will ensure the table of contents and all top level sections
1269start on a new printed page.
1270--
1271
1272
1273== Is it possible to reposition the Table of Contents in HTML outputs?
1274By default the 'xhtml11' and 'html5' backends auto-position the TOC
1275after the header. You can manually position the TOC by setting the
1276'toc-placement' attribute value to 'manual' and then inserting the
1277`toc::[]` block macro where you want the TOC to appear. For example,
1278put this in the document header:
1279
1280----------------------
1281:toc:
1282:toc-placement: manual
1283----------------------
1284
1285The put this where you want the TOC to appear:
1286
1287-------
1288toc::[]
1289-------
1290
1291
1292== HTML generated by AsciiDoc fills the width of the browser, how can I limit it to a more readable book width?
1293You can set the maximum with for outputs generated by 'html5',
1294'xhtml11' and 'slidy' backends by assigning the
1295link:userguide.html#X103[max-width] attribute (either from the
1296command-line or with an attribute entry in the document header). For
1297example:
1298
1299  asciidoc -a max-width=55em article.txt
1300
1301
1302== Using roles to select fonts for PDF
1303Some applications require mixing fonts beyond the set of faces
1304normally provided by default (normal, monospace, italic etc.) for
1305example mixed language text where the font used for the majority of
1306text does not contain suitable glyphs in the minority language.
1307
1308As AsciiDoc can not provide presentation markup since it is not
1309provided by Docbook this is achieved by marking text which should use
1310a different font with a custom role which can be rendered by the the
1311docbook toolchain.
1312
1313NOTE: For XHTML outputs AsciiDoc translates the role attribute to a
1314class which can be selected and styled by CSS as described in the
1315AsciiDoc users guide.
1316
1317The Docbook toolchains will have to be configured to render the text
1318that you mark with the custom role.
1319
1320For FOP a small XSL wrapper is needed, say a file called `my_fo.xsl`
1321containing:
1322
1323---------------------------------------------------------------
1324<xsl:stylesheet version="1.0"
1325               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1326               xmlns:fo="http://www.w3.org/1999/XSL/Format">
1327 <xsl:import href="/etc/asciidoc/docbook-xsl/fo.xsl"/>
1328 <xsl:template match="phrase[@role='f2']">
1329   <fo:inline font-family="the font for f2">
1330     <xsl:apply-templates/>
1331   </fo:inline>
1332 </xsl:template>
1333</xsl:stylesheet>
1334---------------------------------------------------------------
1335
1336This is used with `a2x` by:
1337
1338  a2x -f pdf --fop --xsl-file=my_fo.xsl input.txt
1339
1340and the AsciiDoc source marked by:
1341
1342  normal text [f2]#special font is like this# and back to normal
1343
1344Thanks to Antonio Borneo for this answer.
1345
1346
1347== How can I place a footnote immediately following quoted text?
1348A closing quote is not recognised if it is immediately followed by a
1349letter (the 'f' in 'footnote' in the following example):
1350
1351  ``Double-quoted text''footnote:[Lorum ipsum...]
1352
1353A workaround is to put a word-joiner between the trailing quote
1354and the footnote (the `{empty}` attribute would also work), for
1355example:
1356
1357  ``Double-quoted text''{wj}footnote:[Lorum ipsum...]
1358
Note: See TracBrowser for help on using the repository browser.