Part of the Lekhak guide.
Templates and export
What a template is
A template decides how an export looks. It is a folder of fragments — small pieces of HTML — plus a print configuration file, and Lekhak reads them to dress your manuscript.
You do not have to write one. Five sets ship with Lekhak, listed under View → Template Sets:
- default — the ordinary book: title, prose, pages.
- short story — a unit-dressed collection on A4.
- Book — one page per kind of thing, named after the Type it dresses.
- Guide — a manual: a shaded heading page and a section page, the two Types this guide is written in.
- no-export — prints nothing at all. It is there to keep a folder out of an export, and to show that silence is a valid answer.
They live in the software, so there is nothing on disk to edit. Right-click one and choose Duplicate into project… to get an editable copy in your own project.
A set can dress one format differently: a subfolder named epub, html, docx, pdf or text overrides the parent set for that format only. A document can name its own document template in the inspector to override the set. The Templates view (View menu) lets you edit templates; the CSS editor writes the set’s style.css for HTML and EPUB.
Scope for export can be the whole project, a folder, or a selection (folders expand). no-export keeps a folder out of an export.
Editing a template
The easiest way to make a new template is to duplicate a default set in View → Template Sets, open the copy, and make the changes you need. A fragment is HTML with placeholders in it:
<p class="chapter-title">$${Title}</p> <div class="children">$${children}</div>
$${Title} is the document’s title. $${Content} is its prose. $${children} is everything inside it, each child dressed in the template that applies to it, in the order you arranged them. Naming the children is optional: an export always walks the selection in order, so a fragment that never mentions them has them printed right after itself. The placeholder is for positioning — a chapter that should carry a closing note after its scenes puts $${children} first, then the note.
The Placeholders… button in the template panel lists every name Lekhak knows, with what each one means — including the fields of your own project and the Types in it. It is also how a name gets written: click one and it lands, complete, at the cursor of the box you were in. Typing the placeholder also works. The buttons are merely to prevent errors that may prevent the correct insertion of the data.
If you spell a name wrong, the template still saves and Lekhak tells you: this template names a placeholder Lekhak does not know. Saving anyway is deliberate — a template can be written before the document or the field it names exists. At export, a placeholder that still has no value prints nothing: the name is removed and replaced with nothing.
As well as the config box, the panel gives the page’s print settings as fields — they shape DOCX and PDF exports. Page size, margins, mirror margins and page start are rows you pick from. Below them, the Header and footer rows hold the running head and foot as the three places a piece can sit — left, middle and right. A pick above them says which pages the rows are speaking for: the Main body, the Facing pages (even) that a mirrored book prints differently, or the First page, each section’s opening page — the one a chapter opener usually leaves bare. A row you leave empty keeps the sample’s own head; tick None and these pages carry no head at all. Each row writes one Header: or Footer: line into the config box, so the box stays the truth and nothing is hidden behind the fields. Below the rows, Header and footer font writes the running heads’ own family and size as a single Head font: line, for the header and the footer both; left alone, the sample’s own head stands. If you never export for print, you can safely ignore these fields.
Choosing what to export
File → Export… asks two things: what to include, and how to dress it.
The scope is the selection in the binder, or the whole project if nothing is selected. You can select several folders and documents at once; the export takes them all, in binder order. Selecting a folder exports what is inside it.
The dialogue offers the template your content asks for. Assign a template in the metadata of a folder and everything below it inherits the assignment, until another folder overrides it; the deepest assignment inside the selection is the one offered. Export a chapter from a book folder and the book template’s folder and document fragments still dress its scenes. The pick is a default you may change, and the change is one-off: the next export offers the detected template again. To make a choice stick, assign it to the topmost folder it should cover.
A set can dress one format differently from the rest. A folder inside it named after a format — docx, pdf, epub, html or text — applies to that format only, and the set’s own files cover every format without one. So one set with a docx folder can print one design and hand EPUB another, from the same assignment.
Between the placeholders and the template a scope asks for, a book can be dressed in as much detail as it needs — and when nothing matches, the export is still valid: the default template’s folder and document fragments print the selected material.
Formats
- Plain text — for pasting anywhere.
- HTML — one file, with a stylesheet.
- DOCX — for Word, and the basis of the PDF.
- PDF — via LibreOffice, if it is installed.
- EPUB — the ebook.
File → Print… (Ctrl+P) makes the same PDF and hands it to your system printer.
Page setup
The book folder’s Page setup button is where paper lives: page size or a named trim, the margins, mirroring for a book, and the gutter at the spine. Set it on the book folder — the nearest one above the document wins, so a series folder can give all its books one trim. Where pages begin and what the running heads say are not in this dialogue: those belong to the template’s design, in the template panel.
A template’s own configuration overrides page setup, and page setup overrides the built-in A4 — so you can set the trim once for the project and let a template change it only when it has an opinion.
The running heads and feet read placeholders. A line like Header right: , ,$${PageNo} puts the page number at the right of every page. $${PageNo} is a position, not a count: Word or LibreOffice fills the number in, so it stays right as the text reflows. You can also put $${PageNo} on a line of its own in the text, and the export writes the number at that spot. Formats with no fixed pages — HTML, EPUB and plain text — print nothing for it.
$${BookTitle} names the book you are exporting: the folder you chose, or the project’s own title when you export the whole project. Export a single document or chapter and there is no book, so it prints nothing — nothing is ever invented to fill it.
A running head on a chapter’s opening page usually looks wrong, and most books leave it off. Header first page: none says so; Header first page: , ,$${BookTitle} says the opposite, an opening page with a head of its own. The footer has the same pair. These lines speak for each section’s opening page — every chapter, where chapters start a new section.
Running heads are often set smaller than the body. Head font: Georgia, 9 gives the header, the footer and the page number their own family and size, and leaves the body’s typography alone.
Page size accepts inches, millimetres, named sizes (such as A4) or values like 5x5. A divider between child documents (in page setup) can print a separator such as * * * between children of a folder, or nothing at all.
print-config.txt in a template overrides page setup; a sample .docx supplies the rest. Page setup applies only where the template is silent.