I have quite a few documents which use fundamentally the same template, but with minor changes (e.g. a different colour scheme, font, or logo).
At the moment, my projects import template.typ for general settings. template.typ then imports assets.typ where I store these variable settings (e.g. defining which image is “Logo” or which font to use). I am having to use separate projects for each theme.
This looks something like:
///IKEAexample.typ
#import "template.typ": *
#show: project.with(
documentname: "IKEA thingy",
authors: "Hurtleberry",
pubyear: "2025"
)
...(and then the main document content)
///template.typ
#import "assets.typ": *
#import "ogl.typ": *
#import "blocks.typ": *
...(all the other stuff in the template)
///assets.typ
#let logo = "IKEA.png"
#let coverimage = "IKEAcover.jpg"
#let logowidth = 1cm
#let logoheight = 1cm
#let bodyfont = "Barlow"
I would like to be able to put all these documents in a single Typst project, and tell it to pick a group of settings based on the theme. So I could flag document A as being IKEA-themed, document B as NHS-themed, and so on to have the correct logos, fonts, and colour schemes turned on.
To me, the natural approach involves setting a parameter in the document (#let theme = “IKEA”), grouping the settings in #if statements, and then either passing the parameter to the #import, or having the import simply use the value I’ve already defined. e.g.
///in exampledocument.typ
#let theme = "IKEA"
#import template.typ
///in template.typ
#if theme = "IKEA" [
#let logo = "IKEAlogo.png"
#let coverimage = "IKEAcover.jpg"
#let logowidth = 1cm
#let logoheight = 1cm
]
else
[
#let logo = "NHSlogo"
#let coverimage = "NHScover.jpg"
#let logowidth = 2cm
#let logoheight = 2cm
]
However, the variable is not accessible by the files I’m importing, so I get unknown variable errors. As usual I’m probably missing something obvious ![]()
Is there a way to do this, or more generally, to achieve this idea of having different themed sets within a project that can be called on by individual documents?