Build a project theme¶
A theme gives the same content two reading forms: a website and a book. This tutorial builds an Orbit theme with a shared visual identity, an HTML partial and macro, and a modular PDF template. It needs no plugin or compiler.
1. Start with a real project¶
Use Guidedog 1.0.0-beta.9 or newer. Run this from the directory that will contain orbit:
guidedog quickstart orbit -q -p "Orbit Field Notes" -a "Orbit contributors" -v 1.0
Rename the generated orbit/_templates/book.typ to base-book.typ in the
same directory. Keep the generated theme.typ beside it; the renamed book template
supplies the tested page layout, cover,
running heads, contents, code styles and optimized paragraph breaking.
Download conf.toml,
index.rst and
reading.rst.
Save the first two in orbit and the third in orbit/chapters.
The finished project will have these files:
orbit/
conf.toml
index.rst
chapters/reading.rst
_templates/
layout.html
macros/ui.html
partials/edition.html
theme.typ # Shared PDF theme generated by quickstart.
discussion.typ # Discussion layout generated by quickstart.
article.typ # Standalone article layout generated by quickstart.
base-book.typ # Generated by quickstart; renamed, not replaced.
book.typ
palette.typ
_static/
guidedog.css # Generated by quickstart.
guidedog.js # Generated by quickstart.
typography.js # Generated by quickstart.
theme.css
2. Set the contract¶
The downloaded configuration selects the local template and static directories.
html_css_files adds our stylesheet after the default stylesheet.
html_context supplies a project value to Jinja. The explicit PDF filename
makes the output easy to find.
project = "Orbit Field Notes"
author = "Orbit contributors"
version = "1.0"
release = "1.0"
language = "en"
root_doc = "index"
source_suffix = [".rst"]
exclude_patterns = ["_build", "README.md"]
templates_path = ["_templates"]
html_static_path = ["_static"]
html_css_files = ["theme.css"]
numfig = true
pdf_paper_size = "a4"
[html_theme_options]
accent = "#2658a0"
[html_context]
edition_label = "Field edition"
[[pdf_documents]]
root = "index"
file = "orbit-notes.pdf"
title = "Orbit Field Notes"
author = "Orbit contributors"
All paths in this tutorial are project files. HTML templates are found through
templates_path. The PDF entry point is always _templates/book.typ under
the source directory. Changing templates_path does not move it.
3. Extend the HTML layout¶
Save layout.html
as orbit/_templates/layout.html. Replace the generated file completely:
{% extends "!layout.html" %}
{% import "macros/ui.html" as ui %}
{% block extrahead %}
{{ super() }}
<meta name="theme-name" content="Orbit field notes">
{% endblock %}
{% block body %}
<p class="orbit-kicker">{{ ui.tag(edition_label) }}</p>
{{ super() }}
{% endblock %}
{% block footer %}
{{ super() }}
{% include "partials/edition.html" %}
{% endblock %}
!layout.html selects Guidedog’s built-in layout. Without !, a template
named layout.html would try to extend itself. super() keeps the parent’s
block content. Navigation, search, theme controls and accessible landmarks remain
in the base layout. Our blocks add a label, metadata and an edition footer.
A theme changes presentation. A build plugin changes source text, complete HTML or generated assets. Use Write a plugin when a template cannot express the required operation. Ordinary layout changes need no native code.
4. Give repeated markup one home¶
Create orbit/_templates/macros and orbit/_templates/partials.
Save ui.html
and edition.html
at the matching paths:
{% macro tag(label) %}<span class="orbit-tag">{{ label|e }}</span>{% endmacro %}
<p class="orbit-edition">
<span>{{ project|e }} / {{ release|e }}</span>
<a href="{{ pathto('chapters/reading') }}">Reading a measurement</a>
</p>
A macro takes explicit inputs. An included partial uses the current page’s
context. Escape plain project values with |e. Use pathto for document
links: a hard-coded chapters/reading.html would break on a nested page or
with another HTML builder.
5. Design for the reader’s theme¶
Save theme.css as
orbit/_static/theme.css:
/* Typography and measure are shared. Color follows the reader's chosen scheme. */
:root {
--gd-measure: 43rem;
--gd-radius: 4px;
--gd-bg: #fdfbf6;
--gd-bg-soft: #f3f0e7;
--gd-text: #202c28;
--gd-muted: #53605a;
}
:root[data-theme="dark"] {
--gd-bg: #141c22; --gd-bg-soft: #1b2832;
--gd-text: #eaf1f6; --gd-muted: #b0c0cb;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--gd-bg: #141c22; --gd-bg-soft: #1b2832;
--gd-text: #eaf1f6; --gd-muted: #b0c0cb;
}
}
.gd-article { font-family: Georgia, "Noto Serif", serif; font-size: 1.12rem; }
.gd-article p { line-height: 1.7; hyphens: auto; text-wrap: pretty; }
.gd-article :is(h1, h2, h3) { font-weight: 700; hyphens: none; text-wrap: balance; }
.gd-article h1 { font-size: clamp(2.4rem, 5vw, 3.6rem); letter-spacing: -.025em; }
.gd-header { border-top: 3px solid var(--gd-link); }
.orbit-kicker { margin-bottom: 1rem; }
.orbit-tag {
display: inline-block; padding: .2rem .65rem;
font: 700 .75rem/1.5 var(--gd-sans); letter-spacing: .08em;
border: 1px solid var(--gd-link); border-radius: 3px; color: var(--gd-link);
}
.orbit-edition {
display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: space-between;
font: .85rem/1.6 var(--gd-sans); color: var(--gd-muted);
}
img.graphviz-adaptive { display: block; margin: 1.5rem auto; padding: 1rem; }
@media print {
:root { color-scheme: light; --gd-bg: #fff; --gd-text: #202c28; --gd-muted: #53605a; }
.orbit-tag { color: #202c28; border-color: currentColor; }
.gd-article p { orphans: 3; widows: 3; }
}
The built-in theme follows the system scheme by default, and the existing control selects system, light or dark and saves the choice. Explicit dark rules and the system media query use the same tokens. Typography and spacing stay shared. No new JavaScript is needed. Avoid a fixed ink color on a background whose theme can change.
_static/typography.js optimizes desktop English paragraphs with Knuth-Plass line
breaking and Liang hyphenation, while guidedog.css falls back cleanly to
text-wrap: pretty when JavaScript is disabled or on narrow screens; see
Typography for reading.
Diagrams with :class: graphviz-adaptive use the selected scheme in current
Guidedog builds. Ordinary graphs retain their own colors. Older hosts render
the same DOT in its light palette. See Diagrams with Graphviz and Typst for semantic
node classes and print behavior.
6. Wrap the PDF book¶
Save palette.typ
and book.typ in
orbit/_templates. These are new files; keep base-book.typ beside them.
#let palette = (
accent: rgb("#2658a0"),
size: 11pt,
serif: ("Libertinus Serif", "New Computer Modern"),
sans: ("Libertinus Sans", "DejaVu Sans", "Libertinus Serif"),
)
#import "base-book.typ": book as base-book
#import "palette.typ": palette
// guidedog: margin-x = 31mm
// Keep the host's parameters explicit. The final positional argument is content.
#let book(
title: "", author: "", version: "", date: "", lang: "en", paper: "a4",
numbering: false, logo: none, copyright: "", version-label: "Version", body,
) = base-book(
title: title, author: author, version: version, date: date, lang: lang,
paper: paper, numbering: numbering, logo: logo, copyright: copyright,
version-label: version-label, accent: palette.accent, size: palette.size,
serif: palette.serif, sans: palette.sans, page-ref: n => [p. #n], body,
)
The host calls book with metadata and the chapter content. The wrapper
forwards those values to the generated base and supplies our palette. Passing
body into the styled function keeps its rules in scope. The web stylesheet
does not affect PDF, and the Typst template does not affect HTML.
The base handles language-aware hyphenation and optimized line breaking. The wrapper keeps those rules, uses the matching blue accent and adds page numbers to document cross-references. PDF always uses the light, print palette.
7. Build and inspect both forms¶
Run from the same parent directory as step 1:
guidedog build html orbit -W
guidedog build pdf orbit -W
guidedog build dirhtml orbit -W
guidedog build singlehtml orbit -W
guidedog serve orbit
Open the URL printed by serve. Check the chapter and generated search page,
not only the front page. Try light, dark and system modes. Resize the window.
Use the keyboard to reach the navigation and search. Change the footer partial,
save, then refresh: the preview rebuilds its template dependencies.
Open orbit/_build/pdf/orbit-notes-en.pdf in a PDF reader. Guidedog adds the
language suffix to the configured filename. Inspect the contents,
chapter opening, equation, table, code and diagram. Look for clipped labels,
loose paragraphs and missing glyphs. The other outputs are below
_build/html, _build/dirhtml and _build/singlehtml. Stop the server
with Ctrl+C.
8. Reuse and maintain the theme¶
Create another project with guidedog quickstart. Copy the finished
_templates directory and _static/theme.css into it. Add
html_css_files = ["theme.css"], the accent option and the edition_label
context value to its configuration. Change the footer’s document link to a page
that exists in that project. Keep the new project’s metadata and source tree.
The copied PDF base makes the theme self-contained. When we upgrade Guidedog, we create a scratch quickstart project and compare its templates with our saved base. We adopt the changes we need, then rebuild every target. The built-in HTML layout can change too. Small block overrides are easier to maintain than a second complete layout. For every variable and block, see Templates.
If the build reports a missing base-book.typ, finish the rename in step 1.
If the label is blank, set edition_label in html_context. If CSS is
missing, check both html_static_path and html_css_files. Read the file,
line and correction in the diagnostic before changing unrelated settings.