Crowbook User Guide 0.10.4

« 2. Arguments

3. The configuration file

If you want to use Crowbook for your book, this configuration file is all you’ll have to add (assuming you already have the book in Markdown files; if you don’t, you’ll also have to write a book first, but that’s besides the scope of this document).

The format is not very complicated. This is an example of it:

# metadata
author: Joan Doe
title: Some book
lang: en

output.html: some_book.html

# list of chapters
- preface.md
+ chapter_1.md
+ chapter_2.md
+ chapter_3.md
+ chapter_4.md
- epilogue.md

Basically, it is divided in two parts:

Lines starting with the # characters are comments and are discarded.

Sometimes, you only have one Markdown file and might not want to have a separate configuration file. In this case, you can specify options at the beginning of your Markdown file, using an inline YAML block, separated by two lines containing only ---:

---
author: Joan Doe
title: Some (short) book
lang: en

output.html: some_book.html
---

# Some (short) book

The book content, formatted in Markdown.

This method only allows to set up options: you can’t include a list of chapters in this way, since the only “chapter” that will be included is this Markdown file itself.

You can then use

crowbook --single some_book.md

to generate output formats from this Markdown file.

By default (unless input.yaml_blocks is set to true), Crowboook will only read those inline blocks when it is runned with crowbook --single (or crowbook -s).

There are various options to include a Markdown file.

So a typical usage might look like this:

! copyright.md
- preface.md
0. chapter_0.md # We want to start at chapter 0 instead of 1
# Next chapters can be numbered automatically
+ chapter_1.md
+ chapter_2.md
...

There are two important things to note:

  1. you must not use quotes around the file names.
  2. the path of these files are relative to the directory where your configuration file is. This means you can run crowbook books/my_trilogy/first_book/config.book without being in the book’s directory.

Also note that you don’t have to specify a title. This is because the title of the chapter is inferred from the Markdown document. To go back to our previous example:

+ chapter_1.md

does not specify a chapter title, because it will read it directly in chapter_1.md, e.g.:

The day I was born
==================

...

You should have one and only one level-one header (i.e. chapter title) in each markdown file.

If you have more than one, Crowbook will print a warning and treat it as another chapter (numbered according to the scheme specified for including the file). It might however mess the table of contents in some cases (e.g. for Epub).

If you do not have a level-1 header in a markdown file:

The first part of the configuration file is dedicated to pass options to Crowbook. This is YAML syntax, so each line should be of the form key: value. Note that in most cases you don’t have to put string in quotes, e.g.:

title: My title

It is however possible (and sometimes necessary) to escape some characters to use quotes around strings:

title: "My: title!"

It is possible to use multiline strings with >- and then indenting the lines that are part of the string:

title: >-
 A
 long
 title
author: Joan Doe

will set title to “A long title”. See block literals in YAML for more information on the various way to insert multiline strings (which mostly change the way newlines will or won’t be inserted).

A final note on the syntax: all options must be set before the first chapter inclusion (that is, a line beginning with ‘+’, ‘-’, ‘x.’ (where x is a number) or ‘!’).

Here is the complete list of options, with a short description. The usage of some of them is detailed later on.

Note that these options have a type, which in most case should be pretty straightforward (a boolean can be true or false, an integer must be composed by a number, a string is, well, any string). The path type might puzzle you a bit, but it’s equivalent to a string, except Crowbook will consider it relatively to the book file. The template path type is just the path of a template. Metadata are just strings.

Metadata are data about the book. Except for cover, which points to an image file, all its fields are strings. The main metadata are:

There are also additional metadata:

You can define your own metadata by starting an option name with metadata.foo.

All metadata are accessible from templates, see Templates.

The special import_config option allows you to include the options of another book configuration file. E.g., assuming that you want some common options to be applied to both foo.book and bar.book, you can create a common.book file:

author: Joan Doe
lang: en
license: "Copyright (C) Joan Doe. All rights reserved."

html.header: "[Joan Doe's website](http://joan-doe.com)"
tex.template: my_template.tex

You can then include this file in foo.book:

import_config: common.book
title: Foo

+ foo_01.md
+ foo_02.md

Or include it in bar.book, but override some of its features:

import_config: common.book
title: Bar
license: CC-BY-SA  # Override the license from common.book

+ bar_01.md

These options specify which files to generate.

Recall that all file paths are relative to the directory where the config file is, not to the one where you run crowbook. So if you set

output.epub: foo.epub

and runs

$ crowbook some/dir/config.book

foo.epub will be generated in some/dir, not in your current directory.

Crowbook will try to generate each of the output.xxx files that are specified. That means that you’ll have to set at least one of those if you want a call to

$ crowbook my.book

to generate anything. (It’s still possible to generate a specific format, and only this one, by using the --to argument on the command line).

Note that some formats depend on some commands being installed on your system. Most notably, Crowbook depends on LaTeX (xelatex by default, though you can specify the command to use with tex.command) to generate a PDF file, so PDF rendering won’t work if it is not installed on your system. Crowbook also uses the zip command to generate the EPUB and ODT files.

Current output options are:

(There are other output options for generating proofreading files, see Proofreading.)

Additionally, the output.base_path option allows you to set where the output files will be written (relatively to the book configuration file). E.g.,

output.base_path: docs/book
output.epub: book.epub

will render the EPUB file in docs/book/book.epub.

Crowbook does its best to improve the typography of your text. Default settings should be good enough for most usages, but you can enable/disable specific options:

These options allow to configure the rendering; they are used (or at least should be) for all formats.

An integer that represents the maximum level of numbering for your book. E.g., 1 will only number chapters, while 2 will number chapters, sections, but not anything below that. 6 is the maximum level and turns numbering on for all headers.

default: 1

A string that will be used for chapter titles. You can use {{{number}}} and {{{title}}} in this string, e.g.:

numbering_template: "Chapter {{{number}} {{title}}}"

Note that:

It is possible to include Markdown formatting in this template, but it isn’t advised, because it might cause problems for some formats (e.g. your EPUB file might not be correct anymore).

These options allow to embed additional files for some formats (currently, only EPUB). This can be useful for embedding fonts.

A list of files or directories that should be added. It’s a whitespace-separated list, so it can be, e.g.:

resources.files: font1.otf font2.otf

It is also possible to specify a directory (or multiple directories). So if you have a fonts directories containing font1.otf and font2.otf,

resources.files: fonts

will be equivalent to:

resources.files: fonts/font1.otf fonts/font2.otf

default: not set

This option determine where (in which directory), in the resulting document, those files will be copied. The default is data, so by default the resources.files in the first example above will search font1.otf and font2.otf in the same directory than the .book file, and will copy them to data/font1.otf and data/font2.otf in the EPUB file. This is therefore this last path that you should use if you want to access those files e.g. in a custom CSS stylesheet.

Note that if you pass directories to resources.files, the whole directory would be copied. So assuming fonts/ contains font1.otf and font2.otf

resources.files: fonts
resources.path: data

will copy these two files to data/fonts/font1.otf and data/fonts/font2.otf (and not data/font1.otf and data/font2.otf).

Similarly, the whole path of resources.files is copied, so

resources.files: fonts/font1.otf fonts/font2.otf

will yield the same result.

default: data

4. Templates »