Decide where to place the index. The best location is usually at the end of the article.
Add this section info to the bottom of the _index.adoc file. This tells AsciiDoctor where the index is to be placed. Use the following construction:
[index] == Index
Continue below with "Tagging Terms for an Index"
Creating an Index in FDP Articles and Books
trademarks
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this document, and the FreeBSD Project was aware of the trademark claim, the designations have been followed by the “™” or the “®” symbol.
Table of Contents
1. Introduction
Creating an index in AsciiDoctor with the FreeBSD Documentation Project toolkit is possible and in fact is fairly easy, because the indexing tooling is already built into AsciiDoctor. An index is simply a new section in a document. Here’s a quick summary on how to generate an index for FreeBSD FDP books, articles, and multi-part documents.
The FDP toolkit does not generate an index for HTML output, only PDF output. |
1.1. Creating an Index for Article Documents
Articles are single-part documents as opposed to muli-part documents like books. If the article is short - one or two pages - an index is hardly worth the trouble. But for larger articles, it can help the reader to easily locate specific terms.
AsciiDoctor only allows level 1 headings (== MyHeading) and higher levels for articles. It does not allow level 0 headings (= MyHeading) for articles. |
Here is a procedure for creating an index for an article.
1.2. Creating an Index for Book Documents
There are several additional steps to consider for building a book index. An index is a new chapter, and the steps below are necessary to integrate the new chapter into an existing book.
Create a new chapter by copying an existing chapter. Usually, copying the last existing chapter works well. Here,
chapter10
is used as the name of the last chapter.cd bookdir cp -av chapter10 index
Change the front matter in the index/_index.adoc as described below. Edit index/_index.adoc and change the title, and any "prev:" field. Also change the weight value.
--- title: Index prev: books/mybook/chapter10 description: Index tags: ["firewall", "IPFW", "Virtual Machine", "VM", "QEMU"] showBookMenu: true weight: 140 path: "/books/mybook/index/" ---
Make the weight value the highest value of any chapter in the book. This puts the index at the end of the book.
Also, add or change the next: field in the front matter of the previous chapter (chapter10/_index.adoc).
After the front matter put the index header and title at the end as shown below. Use a level 0 section header for the title "Index". This puts it on a separate page.
. . . ifndef::env-beastie[] toc::[] include::../../../../../shared/asciidoctor.adoc[] endif::[] [index] = Index
1.3. Tagging Terms for the Index
Follow this procedure to tag items for the index.
Now go through all the text in all the chapters and tag each term to be indexed. Add the indexterm:[] tags on their own line near the term. The tag placement can be on the line before or after - just be consistent. Note how subindex terms are specified.
The quick brown fox jumps over the lazy dog. indexterm:[fox] indexterm:[dog] indexterm:[animal, fox] indexterm:[animal, dog]
This example creates four index entries as follows (all shown on page 1):
A animal dog 1 fox 1 D dog 1 F fox 1
Multiple tags on the same line are permitted. However, do not use tags on the same line as the text like this:
Do not do this: The quick brown fox jumps over the lazy dog. indexterm:[fox] indexterm[dog] indexterm[animal, fox] indexterm:[animal, dog]
This tagging style (added to the end) conflicts with the FDP "One Sentence Per Line" directive and vale(1) will complain.
Avoid tagging terms inside any block listings. Instead, put the tags on a separate line either before the listing header or after the listing body. Leave one extra line before the listing header.
indexterm:[fox] indexterm[dog] indexterm[animal, fox] indexterm:[animal, dog] (Leave a blank line here.) [.programlisting] .... The quick brown fox jumps over the lazy dog. ....
Avoid tagging terms inside [NOTE], [TIP], [WARNING], [IMPORTANT], and similar structures.
Keep a running list of decisions on indexing. Be consistent in tag usage. If a term in a tag is singular or capitalized or contains multiple words, always use the same stye of the term in other tags.
Avoid mixing term styles like this:
indexterm:[jump] indexterm:[jumps over] indexterm[Jump]
Not every instance of a term needs its own tag. If there are several sentences together, each having the same term, or even nearby paragraphs all having the same term, just tag the term once. The index entry will be the same for all of them. AsciiDoctor does not filter out multiple entries on the same page.
If tagging terms in a numbered procedure, place the tags on separate lines with '+' for continuation.
Example:
[.procedure] ==== . On the FreeBSD host, install the necessary packages - man:qemu[1], man:sudo[8] (or man:doas[1]). The examples in this book use sudo. + indexterm:[QEMU, pkg install] indexterm:[sudo] indexterm:[sudo, pkg install] + [subs=+quotes] ---- # *pkg install qemu sudo* ---- + . Create a directory layout for the files to be used. + indexterm:[SCRIPTS] indexterm:[ISO] indexterm:[fetch] + [subs=+quotes] ---- % *mkdir -p ~/ipfw/VM ~/ipfw/SCRIPTS ~/ipfw/ISO* % *cd ~/ipfw/ISO* % *fetch https://download.freebsd.org/releases/amd64/amd64/ISO-IMAGES/#<latest version>#/FreeBSD-#<latest-version>#-RELEASE-amd 64-dvd1.iso* ---- + indexterm:[tap] indexterm:[bridge] + . Create the bridge and tap devices for the virtual machines (VMs) to use. + . Finish everything and go home. ====
Make the document normally (make DOC_LANG=whatever). When the book is completed, open the PDF version and review the index for errors and consistency.
2. Conclusion
Check these examples:
https://www.jimby.name/fbsd/_index.adoc.txt - this is a text page showing indexterm:[] usage.
https://www.jimby.name/fbsd/fdp_index_example.png - this is a screenshot of a completed index.