]> erbook 5.0.0 user manual


Abstract

erbook is an extensible document processor that emits XHTML (web page), LaTeX (PDF), man (UNIX manual page), plain text, and any document format you can imagine from eRuby templates that allow scripting and dynamic content generation. Read more…

Resources

To get help or provide feedback, simply contact the author.




Contents

Cautions

  1. An example

Equations

  1. An example

Examples

  1. HelloWorld format specification file
  2. Input document for HelloWorld format
  3. Output of HelloWorld format
  4. An example

Figures

  1. An example

Importants

  1. Save XHTML output as .xhtml
  2. An example

Notes

  1. See the source of this manual
  2. An example

Procedures

  1. An example

Tables

  1. An example

Tips

  1. An example

Warnings

  1. An example



Chapter 1
Introduction

erbook is an extensible document processor that emits XHTML (web page), LaTeX (PDF), man (UNIX manual page), plain text, and any document format you can imagine from eRuby templates that allow scripting and dynamic content generation.

Note 1.  See the source of this manual

note

Did you know that this manual was generated by erbook? Here is the source document to prove it!

1.1  Relevance

Unlike document processors such as DocBook, Deplate, and SiSU, erbook is:

Unlike the documents of raw text processors such as AsciiDoc, txt2tags, and Grutatxt, erbook documents are scriptable eRuby templates, which means that you can inject arbitrary Ruby code into your documents for dynamic content generation.

1.1.1  Reviews

Vitor Peres in ruby-talk:

I actually felt like printing [this manual], because it’s just so well-thought typographically… Even if [erbook] weren’t great by itself, I’d feel good just looking at the manual.

Ara T. Howard in ruby-talk:

[this manual is] a insanely complete and nice looking bit of documentation [… erbook] looks like a great project

Martin DeMello in ruby-talk:

Very nice work indeed!

1.2  Logistics

erbook is open source software so feel free to contribute your improvements and discuss your ideas with the author. You can obtain the source code from this source repository and monitor for changes by subscribing to this news feed.

1.2.1  Credits

The erbook logo, its image file “erbook.png”, and its source file “erbook.svg” make use of the “cartoon owl sitting on a book” graphic, which was created and released into the public domain by Jens Vierbuchen on July 7, 2008.

1.2.2  License

Copyright 2006 Suraj N. Kurapati sunaku@gmail.com

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

1.2.3  Version numbers

erbook releases are numbered in major.minor.patch form, according to the RubyGems rational versioning policy which can be summarized thus:

What increased in the version number? What does the increase signify about the release?
Backwards compatible? New features? Bug fixes?
major No Yes Yes
minor Yes Yes Yes
patch Yes No Yes

Chapter 2
Setup

2.1  Requirements

Your system needs the following software to run erbook.

SoftwareDescriptionNotes
RubyRuby language interpreterVersion 1.8.x is required.
MarukuMarkdown processorRequired by the default XHTML format.
CodeRaySyntax highlighterRequired by the default XHTML format.
TrollopCommand-line option parserRequired by the erbook executable.

If your system has RubyGems, then you can install Maruku and CodeRay by running the following command:

gem install trollop maruku coderay

2.2  Installation

If your system has RubyGems, then you can install erbook by running the following commands:

gem install erbook
erbook -v

Otherwise, follow these instructions:

  1. Download the newest release package from the download area.

  2. Extract the release package somewhere on your system.

  3. Go inside the extracted directory and run the following command:

    ruby bin/erbook -v

If the installation was successful, then you will see output like this:

project: erbook
version: 5.0.0
release: 2008-11-22
website: http://snk.tuxfamily.org/lib/erbook
install: /home/sun/src/erbook

Otherwise, you can contact the author for help.

2.3  Manifest

You will see the following items inside erbook’s installation directory, whose path you can determine by running this command:

erbook -v
  • bin/ — contains executable programs.

    • erbook — core logic of erbook.
  • fmt/ — contains the predefined set of format specification files. If you ever need to install your custom format specification file globally, then put it inside this directory.

  • latex.yaml — high-quality typesetting

  • man.yaml — manual page for UNIX

  • xhtml.yaml — web page for the Internet

  • text.yaml — plain text, nothing fancy

  • lib/ — erbook automatically adds this directory to Ruby’s load path.

  • doc/ — contains this manual and other documentation.

    • erbook.svg — source file of the erbook logo.

    • manual.erb — source file of this manual.

    • api/ — contains API reference documentation for the provided Ruby code.

  • LICENSE — project license and copyright notice.

Chapter 3
Theory of operation

When you run erbook, it does the following:

  1. Loads the format specification file.

  2. Creates an input document by:

    • Reading the input (the content of either the input file or the standard input stream) into memory.

    • Evaluating include directives in the input.

  3. Transforms the input document into a processed document by:

    • Building a document tree data structure from nodes present in the input document.

    • Replacing every node in the input document with the result of its node output template.

  4. Transforms the processed document into an output document according to the document output template.

  5. Prints the output document to the standard output stream.

Although there is only one document being processed here, we refer to it using three distinct terms: input, processed, and output; because the content of the document changes radically with every transformation.

3.1  Nodes

A node is a block of text that appears like this:

<% node_type node_argument1, node_argument2, ... do |node_object| %>
  node_content
<% end %>

Or like this:

<% node_type node_argument1, node_argument2, ... do %>
  node_content
<% end %>

Or like this:

<%= node_type node_argument1, node_argument2, ... %>

Alternatively, you may omit the leading ”<” and trailing “%>” characters from an eRuby directive if the directive spans an entire line. So, the above examples become:

% node_type node_argument1, node_argument2, ... do |node_object|
  node_content
% end

And:

% node_type node_argument1, node_argument2, ... do
  node_content
% end

And:

%= node_type node_argument1, node_argument2, ...

Technically, nodes are Ruby method invocations composed of the following:

ComponentDescription
node_typename of the method being invoked
node_argument1, node_argument2, ...arguments for the method invocation
node_contenta block argument being passed to the method invocation
node_objecta ERBook::Node object (see Section 3.1.1. The ERBook::Node class) representing this method invocation

A format specification file defines what types of nodes an input document may use.

3.1.1  The ERBook::Node class

When erbook builds a document tree from the nodes in an input document, it stores information about these nodes into ERBook::Node objects. A ERBook::Node object has the following properties (methods):

PropertyTypeDescription
typeStringName of the type of this node.
argsArrayArguments passed to this node.
contentStringThe block of text passed to this node.
outputStringResult of the node output template for the content of this node.
digestStringA unique identifier for the content of this node.
traceArrayA stack trace describing the location of this node in the input document.
indexStringA LaTeX-style section number for this node. This property is only present if the index parameter is enabled in the definition of this type of node.
numberIntegerAn order-of-occurrence number for this node. This property is only present if the number parameter is enabled in the definition of this type of node.
depthIntegerDistance from the root of the document tree to this node.
parentERBook::NodeThe ERBook::Node object which contains this node. The value of this property will be nil if this node is a root of the document tree.
childrenArray of ERBook::NodeList of child nodes from the document tree.

Furthermore, the ERBook::Node class is derived from Ruby’s OpenStruct class, so you can define new properties for ERBook::Node objects dynamically.

3.2  Format specification file

A format specification file is a plain-text file marked up in YAML syntax. Through the following parameters, it defines (1) what types of nodes an input document may contain, (2) how the content of those nodes is transformed into output, and (3) how the processed document is transformed into the output document.

ParameterTypeDescription
descStringA short description of the output format.
codeStringRuby code that will be loaded before the input document is processed. This source code will be evaluated inside the main erbook executable, so any file-system or path-dependent portions of this source code should take appropriate precautions.
nodesHashA listing of node definitions.
outputStringAn eRuby template for the final output document. See Section 3.2.2. Document output template.

3.2.1  Node definition

A node definition is a mapping from a name (the “node type”) to the following set of parameters:

ParameterTypeDescription
indexBooleanAssign a LaTeX-style section number to this node?
numberBooleanAssign an order-of-occurrence number to this node?
silentBooleanSuppress the output of this node?
outputStringAn eRuby template for the content of this node. See Section 3.2.1.1. Node output template.

You may define additional parameters in a node definition if you want.

3.2.1.1  Node output template

A node output template (the output parameter in a node definition) is an eRuby template that transforms a node’s content into output. During the processing stage, erbook replaces all nodes in the input document with the result of this template unless the silent parameter is enabled in this node’s definition.

The following variables are available for use in this template:

VariableTypeDescription
@nodeERBook::NodeThe node for which this template is being evaluated.
@rootsArray of ERBook::NodeAll root nodes in the document tree.
@nodesArray of ERBook::NodeAll nodes in the document tree.
@typesHashMapping from node type (String) to array of ERBook::Node objects having that type.
@specHashData from the format specification file.

erbook also provides the following mappings inside the @spec variable:

ExpressionTypeDescription
@spec[:name]StringShort-hand name of the current format.
@spec[:file]StringPath of the current format specification file.

3.2.2  Document output template

A document output template (the output parameter in a format specification file) is an eRuby template that transforms a processed document into the final output document.

The following variables are available for use in this template:

VariableTypeDescription
@contentStringContent of the processed document.
@rootsArray of ERBook::NodeAll root nodes in the document tree.
@nodesArray of ERBook::NodeAll nodes in the document tree.
@typesHashMapping from node type (String) to array of ERBook::Node objects having that type.
@specHashData from the format specification file.

erbook also provides the following mappings inside the @spec variable:

ExpressionTypeDescription
@spec[:name]StringShort-hand name of the current format.
@spec[:file]StringPath of the current format specification file.

3.2.3  Creating your own document format

Here is a working example to help you digest all that you’ve learned so far about format specification files. A few things to notice in this example are:

To run this example:

  1. Save the code shown in Example 1. HelloWorld format specification file to a file named HelloWorld.spec

  2. Save the text shown in Example 2. Input document for HelloWorld format to a file named HelloWorld.input

  3. Run this command:

    erbook HelloWorld.spec HelloWorld.input > HelloWorld.output
  4. Examine the HelloWorld.output file to your satisfaction!

Example 1.  HelloWorld format specification file

desc: An example format.

code: |
  # Returns a random, yet pronounceable, name.
  def generate_name
    letters = ('a'..'z').to_a - %w[ c q w x ] # redundant sounds
    vowels = %w[a e i o u]
    consonants = letters - vowels
    sets = [consonants, vowels]

    length = 3 + rand(5)

    name = (0...length).map do |i|
      # alternate between consonants and vowels
      set = sets[i % sets.length]

      # choose a random letter from the set
      set[rand(set.length)]
    end.join

    name
  end

  class Node
    def name
      # dynamically compute (and store)
      # the name of this node on demand
      @name ||= generate_name
    end
  end

nodes:
  hello:
    index: true
    number: true
    silent: false
    output: |
      <h3><%= @node.type %> #<%= @node.index %>: <%= @node.name.inspect %></h3>

      My name is <%= @node.name.inspect %> and these are my properties:

      <dl style="<%= $style %>">
        <dt>args</dt>
        <dd><code><%= @node.args.inspect %></code></dd>

        <dt>index</dt>
        <dd><code><%= @node.index.inspect %></code></dd>

        <dt>number</dt>
        <dd><code><%= @node.number.inspect %></code></dd>

        <dt>trace</dt>
        <dd><pre><%= @node.trace.join("\n") %></pre></dd>

        <dt>content</dt>
        <dd><%= @node.content %></dd>
      </dl>

output: |
  Welcome to the "<%= @spec[:name] %>" format.
  <%= @content %>
  That's all folks!

Example 2.  Input document for HelloWorld format

<% $style = "border-left: thick dotted LightGrey; padding-left: 1em;" %>
<% hello "Pretentious", 1, 2, 3 do %>
  <big>I'm</big> the very first node, oh _yes_ I am! *sneer*

  <% hello "Bashful", 4, 5, 6 do %>
    Hi, I... *hide*

    <% hello "Hopeful", rand do %>
      *sigh*

      <% hello "Confused", (rand * rand) do %>
        Huh?
      <% end %>
    <% end %>

    <% hello "Raving", __FILE__ do %>
      Oh it's *on* now! You're going *down*!
    <% end %>
  <% end %>

  <% hello "Sleepy", Time.now do %>
    *yawn* Just five more minutes...

    <% hello "Peaceful", Dir.pwd do %>
      So _be_ happy my friend, *happy*!

      <%= hello "Lonely (as you can see, I have no block)" %>
    <% end %>
  <% end %>
<% end %>

<% hello "Snappy" do %>
  Zip! Zap! Wake up, you sap!
  _Whoo I'm wild!_ ;-)
<% end %>

<%= hello "Independent (no block, no parents, I am _free_!)" %>

Example 3.  Output of HelloWorld format

Welcome to the “HelloWorld” format.

hello #1: nil

My name is nil and these are my properties:

args
["Pretentious", 1, 2, 3]
index
"1"
number
1
trace
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
I'm the very first node, oh _yes_ I am! *sneer*

hello #1.1: nil

My name is nil and these are my properties:
args
["Bashful", 4, 5, 6]
index
"1.1"
number
2
trace
doc/HelloWorld.input:3
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
Hi, I... *hide*

hello #1.1.1: nil

My name is nil and these are my properties:
args
["Hopeful", 0.0790764609144532]
index
"1.1.1"
number
3
trace
doc/HelloWorld.input:5
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:3
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
*sigh*

hello #1.1.1.1: nil

My name is nil and these are my properties:
args
["Confused", 0.528769558981025]
index
"1.1.1.1"
number
4
trace
doc/HelloWorld.input:7
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:5
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:3
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
Huh?

hello #1.1.2: nil

My name is nil and these are my properties:
args
["Raving", "doc/HelloWorld.input"]
index
"1.1.2"
number
5
trace
doc/HelloWorld.input:9
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:3
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
Oh it's *on* now! You're going *down*!

hello #1.2: nil

My name is nil and these are my properties:
args
["Sleepy", Sat Nov 22 23:17:11 -0800 2008]
index
"1.2"
number
6
trace
doc/HelloWorld.input:11
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
*yawn* Just five more minutes...

hello #1.2.1: nil

My name is nil and these are my properties:
args
["Peaceful", "/home/sun/src/erbook"]
index
"1.2.1"
number
7
trace
doc/HelloWorld.input:13
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:11
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
So _be_ happy my friend, *happy*!

hello #1.2.1.1: nil

My name is nil and these are my properties:
args
["Lonely (as you can see, I have no block)"]
index
"1.2.1.1"
number
8
trace
doc/HelloWorld.input:15
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:13
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:11
bin/erbook:115:in `content_from_block'
bin/erbook:288:in `hello'
doc/HelloWorld.input:1
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content

hello #2: nil

My name is nil and these are my properties:

args
["Snappy"]
index
"2"
number
9
trace
doc/HelloWorld.input:17
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content
Zip! Zap! Wake up, you sap! _Whoo I'm wild!_ ;-)

hello #3: nil

My name is nil and these are my properties:

args
["Independent (no block, no parents, I am _free_!)"]
index
"3"
number
10
trace
doc/HelloWorld.input:20
bin/erbook:307
bin/erbook:307:in `instance_eval'
bin/erbook:307
content

That’s all folks!

Chapter 4
Usage

4.1  Command-line invocation

erbook is an extensible document processor based on eRuby.

  • The standard input stream will be read if an input file is not specified.

  • The final output document will be written to the standard output stream.

  • If an error occurs, the input document will be written to the standard output stream, so that you can investigate line numbers in the error.

Usage:

erbook [Option...] FormatName [InputFile]
erbook [Option...] FormatFile [InputFile]

FormatName:
latex
high-quality typesetting
man
manual page for UNIX
xhtml
web page for the Internet
text
plain text, nothing fancy
Option:
--unindent, -u
Unindent node content hierarchically
--version, -v
Print version and exit
--help, -h
Show this message

Command-line arguments

The first command-line argument to erbook is either the name of a predefined format (FormatName) or the path to a format specification file (FormatFile).

Predefined formats are simply short-hand names of format specification files located in the fmt/ subdirectory of the erbook installation directory (see Section 2.3. Manifest).

Saving the output to a file

Simply redirect the standard ouput stream (STDOUT) to a file like this:

erbook > YOUR_PATH_HERE

In the above example, YOUR_PATH_HERE is the path of the file in which the output should be saved.

Important 1.  Save XHTML output as .xhtml

important

When you use the XHTML format, ensure that the file extension of your saved output document is either .xhtml or .xml. Alternatively, ensure that your saved output document is served to web browsers under the application/xhtml+xml mime type.

Otherwise, most web browsers will not display the icons and graphics embedded in the saved XHTML output document because they will treat it as HTML instead of as XML. See this QuirksMode.org bug report for details.

4.2  Including external documents

The include directive allows you to insert the content of an arbitrary file at a certain place in the input document. It is written like this:

<%# include YOUR_PATH_HERE #%>

In the above example, YOUR_PATH_HERE is the path of the file whose content you wish to insert into the input document.

You can divide a large document into separate files for easier editing and stitch them together, dynamically, into a single document using the include directive.

4.3  Unindenting nodes hierarchically

When writing erbook documents, I prefer to indent the content of nodes according to their depth (as can be seen in the source of this manual) because my text editor of choice automatically folds blocks of text based on indentation.

If you also prefer to write documents in this way, be sure to pass the --unindent option to erbook so that the indentation will not affect the resulting output.

Part 5
Formats

This part describes the default formats provided along with erbook. The format specification files for these formats can be found in the fmt/ directory of the erbook installation directory (see Section 2.3. Manifest).

These formats are meant to serve as working examples. If you require more functionality from one of these formats, simply make a copy of the corresponding format specification file and edit the copy to suit your needs. If you would like to contribute or discuss your enhancements to these default formats, you can contact the author.

Chapter 5.1
XHTML (web page)

This format generates a monolithic XHTML document that allows users to easily search for a particular topic using nothing more than their web browser’s built-in text search mechanism. This facilitates offline reading, where an Internet search engine is not available.

In the XHTML document, you will notice that the numbers of chapters, sections, figures, admonitions, etc. are hyperlinks that take you back to the corresponding place in the table of contents. These links make it easy to navigate the XHTML document, especially for users of text-only web browsers.

Furthermore, the XHTML document comes equipped with a stylesheet that makes it suitable for printing. In particular, users of the Mozilla and Opera family of web browsers will be pleasantly surprised to notice that all hyperlinks have been expanded to include their target URL next to the link text. So try using the “print preview” function of a graphical web browser to see how the XHTML document will appear when printed.

5.1.1  Text to XHTML conversion

The lib/erbook/to_xhtml.rb file inside erbook’s installation directory (see Section 2.3. Manifest) defines the following methods:

  • String#to_xhtml - Transforms this string into XHTML while ensuring that the result contains one or more block-level elements at the root.

  • String.to_inline_xhtml - Transforms this string into an inline XHTML string (one that does not contain any block-level XHTML elements at the root).

The default implementation of the String#to_xhtml method employs the Markdown markup system. If you do not like Markdown or wish to use a different markup system for text in your documents, then simply edit the to_xhtml.rb file and adjust the source code of the default String#to_xhtml and String.to_inline_xhtml methods accordingly.

For example, if you replace the entire to_xhtml.rb file with the following code, then the output of all nodes will appear within red boxes in the final output document.

class String
  # Transforms this string into XHTML while ensuring that the
  # result contains one or more block-level elements at the root.
  def to_xhtml
    '<p style="border: thin solid red">' + self + '</p>'
  end

  # Transforms this string into an *inline* XHTML string (one that
  # does not contain any block-level XHTML elements at the root).
  def to_inline_xhtml
    self
  end
end

In addition to supporting Markdown syntax, the default implementation has some additional features which are described in the following subsections.

5.1.1.1  Syntax coloring for source code

Syntax coloring is automatically added to source code found inside the <code> and </code> HTML tags. The syntax coloring library, CodeRay, currently supports the following programming languages:

  • Ruby
  • C
  • Delphi
  • HTML
  • RHTML (Rails)
  • Nitro-XHTML

5.1.1.1.1  Specifying the programming language

Because different programming languages have different syntax coloring schemes, you can specify the language of your source code using the lang attribute to ensure that only the appropriate coloring scheme is used. Note that unless the lang attribute is specified, Ruby is assumed to be the programming language of all source code by default.

For example, here is some source code without the lang attribute:

# Ruby ###########################
def hello
  puts "Hello world!"
end


/* C ****************************/
#include <stdio.h>
int main(int argc, char **argv) {
  printf("Hello world!\n");
  return 0;
}


<!-- HTML ----------------------->
<html>
  <body>
    Hello world!
  <body>
</html>

And here is the same source code with a lang="c" attribute:

# Ruby ###########################
def hello
  puts "Hello world!"
end


/* C ****************************/
#include <stdio.h>
int main(int argc, char **argv) {
  printf("Hello world!\n");
  return 0;
}


<!-- HTML ----------------------->
<html>
  <body>
    Hello world!
  <body>
</html>

And here is the same source code with a lang="html" attribute:

# Ruby ###########################
def hello
  puts "Hello world!"
end


/* C ****************************/
#include <stdio.h>
int main(int argc, char **argv) {
  printf("Hello world!\n");
  return 0;
}


<!-- HTML ----------------------->
<html>
  <body>
    Hello world!
  <body>
</html>

5.1.1.2  Smart sizing of source code

Source code is automatically sized to be displayed as either a line or paragraph of text, depending on whether it contains line breaks.

For example, here is a single line life = true or false of code. And here is a paragraph

life =
true or
false
of code.

5.1.1.3  Protecting verbatim text

Sometimes you just need to protect some text from being mangled by the text-to-XHTML conversion process . In such cases, you can wrap the text you want to proctect within <noformat> and </noformat> tags.

5.1.2  Parameters

The XHTML format accepts the following document parameters.

ParameterTypeDefault valueDescription
$titleString"$title"Title of the document.
$authorsHash{"$authors" => nil}A mapping of author name to author URL. You can obfuscate e-mail addresses using the provided String#to_xml_entities method like this: { "Y. Matsumoto" => "mailto:matz@ruby.invalid".to_xml_entities }
$dateStringTime.now.strftime("%d %B %Y")Date when the document was written.
$logoStringnilArbitrary content that goes above the document title in the default header.
$feedsHashnilA mapping of feed URL to feed format. Here is an example: $feeds = { "my_rss_feed.xml" => "rss", "my_atom_feed.xml" => "atom" }

5.1.3  Methods

The XHTML format provides the following methods. In the method declarations shown below,

  • a pound sign (#) indicates that the method is an instance method, meaning that it can only be invoked on instances of a class, not on the classes themselves.
  • a double colon sign (::) indicates that the method is a class method, meaning that it can only be invoked on a class.

5.1.3.1  ERBook::Node#title()

Returns the user-defined title for this node‘s content.

5.1.3.2  ERBook::Node#id()

Returns the user-defined indentifer for this node.

5.1.3.3  ERBook::Node#title_xhtml()

Returns the title of this node as XHTML.

5.1.3.4  ERBook::Node#content_xhtml()

Returns the content of this node as XHTML.

5.1.3.5  ERBook::Node#title_link(aTitle = nil)

Returns a hyperlink to this node containing its title.

5.1.3.6  ERBook::Node#index_link()

Returns a hyperlink to this node containing its LaTeX-style index number.

5.1.3.7  ERBook::Node#number_link()

Returns a hyperlink to this node containing its occurrence number.

5.1.3.8  Hash#to_xml_atts()

Transforms this hash into a string of XML attribute key="value" pairs.

5.1.3.9  ERBook::Template#verbatim(aContent)

Protects the given content from the text-to-XHTML conversion process.

5.1.3.10  ERBook::Template#hyperlink(aUrl, aLabel = aUrl, aTitle = nil)

Returns XHTML for a hyperlink to the given URL of the given label and mouse-hover title.

5.1.3.11  ERBook::Template#embed_image_file(aPath, aFormat = aPath[/\w+/], aAtts = {})

Returns an <img/> tag that embeds the given image file.

aPath:path to the image file
aFormat:format of the image file (e.g. PNG, JPEG, GIF, etc.)
aAtts:additional attributes for the <img> tag

5.1.3.12  ERBook::Template#embed_image_data(aData, aFormat, aAtts = {})

Returns an <img/> tag that embeds the given raw image data.

aData:raw image data
aFormat:format of the image file (e.g. PNG, JPEG, GIF, etc.)
aAtts:additional attributes for the <img> tag

5.1.3.13  String#to_xml_entities()

Transforms this UTF-8 string into XML entities.

5.1.3.14  String#to_uri_fragment()

Transforms this string into a valid URI fragment. See www.nmt.edu/tcc/help/pubs/xhtml/id-type.html

5.1.3.15  String#to_inline_xhtml()

Transforms this string into an inline XHTML string (one that does not contain any block-level XHTML elements at the root).

5.1.3.16  String#to_xhtml(aInline = false)

Transforms this string into XHTML while ensuring that the result contains one or more block-level elements at the root.

If aInline is true, then the resulting XHTML will be an inline string.

Chapter 5.1.4
Nodes

Unless otherwise noted, all nodes defined by the XHTML format accept two arguments, in this order:

  1. a required title for the node
  2. an optional unique identifier for the node

The second argument is used by the cross-referencing nodes (see Section 5.1.4.1.4. xref and Section 5.1.4.5.2. cite), which allow you to refer to another node in the document by its unique identifier.

Furthermore, node definitions in the XHTML format have two additional parameters:

ParameterTypeDescription
tocBooleanInclude this node in the Table of Contents (TOC)?
lofBooleanInclude this node in the List of Figures (LOF)?

5.1.4.1  Structural nodes

The nodes described in this section form the overall structure of the output document.

5.1.4.1.1  header

This node overrides the logo, title, list of authors, and date when the document was written, all of which are shown at the top of the document.

5.1.4.1.2  footer

This node overrides (1) the date when this document was generated and (2) the hyperlink to the erbook website, shown at the bottom of the document. The hyperlink is there as a way of saying thanks for erbook, the wonderful little utility you have grown so fond of! ;-)

5.1.4.1.3  abstract

A summary of the entire document. This is what most readers will skim through, if you are lucky. Alas, nobody reads entire documents these days! :-(

5.1.4.1.4  xref

A cross-reference; a hyperlink that takes you to any node in the document.

The first argument of this node is either the unique identifier or the user-defined title of the node you wish to cross-reference. If no nodes in the document have the given identifier or user-defined title, then an error will be raised.

The second argument of this node overrides the default link text of the cross-reference.

For example, this node in the input document:

<%= xref "SpecFile" %>

appears in the output document like this: Section 3.2. Format specification file.

As another example, this node in the input document:

<%= xref "SpecFile", "custom link text" %>

appears in the output document like this: custom link text.

5.1.4.2  Organizational nodes

The nodes described in this section are meant to help organize the document’s content logically. Based on how deeply these nodes are nested in the document, their heading will be larger (shallow depth) or smaller (deep depth).

5.1.4.2.1  part

A collection of chapters.

Part 5.1.4.2.1.1
An example

This is how a part node appears.

5.1.4.2.2  chapter

A collection of sections.

Chapter 5.1.4.2.2.1
An example

This is how a chapter node appears.

5.1.4.2.3  section

A collection of paragraphs about a particular topic.

5.1.4.2.3.1  An example

This is how a section node appears.

5.1.4.2.4  paragraph

A collection of sentences about a particular idea.

An example

This is how a paragraph node appears. Notice that there is no LaTeX-style index number in the heading of this paragraph node.

5.1.4.3  Admonition nodes

An admonition is basically a box that is indented more deeply than the text surrounding it. It is typically used to convey extraneous or pertinent information about the application of ideas discussed in the surrounding text.

I like to follow the KDE guidelines[1] when determining which admonition to use in my documents.

5.1.4.3.1  warning

Use a warning node when “data loss could occur if you follow the procedure being described.” [1]

Warning 1.  An example

warning

This is how a warning node appears.

5.1.4.3.2  caution

bq. A note of caution. Use this for example when the reader may lose easily recovered or replaceable information (e.g. user settings), or when they could cause data loss if they don’t correctly follow the procedure being outlined. [1]

Caution 1.  An example

caution

This is how a caution node appears.

5.1.4.3.3  important

Use an important node when:

bq. When there is no danger of data loss, but you wish to make clear to the reader a consequence that isn’t immediately obvious (e.g. when changing the font for one instance of a program also changes the default setting, and this isn’t clear from the GUI.) [1]

Important 2.  An example

important

This is how a important node appears.

5.1.4.3.4  note

Use a note node to convey:

bq. Information the user should be aware of, but is peripheral to the actual task being described. [1]

Note 2.  An example

note

This is how a note node appears.

5.1.4.3.5  tip

Use a tip node when:

bq. When you’re giving a hint to make things easier or more productive for the reader. [1]

Tip 1.  An example

tip

This is how a tip node appears.

5.1.4.4  Auxilary materials

5.1.4.4.1  figure

A diagram, sketch, image, or illustration; something that visually depicts an idea or thought.

Figure 1.  An example

This is how a figure node appears.

5.1.4.4.2  table

Information (typically measurement data) represented in tabular form for easy reading, comparison, and analysis.

Table 1.  An example

This is how a table node appears.

5.1.4.4.3  example

A sample application of an idea or thought.

Example 4.  An example

This is how a example node appears.

5.1.4.4.4  equation

A mathematical equation or formula.

Equation 1.  An example

This is how a equation node appears.

5.1.4.4.5  procedure

An outline; a series of steps outlining some kind of process.

Procedure 1.  An example

This is how a procedure node appears.

5.1.4.5  Bibliographical nodes

The nodes in this section deal with attribution of ideas—an important weapon against plagiarism.

5.1.4.5.1  reference

This node stores bibliography information about an information source that is relevant to your document.

If you wish to cite a certain source in several places in your document, start by creating a reference node first and then use a cite node (see Section 5.1.4.5.2. cite) to perform the citation.

An example

See Reference 2 for an example of how a reference node appears.

5.1.4.5.2  cite

A citation to a reference node (see Section 5.1.4.5.1. reference) in the document’s bibliography.

The first argument of this node is the unique identifier of the reference node you wish to cite. You can specify additional arguments to give more detail about the citation.

For example, this node in the input document:

<%= cite "xhtml.nodes.reference.example" %>

appears in the output document like this: [2]

As another example, this node in the input document:

<%= cite "xhtml.nodes.reference.example", "chapter 10", "page 53", "..." %>

appears in the output document like this: [2, chapter 10, page 53, ...]

Chapter 5.2
Plain text

This format is not yet implemented. I will do this evenually, but until then, patches are welcome! :-)

http://en.wikipedia.org/wiki/Plain_text

Chapter 5.3
LaTeX (PDF)

This format is not yet implemented. I will do this evenually, but until then, patches are welcome! :-)

http://www.latex-project.org

Chapter 5.4
man (UNIX manual page)

This format is not yet implemented. I will do this evenually, but until then, patches are welcome! :-)

http://en.wikipedia.org/wiki/Man_page

References

  1. L. Watts, “Admonitions: Tips, hints, and Warnings”, in The KDE DocBook Authors guide, Chapter 13, [Online document], 22 September 2004 (Revision 1.00.00), [cited 8 December 2007], Available at http://l10n.kde.org/docs/markup/tips-hints-etc.html

  2. This is how a reference node appears.