Glyph – Compiling a project

By default, a Glyph project can be “compiled” into an HTML document. Additionally, Glyph can also be used to produce documents in the following formats:

  • HTML5
  • PDF (generated from HTML using a third-party generator like Prince or wkhtmltopdf)
  • Web (i.e. multiple HTML files)
  • Web5 (i.e. multiple HTML5 files)

HTML/HTML5 output

To compile a Glyph project to an HTML document, use the compile command within your Glyph project folder. Glyph parses the document.glyph file (and all included files and snippets); if no errors are found, Glyph creates an HTML document in the /output/html folder.

The name of the HTML file can be set in the configuration (document.filename setting).

To create an HTML5 file instead, you must specify it explicitly like this:

glyph compile -f html5

PDF Output

To generate a PDF document, you must specify pdf as format, like this:

glyph compile -f pdf

The command above will attempt to compile the project into an HTML document and then call a third-party PDF generator to convert it into a PDF file.

Currently, Glyph supports:

  • Prince (version 7.0 or higher) — a commercial generator that can be used freely for personal use. Prince produces high-quality PDF files and implement most of the new features introduced in CSS3, used heavily in Glyph’s pagination.css default stylesheet.
  • wkhtmltopdf (version 1.0 beta4 or higher) — an open source generator that uses the WebKit rendering engine to transform HTML files into PDF. Although not as advanced as Prince, it produces very satisfactory results.

By default, Glyph attempts to use wkhtmltopdf. To change this, set the output_pdf_generator setting to prince.

EPUB/MOBI output

To generate .epub or .mobi e-books, you must specify epub or mobi as format, like this:

glyph compile -f mobi

glyph compile -f epub

This option requires that you have Calibre and its command-line tools installed. Glyph assumes the ebook-convert command is installed in /usr/bin. If this is not so, you can set the options.ebook.converter option to the path to the ebook-convert command.

If you have cover art for your e-book, put it in the images folder, and specify the name of the file in the document.cover configuration option.

You can also specify the output profile used by the ebook-convert command by setting the output.epub.profile and output.mobi.profile options. If these are not specified, the conversion will use the kindle output profile for mobi files, and the nook output profile for epub files. See the documentation for Calibre for a list of available output profiles.

Web/Web5 Output

To generate a Web or Web5 output, specify web or web5 as format. These two output formats behave different way from the others, and require that your project uses topics and layouts.

Basically, here’s what happens when you compile your project in web or web5 format:

  1. The document code is parsed as normal
  2. Separate topic files are generated according to the @src attributes of your sections
  3. The document.glyph (or whatever file you’re using as document source) is not rendered. Instead, an index.html file will be created in the output folder based on the contents of your index layout.

Auto Regeneration

You can also call the compile command with a --auto switch. If you do so, your project will be recompiled automatically every time any source file is changed.