Skip to content

Instantly share code, notes, and snippets.

@reknih
Created March 26, 2023 10:20
Show Gist options
  • Save reknih/a568bdda88507cbe021e4d11f92b9132 to your computer and use it in GitHub Desktop.
Save reknih/a568bdda88507cbe021e4d11f92b9132 to your computer and use it in GitHub Desktop.
A DIN letter template like the one we use at Typst
/*
DIN Letter template
Save this file in your project. Use it like this
in your project file:
#import "template.typ": *
#show: letter.with(
sender: [
Acme Inc\
Musterstraße 100, 10623 Berlin, Germany \
#link("https://example.com")#h(2mm)#link("mailto:hello@example.com")
],
address: [
Trading Goods Inc \
Pappelallee 23 \
12345 Neustadt \
Germany
],
date: [Berlin, March 26h, 2023],
subject: "Our Discussion on Breadcrumbs",
footer-cells: (
(
title: [Acme Inc],
content: [
Musterstraße 100 \
10623 Berlin \
Germany
],
),
(
title: [Directors],
content: [
Petra Mustermann \
#link("mailto:mustermann@example.com")
],
),
(
title: [Registry Court],
content: [
Amtsgericht\ Berlin-Charlottenburg \
#text(weight: 600, "VAT ID") DE123456789
],
),
),
)
// Your letter goes here
*/
#let letter(
address: none,
sender: none,
date: none,
subject: none,
logo: none,
footer-cells: (),
body
) = {
set text(lang: "en", 10pt, font: "HK Grotesk")
set enum(numbering: "(1)")
set list(marker: "–")
show heading: set block(below: 1.25em, above: 1.5em)
show heading: (it) => {
set text(if it.level == 1 {12pt} else {10pt})
it
}
set page(
margin: (
top: 3.25cm,
bottom: 5cm,
left: 2.5cm,
right: 2cm
),
header: if logo != none {
place(bottom+right, image(height:1cm, logo))
},
footer: v(1fr) + par(text(7pt, fill: rgb("#565565"), grid(
columns: (1fr,) * footer-cells.len() + (auto,),
column-gutter: 8pt,
..footer-cells.map(cell => align(bottom, {
text(weight: 600, upper(cell.title))
linebreak()
cell.content
})),
align(right+bottom)[Page #counter(page).display() of #locate(loc => counter(page).final(loc).first())]
))) + v(1.5cm)
)
v(2cm)
box(width: 60mm)[
#text(7pt, fill: rgb("#565565"), sender)
#address
]
align(right, date)
v(8.4mm)
strong(subject)
parbreak()
body
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment