Your Own Style
A book can carry a style of its own, kept with the text: in the book's repository, or in the folder you open in the editor. It builds on one of Typoteka's styles and changes what you want changed.
Layout
text
my-book/
typoteka.json
chapter-1.md
styles/
mine/
style.json optional: name, parent style, typefaces
styles.css required
fonts/
display.woff2Point the book at it in typoteka.json:
json
"style": { "path": "styles/mine" }To share one style between several books, keep it in its own repository and name it there:
json
"style": { "repo": "owner/book-styles", "ref": "main", "path": "styles/mine" }style.json
json
{
"id": "mine",
"name": "My Frankenstein",
"extends": "novel",
"fonts": [
{
"family": "Display",
"faces": [{ "file": "fonts/display.woff2", "weight": "400", "style": "normal" }]
}
]
}nameis what the editor's style gallery shows. Without astyle.json, the style is named after its directory.extendsis the id of the style it builds on (base,novel, …, as on each style's page). Without it, the style builds on Base. Your stylesheet loads after that style's, so a rule of yours with the same selector wins.fontslists the typefaces the editor should load before it lays the book out, so the first render already measures text in them.blockslists the blocks the style defines for authors, each with aclass(::: monster) and alabeldescribing it. A block can also say what it is for, withfor:"table","image","text", or several of them (["table", "image"]). Right-clicking a table or an image in the book offers the blocks for it (see Editing)."text"is a block wrapped around a passage of text, such as a monster's statistics or a note: the visual editor offers it under Wrap in a block. A block withoutforis not offered anywhere.
styles.css
Plain CSS. The layout blocks and the parent style's rules are already in place; write only what differs:
css
@font-face {
font-family: 'Display';
src: url(fonts/display.woff2) format('woff2');
}
.chapter h2 {
font-family: 'Display', serif;
}Relative url()s (typefaces, images) are resolved against the style's own directory and loaded with it. Addresses on other sites are left as written.
Write selectors as for a page of your own: p, h1, body, :root. The book is drawn inside the editor, but a style's rules reach only the book, never the editor around it, and the editor's own CSS does not reach the book. body, html and :root stand for the book's root, so custom properties and a typeface set there apply to the whole book. A background for the paper belongs in @page, not on body.
The book starts from the browser's defaults with a few corrections: no default margins or padding, box-sizing: border-box, headings and links that inherit their size, weight and colour, images that are blocks no wider than their column, and lists that keep their markers. Any rule your style writes wins over these, however light its selector.
Some CSS draws on screen but not in a PDF printed from Firefox, so a book exported there loses it: masks (mask-image), blend modes (mix-blend-mode, background-blend-mode) and SVG images with filters (the noise of a paper texture, for example). Cut shapes with clip-path, darken with a semi-transparent layer, and use a PNG or WebP for a texture.
In a style with columns and headings that span them (column-span: all), two things keep different browsers breaking pages alike: leave column-fill at balance, its default (with auto, Firefox does not share the text out before such a heading, and Chrome does), and float images inside a figure that is not split, figure { display: flow-root; break-inside: avoid } with figure img { float: left } (an image in the flow after such a heading that does not fit at the foot of a page makes Firefox carry all the text after the heading to the next page). See Browsers.
hyphens, orphans and widows work as CSS says in every browser: the editor breaks words itself where a style sets hyphens: auto, and keeps a paragraph's lines together as orphans and widows ask, also in Firefox, which does not implement them (both can be turned off in a project's advanced settings).
The table of contents comes laid out by the shared layer: each level further in, dot leaders, the page number at the end, on pages of its own. A style restyles it through these classes:
| Element | What it is |
|---|---|
.contents | The table. |
h1.contents-title | Its title ("Contents", "Índice"). It is an h1, so it feeds the running heads as a chapter's title does. |
.contents-list | The list of entries; set it in columns with columns: 2. |
.contents-entry.contents-level-1 | A chapter; -level-2 and -level-3 are its sections. Hide a level with display: none. |
.contents-entry a::before | The dot leader. |
.contents-entry a::after | The page number (target-counter(attr(href), page)). |
A cover (::: cover) is a div.cover on a named page, cover, whose margins and margin boxes the shared layer empties. Its image is absolutely placed over the whole block, under everything else in it. A style styles the rest: .cover h1 { color: white; padding: 20mm 15mm 0; } puts a title over the picture, and @page cover { background: #111; } paints the paper behind an image that does not reach the edges.
Running heads, page numbers and everything else in the page margins are covered in Page margins.
CSS only
A style kept with a book cannot run scripts. A style.json that lists handlers is refused: the book renders in Base and the editor shows a Warning in the status bar saying why. Handlers are scripts, and running one from a book's repository would run that repository's code in your editor.