This chapter explains in concrete, practical terms how to make DocBook documents. It's an overview of all the kinds of markup that are possible in DocBook documents. It explains how to create several kinds of DocBook documents: books, sets of books, chapters, articles, and reference manual entries. The idea is to give you enough basic information to actually start writing. The information here is intentionally skeletal; you can find “the details” in the reference section of this book.
An XML consists of an optional XML Declaration, an optional Document Type Declaration, which includes an optional Internal Subset, and a Document (or Root) Element. If you're used to using a DTD, many of these will be familiar to you. If you're using the RELAX NG version of DocBook, many of your documents will omit the Document Type Declaration.
XML documents often begin with an XML declaration that identifies a few simple aspects of the document:
<?xml version="1.0" encoding="utf-8"?>
Identifying the version of XML ensures that future changes to the XML specification will not alter the semantics of this document. The encoding declaration tells the processor what character encoding your document uses. It must match the actual encoding that you use. The complete details of the XML declaration are described in the XML specification.
If your document uses XML 1.0 and an encoding of either utf-8
or utf-16
, the XML Declaration is not required.
But it is never wrong to include it.
XML documents don't require a DTD and if you are using RELAX NG, often they will not include one. Historically, DocBook XML documents have almost always had one.
The document type declaration identifies the DTD that will be used by the document and what the root element of the document will be. A typical doctype declaration for a DocBook V4.4 document looks like this:
<?xml version='1.0'?> <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
This declaration indicates that the root element will be
book
and that the DTD
used will be DocBook V4.4. External
declarations in XML must include a system
identifier (the public identifier is optional). In this example, the
DTD is stored on a web server.
System identifiers in XML must be
URIs. Many systems may accept filenames and
interpret them locally as file:
URLs, but it's always correct to fully qualify
them.
DocBook V5.0 documents can be validated with a DTD:
<?xml version='1.0'?> <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V5.0//EN" "http://www.oasis-open.org/docbook/xml/5.0/docbook.dtd">
But the limited constraints that can be expressed in DTDs mean that the resulting document may or may not really be valid DocBook V5.0. The normative schema for DocBook V5.0 is the RELAX NG Grammar with its Schematron annotations.
It's also possible to provide additional declarations in a document by placing them inside the document type declaration:
<?xml version='1.0'?> <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V5.0/EN" "http://www.oasis-open.org/docbook/xml/5.0/docbook.dtd" [ <!ENTITY nwalsh "Norman Walsh"> <!ENTITY chap1 SYSTEM "chap1.sgm"> <!ENTITY chap2 SYSTEM "chap2.sgm"> ]>
These declarations form what is known as the internal subset.
The declarations stored in the file referenced by the public or system
identifier in the DOCTYPE
declaration is called the
external subset, which is technically optional. It is legal to put the
DTD in the internal subset and to have no external
subset, which often makes sense documents that will be validated with
RELAX NG:
<?xml version='1.0'?> <!DOCTYPE book [ <!ENTITY nwalsh "Norman Walsh"> <!ENTITY chap1 SYSTEM "chap1.sgm"> <!ENTITY chap2 SYSTEM "chap2.sgm"> ]>
All XML documents must have exactly one root element, although it may have sibling comments and processing instructions. If the document has a document type declaration, the root element usually immediately follows it:
<?xml version='1.0'?> <!DOCTYPE book [ <!ENTITY nwalsh "Norman Walsh"> <!ENTITY chap1 SYSTEM "chap1.sgm"> <!ENTITY chap2 SYSTEM "chap2.sgm"> ]> <book>…</book>
The important point is that the root element must be physically present immediately after the document type declaration. You cannot place the root element of the document in an external entity.
If you are entering XML using a text editor such as Emacs or vi, there are a few things to keep in mind. Using a structured text editor designed for XML hides most of these issues.
In XML, all markup is case-sensitive. In DocBook, you must always type all element, attribute, and entity names in lowercase.
You are required to quote all attribute values in XML.
When quoting attribute values, you can use either a straight single quote ('), or a straight double quote ("). Don't use the “curly” quotes (“ and ”) in your editing tool.
Empty elements in XML are marked with a
distinctive syntax: <xref/>
.
Processing instructions in XML begin
and end with a question mark: <?pitarget
data?>
.
When a DTD or other external file is referenced from a document, the reference can be specified in three ways: using a public identifier, a system identifier, or both. In XML, the system identifier is required and the public identifier is optional.
A public identifier is a globally unique, abstract name, such as the following, which is the official public identifier for DocBook V5.0:
-//OASIS//DTD DocBook V5.0//EN
In XML the system identifier must be a Uniform Resource Indicator (URI). The most common URI today is the Uniform Resource Locator (URL), which is familiar to anyone who browses the Web.
The advantage of using a public identifier is that it makes your documents more portable. For any system on which DocBook is installed, the public identifier will resolve to the appropriate local version of the DTD (if public identifiers can be resolved at all).
Public identifiers have two disadvantages:
Because XML does not require them, and because system identifiers are required, developing XML tools may not provide adequate support for public identifiers. To work with these systems you must use system identifiers.
Public identifiers aren't magic. They're simply a method of indirection. For them to work, there must be a resolution mechanism for public identifiers. Luckily, there are standards that define mechanisms for mapping public identifiers to system identifers using catalog files.
See OASIS Technical Resolution 9401:1997 (Amendment 2 to TR 9401). or FIXME: link to XML Catalogs.
An important characteristic of public identifiers is that they are globally unique. Referring to a document with a public identifier should mean that the identifier will resolve to the same actual document on any system even though the location of that document on each system may vary. As a rule, you should never reuse public identifiers, and a published revision should have a new public identifier. Not following these rules defeats one purpose of the public identifier.
A public identifier can be any string of upper- and lowercase letters, digits, any of the following symbols: “'”, “(“, “)”, “+”, “,”, “-”, “.”, “/”, “:”, “=”, “?”, and white space, including line breaks.
Most public identifiers conform to the ISO 8879 standard that defines formal public identifiers. Formal public identifiers, frequently referred to as FPI, have a prescribed format that can ensure uniqueness:[1]
prefix
//owner-identifier
//text-class
text-description
//language
//display-version
Here are descriptions of the identifiers in this string:
prefix
The prefix
is either a
“+
” or a “-
” Registered public
identifiers begin with “+
”; unregistered
identifiers begin with “-
”.
(ISO standards sometimes use a third form
beginning with ISO
and the standard number, but
this form is only available to ISO.)
The purpose of registration is to guarantee a unique owner-identifier. There are few authorities with the power to issue registered public identifiers, so in practice unregistered identifiers are more common.
The Graphics Communication Association (GCA) can assign registered public identifiers. They do this by issuing the applicant a unique string and declaring the format of the owner identifier. For example, the Davenport Group was issued the string “A00002” and could have published DocBook using an FPI of the following form:
+//ISO/IEC 9070/RA::A00002//...
Another way to use a registered public identifier is to use the format reserved for internet domain names. For example, O'Reilly can issue documents using an FPI of the following form:
+//IDN oreilly.com//...
As of DocBook V3.1, the OASIS Technical
Committee responsible for DocBook has elected to use the unregistered
owner identifier, OASIS
, thus its prefix is
-
.
-//OASIS//...
owner-identifier
Identifies the person or organization that owns the identifier. Registration guarantees a unique owner identifier. Short of registration, some effort should be made to ensure that the owner identifier is globally unique. A company name, for example, is a reasonable choice as are Internet domain names. It's also not uncommon to see the names of individuals used as the owner-identifier, although clearly this may introduce collisions over time.
The owner-identifier for DocBook V3.1 is
OASIS
. Earlier versions used the owner-identifier
Davenport
.
text-class
The text class identifies the kind of document that is associated with this public identifier. Common text classes are
An SGML or XML document.
A DTD or part of a DTD.
A collection of element declarations.
A collection of entity declarations.
Data that is not in SGML or XML.
DocBook is a DTD, thus its text class is DTD.
text-description
This field provides a description of the document. The text description is free-form, but cannot include the string //.
The text description of DocBook is DocBook V5.0
.
In the uncommon case of unavailable public texts (FPIs for proprietary DTDs, for example), there are a few other options available (technically in front of or in place of the text description), but they're rarely used.[2]
language
Indicates the language in which the document is written. It is recommended that the ISO standard two-letter language codes be used if possible.
DocBook is an English-language DTD, thus its
language is EN
.
display-version
This field, which is not frequently used, distinguishes between public texts that are the same except for the display device or system to which they apply.
For example, the FPI for the ISO Latin 1 character set is:
-//ISO 8879-1986//ENTITIES Added Latin 1//EN
A reasonable FPI for an XML version of this character set is:
-//ISO 8879-1986//ENTITIES Added Latin 1//EN//XML
System identifiers are usually filenames on the local system. In SGML, there's no constraint on what they can be. Anything that your SGML processing system recognizes is allowed. In XML, system identifiers must be URIs (Uniform Resource Identifiers).
The use of URIs as system identifiers introduces the possibility that a system identifier can be a URN. This allows the system identifier to benefit from the same global uniqueness benefit as the public identifier. It seems likely that XML system identifiers will eventually move in this direction.
The rest of this chapter describes how you can break documents into logical chunks, such as books, chapters, sections, and so on. Before we begin, and while the subject of the internal subset is fresh in your mind, let's take a quick look at how to break documents into separate physical chunks.
Actually, we've already told you how to do it. If you recall, in the preceding sections we had declarations of the form:
<!ENTITYname
SYSTEM "filename
">
If you refer to the entity name
in your document after this declaration, the system will insert the
contents of the file filename
into your
document at that point. So, if you've got a book that consists of
three chapters and two appendixes, you might create a file called
book.sgm
, which looks like this:
<!DOCTYPE book [ <!ENTITY chap1 SYSTEM "chap1.sgm"> <!ENTITY chap2 SYSTEM "chap2.sgm"> <!ENTITY chap3 SYSTEM "chap3.sgm"> <!ENTITY appa SYSTEM "appa.sgm"> <!ENTITY appb SYSTEM "appb.sgm"> ]> <book><title>My First Book</title> &chap1; &chap2; &chap3; &appa; &appb; </book>
You can then write the chapters and appendixes conveniently in separate files. Note that these files do not and must not have document type declarations.
For example, Chapter 1 might begin like this:
<chapter id="ch1"><title>My First Chapter</title> <para>My first paragraph.</para> …
But it should not begin with its own document type declaration:
<!DOCTYPE chapter> <chapter id="ch1"><title>My First Chapter</title> <para>My first paragraph.</para> …
It is also possible to construct documents from physical chunks using XInclude. FIXME: say more about xinclude.
DocBook elements can be divided broadly into these categories:
Sets |
Books |
Divisions, which divide books into parts |
Components, which divide books or divisions into chapters |
Sections, which subdivide components |
Meta-information elements |
Block elements |
Inline elements |
In the rest of this section, we'll describe briefly the elements that make up these categories. This section is designed to give you an overview. It is not an exhaustive list of every element in DocBook.
For more information about any specific element and the elements that it may contain, consult the reference page for the element in question.
A set
contains two or more
book
s. It's the hierarchical top of DocBook. You
use the set
tag, for example, for a series of books
on a single subject that you want to access and maintain as a single
unit, such as the manuals for an airplane engine or the documentation
for a programming language.
A book
is probably the most common top-level
element in a document. The DocBook definition of a book is very loose
and general. Given the variety of books authored with DocBook and the
number of different conventions for book organization used in
countries around the world, attempting to impose a strict ordering of
elements can make the content model extremely complex. But DocBook
gives you free reign. It's very reasonable to use a local Chapter 5, Customizing DocBook to impose a more strict ordering for your
applications.
A book
consists of a mixture of the following elements:
The dedication
pages almost always occur at the front of
a book.
There are a couple of component-level elements designed for
navigation: toc
, for Tables of Contents and Lists of Titles
(for lists of figures, tables, examples, and so
on); and index
, for indexes.
Divisions are the first hierarchical level below
book
. They contain part
s and
reference
s. A part
, in turn, contains components.
A reference
contains refentry
s. These are
discussed more thoroughly in the section called “Making a Reference Page””.
Books can contain components directly and are not required to contain divisions.
These are the chapter-like elements of a book
.
Components are the chapter-like elements of a
book
or part
: preface
,
chapter
, appendix
, glossary
, and
bibliography
. An article
can also occur at the
component level. We describe article
s in more detail in the
section titled the section called “Making an Article””. Components generally
contain block elements and/or sections, and some can contain
navigational components and refentry
s.
There are several flavors of sectioning elements in DocBook:
sect1
…sect5
elementsThe sect1
…sect5
elements are the most common sectioning elements. They can occur in
most component-level elements. These numbered section elements must be
properly nested (sect2
s can only occur inside
sect1
s, sect3
s can only occur inside
sect2
s, and so on). There are five levels of numbered
sections.
section
elementThe section
element is an alternative to
numbered sections. The section
elements are recursive,
meaning that you can nest them to any depth desired.
simplesect
elementIn addition to numbered sections, there's the
simplesect
element. It is a terminal section that can occur
at any level, but it cannot have any other sectioning element nested
within it.
The distinguishing feature of simplesect
is that it
does not occur in the Table of Contents.
bridgehead
A bridgehead
provides a section title without
any containing section.
refsect1
…refsect3
elementsThese elements, which occur only in refentry
s,
are analogous to the numbered section elements in components. There
are only three levels of numbered section elements in a
refentry
.
glossdiv
, bibliodiv
, and
indexdiv
The glossary
, bibliography
,
and index
elements can be broken into top-level
divisions, but not sections. Unlike sections, these elements do not
nest.
All of the elements at the section level and above, and
many block elements further down, include a wrapper
for meta-information about the content. That element is named
info
. In earlier versions of DocBook, there were many
similarly named elements for this purpose, bookinfo
,
chapterinfo
, etc. In DocBook V5.0, there is only one.
The meta-information wrapper is designed to contain
bibliographic information about the content (author
,
title
, publisher
, and so on) as well as other
meta-information such as revision histories, keyword sets, and index
terms.
The block elements occur immediately below the component and sectioning elements. These are the (roughly) paragraph-level elements in DocBook. They can be divided into a number of categories: lists, admonitions, line-specific environments, synopses of several sorts, tables, figures, examples, and a dozen or more miscellaneous elements.
There are eight list elements in DocBook:
calloutlist
A list of callout
s and their descriptions.
The callout
s are marks, frequently numbered and typically on a
graphic or verbatim environment, that are described in a
calloutlist
, outside the element in which they
occur.
bibliolist
glosslist
itemizedlist
An unordered (bulleted) list. There are attributes to control the marks used.
orderedlist
A numbered list. There are attributes to control the type of enumeration.
segmentedlist
A repeating set of named items. For example, a list of
states and their capitals might be represented as a
segmentedlist
.
simplelist
An unadorned list of items. simplelist
s can be
inline or arranged in columns.
variablelist
A list of terms and definitions or descriptions. (This
list of list types is a variablelist
.)
There are five types of admonitions in DocBook:
caution
, important
, note
,
tip
, and warning
.
All of the admonitions have the same structure: an optional
title
followed by paragraph-level elements. DocBook does
not impose any specific semantics on the individual admonitions. For
example, DocBook does not mandate that warning
s be reserved
for cases where bodily harm can result.
These environments preserve whitespace and line breaks in the source text. DocBook does not provide the equivalent of HTML's br tag, so there's no way to interject a line break into normal running text.
address
The address
element is intended for postal
addresses. In addition to being line-specific, address
contains additional elements suitable for marking up names and
addresses.
literallayout
A literallayout
does not have any semantic
association beyond the preservation of whitespace and line breaks. In
particular, while programlisting
and
screen
are frequently presented in a fixed-width
font, a change of fonts is not necessarily implied by
literallayout
.
programlisting
A programlisting
is a verbatim environment, usually
presented in Courier or some other fixed-width font, for program
sources, code fragments, and similar listings.
screen
A screen
is a verbatim or literal environment
for text screen-captures, other fragments of an
ASCII display, and similar things. screen
is also a frequent catch-all for any verbatim
text.
screenshot
screenshot
is actually a wrapper for a
mediaobject
intended for screen shots of a
GUI for example.
synopsis
A synopsis
is a verbatim environment for command
and function synopsis.
Examples, Figures, and Tables are common block-level elements:
example
, informalexample
,
figure
, informalfigure
,
table
, and informaltable
.
The distinction between formal and informal elements is that formal
elements have titles while informal ones do not. The
informalfigure
element was introduced in DocBook
V3.1. In prior versions of DocBook, you could only
achieve the effect of an informal figure by placing its content,
unwrapped, at the location where the informal figure was desired.
There are three paragraph elements: para
, simpara
(simple paragraphs may not contain other block-level
elements), and formalpara
(formal paragraphs have
titles).
There are two block-equation elements, equation
and
informalequation
(for inline equations, use
inlineequation
).
Informal equations don't have titles. For reasons of
backward-compatibility, equation
s are not required
to have titles. However, it may be more difficult for some stylesheet
languages to properly enumerate equation
s if they
lack titles.
Graphics occur most frequently in figure
s and
screenshot
s, but they can also occur without a
wrapper. DocBook considers a mediaobject
a block
element, even if it appears to occur inline. For graphics that you
want to be represented inline, use inlinemediaobject
.
DocBook V3.1 introduced a new element to contain
graphics and other media types: mediaobject
and its inline
cousin, inlinemediaobject
. These elements may contain
video, audio, image, and text data. A single media object can contain
several alternative forms from which the presentation system can
select the most appropriate object.
DocBook V3.1 introduced the qandaset
element, which is suitable for FAQs (Frequently
Asked Questions) and other similar collections of
question
s and answer
s.
The following block elements are also available:
blockquote
A block quotation. Block quotations may have
attribution
s.
cmdsynopsis
An environment for marking up all the parameters and options of a command.
epigraph
A short introduction, typically a quotation, at the beginning of a document.
epigraph
s may have attribution
s.
funcsynopsis
An environment for marking up the return value and arguments of a function.
msgset
procedure
A procedure. Procedures contain step
s, which
may contain substeps
.
sidebar
A sidebar.
Users of DocBook are provided with a surfeit of inline elements. Inline elements are used to mark up running text. In published documents, inline elements often cause a font change or other small change, but they do not cause line or paragraph breaks.
In practice, writers generally settle on the tagging of inline elements that suits their time and subject matter. This may be a large number of elements or only a handful. What is important is that you choose to mark up not every possible item, but only those for which distinctive tagging will be useful in the production of the finished document for the readers who will search through it.
The following comprehensive list may be a useful tool for the process of narrowing down the elements that you will choose to mark up; it is not intended to overwhelm you by its sheer length. For convenience, we've divided the inlines into several subcategories.
The classification used here is not meant to be authoritative, only helpful in providing a feel for the nature of the inlines. Several elements appear in more than one category, and arguments could be made to support the placement of additional elements in other categories or entirely new categories.
These inlines identify things that commonly occur in general writing:
abbrev
acronym
An often pronounceable word made from the initial (or selected) letters of a name or phrase.
emphasis
footnote
A footnote. The location of the footnote
element identifies the location of the first reference to the
footnote. Additional references to the same footnote can be inserted with
footnoteref
.
phrase
quote
trademark
The cross reference inlines identify both explicit cross references,
such as link
, and implicit cross references like
glossterm
. You can make the most of the implicit
references explicit with a linkend
attribute.
These inlines are used to mark up text for special presentation:
foreignphrase
A word or phrase in a language other than the primary language of the document.
wordasword
A word meant specifically as a word and not representing anything else.
computeroutput
literal
markup
A string of formatting markup in text that is to be represented literally.
prompt
A character or string indicating the start of an input field in a computer display.
replaceable
tag
userinput
DocBook does not define a complete set of elements for representing equations. No one has ever pressed the DocBook maintainers to add this functionality, and the prevailing opinion is that incorporating MathML using a mechanism like namespaces is probably the best long-term solution.
inlineequation
subscript
superscript
A superscript (as in x^2, the mathematical notation for x multiplied by itself).
These elements describe aspects of a user interface:
accel
guibutton
guiicon
guilabel
The text of a label in a GUI.
guimenu
guimenuitem
guisubmenu
keycap
keycode
The internal, frequently numeric, identifier for a key on a keyboard.
keycombo
keysym
menuchoice
mousebutton
shortcut
A key combination for an action that is also accessible through a menu.
Many of the technical inlines in DocBook are related to programming.
classname
The name of a class, in the object-oriented programming sense.
constant
errorcode
errorname
errortype
function
The name of a function or subroutine, as in a programming language.
literal
msgtext
parameter
property
A unit of data associated with some part of a computer system.
replaceable
returnvalue
symbol
token
type
varname
These inlines identify parts of an operating system, or an operating environment:
application
command
The name of an executable program or other software command.
envar
filename
msgtext
option
parameter
prompt
A character or string indicating the start of an input field in a computer display.
systemitem
A typical book
, in English at least, consists of
some meta-information in an info
(title
, author
,
copyright
, and so on), one or more preface
s, several chapter
s, and perhaps a
few appendix
es. A book
may also
contain bibliography
s,
glossary
s, index
es and a
colophon
.
Example 2.1, “A Typical Book” shows the structure of a typical book. Additional content is required where the ellipses occur.
Example 2.1. A Typical Book
<book> <bookinfo> <title>My First Book</title> <author><firstname>Jane</firstname><surname>Doe</surname></author> <copyright><year>1998</year><holder>Jane Doe</holder></copyright> </bookinfo> <preface><title>Foreword</title> ... </preface> <chapter> ... </chapter> <chapter> ... </chapter> <chapter> ... </chapter> <appendix> ... </appendix> <appendix> ... </appendix> <index> ... </index> </book>
chapter
s, preface
s, and
appendix
es all have a similar structure. They
consist of a title
, possibly some additional
meta-information, and any number of block-level elements followed by
any number of top-level sections. Each section may in turn contain any
number of block-level elements followed by any number from the next
section level, as shown in Example 2.2, “A Typical Chapter”.
For documents smaller than a book, such as: journal articles, white
papers, or technical notes, article
is frequently
the most logical starting point. The body of an
article
is essentially the same as the body of a
chapter
or any other component-level element, as
shown in Example 2.3, “A Typical Article”
article
s may include
appendix
es, bibliography
s,
index
es and glossary
s.
Example 2.3. A Typical Article
<article> <artheader> <title>My Article</title> <author><honorific>Dr</honorific><firstname>Emilio</firstname> <surname>Lizardo</surname></author> </artheader> <para> ... </para> <sect1><title>On the Possibility of Going Home</title> <para> ... </para> </sect1> <bibliography> ... </bibliography> </article>
The reference page or manual page in DocBook was inspired by, and in fact designed to reproduce, the common UNIX “manpage” concept. (We use the word "page" loosely here to mean a document of variable length containing reference material on a specific topic.) DocBook is rich in markup tailored for such documents, which often vary greatly in content, however well-structured they may be. To reflect both the structure and the variability of such texts, DocBook specifies that reference pages have a strict sequence of parts, even though several of them are actually optional.
Of the following sequence of elements that may appear in a
refentry
, only two are obligatory:
refnamediv
and
refsect1
.
info
The info
element contains
meta-information about the reference page (which should not be
confused with refmeta
, which it
precedes). It marks up information about the author of the document,
or the product to which it pertains, or the document's revision
history, or other such information.
refmeta
refmeta
contains a title for
the reference page (which may be inferred if the
refmeta
element is not present) and an indication
of the volume number in which this reference page occurs. The
manvolnum
is a very UNIX-centric concept. In
traditional UNIX documentation, the subject of a reference page is
typically identified by name and volume number; this allows you to
distinguish between the uname command,
“uname(1)” in volume 1 of the documentation and the
uname
function, “uname(3)” in
volume 3.
Additional information of this sort such as conformance or
vendor information specific to the particular environment you are
working in, may be stored in refmiscinfo
.
refnamediv
The first obligatory element is refnamediv
, which is a wrapper for
information about whatever you're documenting, rather than the
document itself. It can begin with a refdescriptor
if several items are being
documented as a group and the group has a name. The refnamediv
must contain at least one
refname
, that is, the name of
whatever you're documenting, and a single short statement that sums up
the use or function of the item(s) at a glance: their refpurpose
. Also available is the refclass
, intended to detail the
operating system configurations that the software element in question
supports.
If no refentrytitle
is given in the
refmeta
, the title of the reference page is the
refdescriptor
, if present, or the first
refname
.
refsynopsisdiv
A refsynopsisdiv
is intended
to provide a quick synopsis of the topic covered by the reference
page. For commands, this is generally a syntax summary of the command,
and for functions, the function prototype, but other options are
possible. A title
is allowed, but
not required, presumably because the application that processes
reference pages will generate the appropriate title if it is not
given. In traditional UNIX documentation, its title is always
“Synopsis”.
refsect1
…refsect3
Within refentry
s, there are only three levels
of sectioning elements: refsect1
,
refsect2
, and refsect3
.
Example 2.4, “A Sample Reference Page” shows the beginning of a refentry
that illustrates one possible
reference page:
Example 2.4. A Sample Reference Page
<refentry id="printf"> <refmeta> <refentrytitle>printf</refentrytitle> <manvolnum>3S</manvolnum> </refmeta> <refnamediv> <refname>printf</refname> <refname>fprintf</refname> <refname>sprintf</refname> <refpurpose>print formatted output</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> #include <stdio.h> </funcsynopsisinfo> <funcprototype> <funcdef>int <function>printf</function></funcdef> <paramdef>const char *<parameter>format</parameter></paramdef> <paramdef>...</paramdef> </funcprototype> <funcprototype> <funcdef>int <function>fprintf</function></funcdef> <paramdef>FILE *<parameter>strm</parameter></paramdef> <paramdef>const char *<parameter>format</parameter></paramdef> <paramdef>...</paramdef> </funcprototype> <funcprototype> <funcdef>int <function>sprintf</function></funcdef> <paramdef>char *<parameter>s</parameter></paramdef> <paramdef>const char *<parameter>format</parameter></paramdef> <paramdef>...</paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1><title>Description</title> <para> <indexterm><primary>functions</primary> <secondary>printf</secondary></indexterm> <indexterm><primary>printing function</primary></indexterm> <function>printf</function> places output on the standard output stream stdout. … </para> </refsect1> </refentry>
DocBook contains markup for the usual variety of front- and backmatter necessary for books and articles: indexes, glossaries, bibliographies, and tables of contents. In many cases, these components are generated automatically, at least in part, from your document by an external processor, but you can create them by hand, and in either case, store them in DocBook.
Some forms of backmatter, like indexes and glossaries, usually require additional markup in the document to make generation by an application possible. Bibliographies are usually composed by hand like the rest of your text, unless you are automatically selecting bibliographic entries out of some larger database. Our principal concern here is to acquaint you with the kind of markup you need to include in your documents if you want to construct these components.
Frontmatter, like the table of contents, is almost always generated
automatically from the text of a document by the processing
application. If you need information about how to mark up a table of
contents in DocBook, please consult the reference page for
toc
.
In some highly-structured documents such as reference manuals, you can automate the whole process of generating an index successfully without altering or adding to the original source. You can design a processing application to select the information and compile it into an adequate index. But this is rare.
In most cases—and even in the case of some reference manuals—a useful index still requires human intervention to mark occurrences of words or concepts that will appear in the text of the index.
Docbook distinguishes two kinds of index markers: those that are singular and result in a single page entry in the index itself, and those that are multiple and refer to a range of pages.
You put a singular index marker where the subject it refers to actually occurs in your text:
<para> The tiger<indexterm> <primary>Big Cats</primary> <secondary>Tigers</secondary></indexterm> is a very large cat indeed. </para>This index term has two levels,
primary
and
secondary
. They correspond to an increasing amount
of indented text in the resultant index. DocBook allows for three
levels of index terms, with the third labeled
tertiary
.
There are two ways that you can index a range of text. The first is to put index marks at both the beginning and end of the discussion. The mark at the beginning asserts that it is the start of a range, and the mark at the end refers back to the beginning. In this way, the processing application can determine what range of text is indexed. Here's the previous tiger example recast as starting and ending index terms:
<para> The tiger<indexterm id="tiger-desc" class="startofrange"> <primary>Big Cats</primary> <secondary>Tigers</secondary></indexterm> is a very large cat indeed… </para> ⋮ <para> So much for tigers<indexterm startref="tiger-desc" class="endofrange">. Let's talk about leopards. </para>
Note that the mark at the start of the range identifies itself as the
start of a range with the class
attribute, and provides an id
.
The mark at the end of the range points back to the start.
Another way to mark up a range of text is to specify that the entire
content of an element, such as a chapter or section, is the complete
range. In this case, all you need is for the index term to point to
the id
of the element that
contains the content in question. The zone
attribute of indexterm
provides this functionality.
One of the interesting features of this method is that the actual index marks do not have to occur anywhere near the text being indexed. It is possible to collect all of them together, for example, in one file, but it is not invalid to have the index marker occur near the element it indexes.
Suppose the discussion of tigers in your document comprises a
whole text object (like a sect1
or a chapter
) with an
id
value of
tiger-desc
. You can put the following
tag anywhere in your document to index that range of text:
<indexterm zone="tiger-desc"> <primary>Big Cats</primary> <secondary>Tigers</secondary></indexterm>
DocBook also contains markup for index hits that point to other index
hits (of the same type such as "See Cats, big" or "See also
Lions"). See the reference pages for see
and
seealso
.
After you have added the appropriate markup to your document, an external application can use this information to build an index. The resulting index must have information about the page numbers on which the concepts appear. It's usually the document formatter that builds the index. In this case, it may never be instantiated in DocBook.
However, there are applications that can produce an index marked up in
DocBook. The following example includes some one- and two-level
indexentry
elements (which
correspond to the primary and secondary levels in the
indexterm
s themselves) that begin with the letter D:
<index><title>Index</title> <indexdiv><title>D</title> <indexentry> <primaryie>database (bibliographic), 253, 255</primaryie> <secondaryie>structure, 255</secondaryie> <secondaryie>tools, 259</secondaryie> </indexentry> <indexentry> <primaryie>dates (language specific), 179</primaryie> </indexentry> <indexentry> <primaryie>DC fonts, <emphasis>172</emphasis>, 177</primaryie> <secondaryie>Math fonts, 177</secondaryie> </indexentry> </indexdiv> </index>
glossary
s, like bibliography
s, are often
constructed by hand. However, some applications are capable of
building a skeletal index from glossary term markup in the document.
If all of your terms are defined in some glossary database, it may
even be possible to construct the complete glossary automatically.
To enable automatic glossary generation, or simply automatic linking
from glossary terms in the text to glossary entries, you must add
markup to your documents. In the text, you markup a term for
compilation later with the inline glossterm
tag. This tag can have a linkend
attribute whose value is the ID of the actual entry in the
glossary.[3]
For instance, if you have this markup in your document:
<glossterm linkend="xml">Extensible Markup Language</glossterm> is a new standard…
your glossary might look like this:
<glossary><title>Example Glossary</title> ⋮ <glossdiv><title>E</title> <glossentry id="xml"><glossterm>Extensible Markup Language</glossterm> <acronym>XML</acronym> <glossdef> <para>Some reasonable definition here.</para> <glossseealso otherterm="sgml"> </glossdef> </glossentry> </glossdiv>
Note that the glossterm
tag
reappears in the glossary to mark up the term and distinguish it from
its definition within the glossentry
.
The id
that
the glossentry
referenced in the
text is the ID of the glossentry
in the glossary
itself. You can use the link between source and glossary to create a
link in the online form of your document, as we have done with the
online form of the glossary in this book.
There are two ways to set up a bibliography in DocBook: you can have
the data raw or
cooked. Here's an example of a raw
bibliographical item, wrapped in the biblioentry
element:
<biblioentry xreflabel="Kites75"> <authorgroup> <author><firstname>Andrea</firstname><surname>Bahadur</surname></author> <author><firstname>Mark</><surname>Shwarek</></author> </authorgroup> <copyright><year>1974</year><year>1975</year> <holder>Product Development International Holding N. V.</holder> </copyright> <isbn>0-88459-021-6</isbn> <publisher> <publishername>Plenary Publications International, Inc.</publishername> </publisher> <title>Kites</title> <subtitle>Ancient Craft to Modern Sport</subtitle> <pagenums>988-999</pagenums> <seriesinfo> <title>The Family Creative Workshop</title> <seriesvolnums>1-22</seriesvolnums> <editor> <firstname>Allen</firstname> <othername role=middle>Davenport</othername> <surname>Bragdon</surname> <contrib>Editor in Chief</contrib> </editor> </seriesinfo> </biblioentry>
The “raw” data in a biblioentry
is comprehensive to a
fault—there are enough fields to suit a host of different
bibliographical styles, and that is the point. An abundance of data
requires processing applications to select, punctuate, order, and
format the bibliographical data, and it is unlikely that all the
information provided will actually be output.
All the “cooked” data in a bibliomixed
entry in a bibliography, on the
other hand, is intended to be presented to the reader in the form and
sequence in which it is provided. It even includes punctuation between
the fields of data:
<bibliomixed> <bibliomset relation=article> <surname>Walsh</surname>, <firstname>Norman</firstname>. <title role=article>Introduction to Cascading Style Sheets</title>. </bibliomset> <bibliomset relation=journal> <title>The World Wide Web Journal</title> <volumenum>2</volumenum><issuenum>1</issuenum>. <publishername>O'Reilly & Associates, Inc.</publishername> and <corpname>The World Wide Web Consortium</corpname>. <pubdate>Winter, 1996</pubdate></bibliomset>. </bibliomixed>
Clearly, these two ways of marking up bibliographical entries are suited to different circumstances. You should use one or the other for your bibliography, not both. Strictly speaking, mingling the raw and the cooked may be “kosher” as far as the DTD is concerned, but it will almost certainly cause problems for most processing applications.
[1] Essentially, it can ensure that two different owners won't accidentally tread on each other. Nothing can prevent a given owner from reusing public identifiers, except maybe common sense.
[3] Some sophisticated formatters might even be able to establish the link simply by examining the content of the terms and the glossary. In that case, the author is not required to make explicit links.