Fonts and colors customization

Sometimes, you may want to use a built-in theme, but customize the fonts and colors of your book to match your branding or personal preferences. Bookly allows you to override the default fonts and colors by providing your own definitions to the fonts and colors arguments of #bookly.with.

Fonts

To use a custom font set, provide bookly with a fonts argument containing a dictionary with the following keys:

Key
<size>: 11ptlength

Size of the body text. The size of raw text is set to 0.8 times this value.

Key
<body>: "New Computer Modern"string|array

Font family for the body text.

Key
<math>: "New Computer Modern Math"string|array

Font family for mathematical equations.

Key
<raw>: "DejaVu Sans Mono"string|array

Font family for raw text, such as code snippets.

These defaults are exported by the template as default-fonts:

#let default-fonts = (
  size: 11pt,
  body: "New Computer Modern",
  math: "New Computer Modern Math",
  raw: "DejaVu Sans Mono",
)

Let’s say you want to use “Lato” for the body text, “Lete Sans Math” for equations, and “Cascadia Code” or “Fira Code” (depending on font availability) for raw text, with a font size of 10pt. You can define your custom fonts as follows:

#let my-fonts = (
  size: 10pt,
  body: "Lato",
  math: "Lete Sans Math",
  raw: ("Cascadia Code", "Fira Code"),
)

Then, apply them to your book by passing the my-fonts dictionary to the bookly function:

#show: bookly.with(
  fonts: my-fonts,
)
Note
You don’t have to provide every key of the fonts dictionary. The dictionary you provide is merged with default-fonts, so if you only want to change the math font, you can just provide the math key and the other fonts keep their default values.

Colors

Colors are customized the same way. Provide a colors argument to the bookly function, containing a dictionary with the following keys:

Key
<primary>: rgb("#c1002a")color

Primary color of the book, used for chapter numbers, headings ornaments, links in tables of contents, etc.

Key
<secondary>: rgb("#dddddd").darken(15%)color

Secondary color, used for rules and other secondary ornaments.

Key
<boxeq>: rgb("#dddddd")color

Background color of the equation boxes created with boxeq.

Key
<header>: blackcolor

Color used for adapting the color of the document headers.

These defaults are exported by the template as default-colors:

#let default-colors = (
  primary: rgb("#c1002a"),
  secondary: rgb("#dddddd").darken(15%),
  boxeq: rgb("#dddddd"),
  header: black,
)

Let’s say you want to use a blue primary color and a light blue background for the equation boxes. You can define your custom colors as follows:

#let my-colors = (
  primary: rgb("#014682"),
  boxeq: rgb("#e6eef6"),
)

Then, apply them to your book by passing the my-colors dictionary to the bookly function:

#show: bookly.with(
  colors: my-colors,
)
Note

As for fonts, the colors dictionary you provide is merged with default-colors, so you only need to give the keys you want to change.

The resulting colors are stored in the states.colors state. When writing a custom theme, use states.colors.get() (inside a context) or the colors argument passed to the theme function, so that your theme follows the colors chosen by the user.