Parts, Chapters and Sections
Parts
To start a new “Part” in your book, you start a line with -# followed by the title of the Part.
1 -# Part 1
Chapters, Sections and Sub-sections
Chapters are started by a single #. Sections with two ##, sub-sections with three ### all the way down to sub-sub-sub-sections #####.
1 # Chapter 1
2
3 ## Section 1.1
4
5 ### Sub-section 1.1.1
6
7 #### Sub-sub-section 1.1.1.1
8
9 ##### Sub-sub-sub-section 1.1.1.1.1
Please note that only lines of text with one or more number signs will show up in the Table of Contents (you can control what level of hierarchy you want to show up in your Table of Contents in the Settings section for your book).
Table of Contents
Leanpub automatically generates a Table of Contents for you. It will show Chapter headings in bold in a large font.
Front Matter, Main Matter and Back Matter
Authors often want their books to be composed of distinct front, main, and even back ‘parts’. For example, an Introduction will be numbered separately from the main chapters of the book. So an Introduction might be numbered (if you want numbering) 1, and then for Chapter One the numbering will start over at 1.
To format sections as front matter (like an introduction), main matter (the chapters of your book) and back matter (an appendix, say), you just need to type the following at the point where you want the front matter, main matter or back matter section to begin:
{frontmatter}
{mainmatter}
{backmatter}
Each instruction should be on a line by itself, with blank lines above and below it. Unless the instruction is the first line in a .txt file, in which case you just need a blank line below it.
We do generally recommend that each instruction for a part should have its own file, so things are clear in book.txt. That means you should have a separate file that contains only the e.g. backmatter instruction and is called “backmatter.txt”.
Introduction & Acknowledgments
These sections are usually included at the front of the book as front matter. Files designated as front matter will be numbered as a separate set of files and their page numbers will be roman numerals (i.e. 5 is V). This means that when you start the next section, the numbering starts over.
To designate that a section is front matter, at the beginning of the section, just type:
{frontmatter}
on a separate line, with blank lines above and below it.
When you want the ‘mainmatter’ section to start, just type:
{mainmatter}
at the start of the main matter section (or at the end of the front matter section) on a separate line, with blank lines above and below it.
One easy way to do this is to make a separate text file that just contains the syntax indicating the start of the section.
So you could create a new text file, and just type:
{frontmatter}
and nothing else! If you save the file as frontmatter.txt in your Book.txt file, it might look like this:
frontmatter.txt
introduction.txt
and Leanpub will know to format introduction.txt as front matter.
Front matter has no section numbering, even if you have turned on section numbering for the rest of your book.
Also, you only need to give each instruction once, and that instruction applies to everything that comes after, unless you type a new instruction. So if you type {frontmatter} in one file, everything after it will be frontmatter until you type {mainmatter}.
Appendix, Appendices, Index
These sections are usually included at the back of the book as back matter. Back matter has no section numbering, even if you have turned on section numbering for the rest of your book. However, page numbering continues unchanged.
To designate that a section is back matter, at the beginning of the section, just type:
{backmatter}
on a separate line, with blank lines above and below it.
Front Matter, Main Matter, and Back Matter Example
1 {frontmatter}
2
3 # Preface
4
5 This is the first front matter section.
6
7 # Introduction
8
9 This is the first front matter section.
10
11 {mainmatter}
12
13 # Chapter One
14
15 This is the first main matter section
16
17 # Chapter Two
18
19 This is the second main matter section
20
21 # Chapter Three
22
23 This is the third main matter section.
24
25 {backmatter}
26
27 # Appendix One
28
29 This is the first back matter section.
30
31 # Appendix Two
32
33 This is the second back matter section.