Glyph - Document Structure

Every Glyph project contains a document.glyph file that is typically used to define the document structure. The default document.glyph generated automatically when creating a new project is the following:

 1book[
 2  @frontmatter[
 3    toc[]
 4    preface[
 5      @title[Preface]
 6      todo[Write the preface]
 7      include[preface]
 8    ]
 9  ]
10  @bodymatter[  
11    chapter[ 
12      @title[Chapter 1]
13      todo[Write chapter 1]
14      include[chapter_1]
15    ]
16    chapter[
17      @title[Chapter 2]
18      todo[Write chapter 2]
19      include[chapter_2]
20    ]
21  ]
22  @backmatter[
23    appendix[
24      @title[Appendix A]
25      todo[Write appendix A]
26      include[appendix_a]
27    ]
28  ]
29]

Even without knowing anything about Glyph Language, you can easily figure out that this file defines a document with a Table of Contents, a Preface some Chapters and an Appendix.

As you can see, Glyph wraps portions of text within square brackets preceded by an identifier. These identifiers are used for macros and attributes. The only syntactic difference between macros and attributes is that attributes are preceded by a @.

For now, think about a macro as something that performs a certain action and — generally — produces some text output or manipulation of the text inside it. In this way, it becomes easy to understand that the chapter macro creates a chapter and the include macro includes an external file, for example.
Attributes “belong” to the macro they’re in, so in this case the book macro has the following attributes:

  • @frontmatter
  • @bodymatter
  • @backmatter

More specifically, in this document.glyph file:

  • The book macro wraps every other macro and is used to create the document header and default title page.
  • Then, the @frontmatter, @bodymatter, and @backmatter attributes are used to divide the portions of your document according to the rules of book design. They are not mandatory, but they can be used, for example, to number your appendixes with letters instead of numbers and similar.
  • preface, chapter, appendix are just a way to wrap content in <div> tags, from an HTML point of view (or <section> tags, in HTML5), but they are also necessary to nest the content of your document and generate the Table of Contents automatically, together through @title attributes.