A customizable Typst letter template with some presets for DIN 5008 A/B and Swiss C5 Letter. Please note that the template is still under development and subject to breaking changes.
See the examples
-
lttr_init
is responsible to compute all values from the parameters and default values for different formats. It also sets thepage
andtext
attributes. -
lttr_preamble
renders:lttr_sender
lttr_receiver
lttr_indicator_lines
lttr_content_offset
lttr_horizontal_table
lttr_date_place
lttr_title
lttr_opening
-
lttr_closing
renders the closing line and the signature.
All Parameters are optional and will override the global defaults and the
defaults of the chosen format. Some of them allow to either specify the content
directly or use a dict if other settings need to be changed also. For example:
receiver: "x"
is the same as receiver: (content: "x")
.
-
debug
([Bool]
)
Whether or not to show (colorful) debug lines. -
format
([String]
)
Format of the letter ("DIN-5008-A"
,"DIN-5008-B"
,"C5-WINDOW-RIGHT"
,"C5-WINDOW-LEFT"
). -
_page
([Dict]
)
Set page settings (docs). -
_text
([Dict]
)
Set text settings (docs). -
settings
([Dict]
) Basic settings.content_spacing
([Length]
)
Minimum spacing between sender/receiver and letter content (or the horizontal table if present) and also the spacing after the horizontal table.justify_content
([Bool]
)
Wheter or not to justify the content.
Example:
settings: ( content_spacing: 8.46mm, justify_content: true, ),
-
indicator_lines
([Dict]
)
Info to render lines for the hole puncher and folding (see below).fold_marks
([Array]
)
Lenghts ([Length]
) from top of page of the fold marksshow_puncher_mark
([Bool]
)
Whether or not to show the puncher mark.
Example:
indicator_lines: ( fold_marks: (87mm, 87mm+105mm), show_puncher_mark: true, )
-
receiver
([Array, Content, Dict]
)
Info to render the receiver fields.content
([Array, Content]
)
Content of the receiver field.dimensions
([Dict]
)
Dimensions of the address field (width: [Length]
,height: [Length]
)fmt
([Function]
)
Rendering function which takes the receiver ([Dict]
) to format and show it.position
([Dict]
)
Position of the address field (top: [Length]
,left: [Length]
)spacing
([Length]
)
Spacing before the content.align
([Align]
) Alignment of the receiver field.
Example:
receiver: ( position: (top: 5cm) content: ( "Peter Doe", "Somestreet 16", "1234 New York", ), ),
-
return_to
([Array, Content, Dict, String]
)
The returning address.content
([Array, Content]
)
Content of the return_to field.dimensions
([Dict]
)
Dimensions of the return_to field (width: [Length]
,height: [Length]
)fmt
([Function]
)
Rendering function which takes the return_to ([Dict]
) to format and show it.position
([Dict]
)
Position of the return_to field (top: [Length]
,left: [Length]
)
Example:
return_to: "Some Address, I don't care...",
-
remark_zone
([Array, Content, Dict, String]
)
The remark zone.align
([Align]
)
Alignment of the remark_zone.content
([Array, Content, String]
)
Content of the remark_zone field.dimensions
([Dict]
)
Dimensions of the remark_zone field (width: [Length]
,height: [Length]
)fmt
([Function]
)
Rendering function which takes the remark_zone ([Dict]
) to format and show it.position
([Dict]
)
Position of the remark_zone field (top: [Length]
,left: [Length]
)
remark_zone: ( "This is a", "multiline remark", )
-
sender
([Array, Content, Dict]
)
Info to render the sender fields.content
([Array, Content]
) Content or array of lines for the sender field.fmt
[Function]
Rendering function which takes the sender ([Dict]
) to format and show it.position
([Dict]
)
Position of the sender field.width
([Length]
)
Width of the sender field.
Example:
sender: ( content: ( "John Doe", "Somestreet 15", "1234 New York", ) position: (left: 110mm, top: 20mm), width: 80mm, ),
-
horizontal_table
([Dict, Array]
)
A table to add before the date, time and title.content
([Array]
)
Array of of entries for the table where each entry is itself an array of exactly two items for title and body ([Content, String]
)fmt
([Function]
)
Formatting function which takes the title and body of a cell to format and show it.spacing
([Lenght]
) Spacing before the horizontal table.
Example:
horizontal_table: ( ("Ihr Zeichen", "Bananalover149"), ("Ihre Nachricht vom", "12.12.2022"), ("Unser Zeichen", "Bananenfabrik"), ("Datum", "12.08.2023"), )
-
opening
([Content, Dict, String]
)
Info to render thetitle
template (see below).content
([Content, String]
)
Content of the opening (e.g. "Dear Sir....").spacing
([Length]
)
Spacing before the letter opening.
Example:
opening: ( content: "Dear Sir or Madam,", spacing: 2mm, )
-
date_place
([Content, Dict, String]
)
Info to render thedate_place
template (see below).align
([Align]
)
Alignment of the place and datedate
([Content, String]
)
Date of the letter.place
([Content, String]
)
Place of the letter.
Example:
date_place: ( align: left, date: "20.04.2023", place: "Weitfortistan", ),
-
title
([Content, Dict, String]
)
Info to render thetitle
template. The title is also set as document property.content
([Content, String]
)
Content of the title.spacing
([Length]
)
Spacing before the title.
Example:
title: ( content: "Writing Letters in Typst is Easy", spacing: 2mm, )
-
closing
([Content, Dict, String]
)
Info to render the closingcontent
([Content, String]
)
Content of the closing (e.g. "kind regards").spacing
([Length]
)
Spacing before the closing.
Example:
closing: "kind regards"
-
signature
([Dict, none]
)
Info to render the signature.content
([Content]
)
Content of the signaturespacing
([Length]
)
Spacing before the signature.
Example:
signature: ( content: "Peter Pan (with the big Signature)", spacing: 16mm, )
lttr_state
prints the entire state used to render the components. This can be useful for debugging purposes.
- dvdvgt/typst-letter: A typst template for a DIN 5008 inspired letter with the goal to fit nicely into C6/5 envelops.
- qjcq/awesome-typst: Awesome Typst Links
Currently, I just create a symlink such that I can import it with #import "@local/lttr:0.1.0": *
as follows.
mkdir -p ${XDG_DATA_HOME}/typst/packages/local/lttr/
ln -s /path/to/this/repo ${XDG_DATA_HOME}/typst/packages/local/lttr/0.1.0
While there exists a first version of typst packages, they do not yet accept
custom templates (afaik). For the meantime, you can download and extract the
release tarball to ${XDG_DATA_HOME}/typst/packages/local/lttr/<version>
and
import it as described in Development Setup.
There are a couple of limitations in typst which I hope will be addressed.
- There is currently no way to query properties set with
set
. This would be nice to query the document title and author names issue. Forthermore, it is not possible to callset
after the first lttr function has been called (even if no content was rendered added). - datetime with locales settings
Other things:
- Add more layouts including (us letter, ?)
- Vertical table for sender field as for example here
- Maybe add lines with labels to display measurements/sizes in debug mode
- Add this to the typst preview packages. Currently, they apparently do not accept packages.