Skip to content

Instantly share code, notes, and snippets.

@mbollmann
Created August 31, 2025 12:19
Show Gist options
  • Save mbollmann/a3c4a7301bc19125192a003fec68341f to your computer and use it in GitHub Desktop.
Save mbollmann/a3c4a7301bc19125192a003fec68341f to your computer and use it in GitHub Desktop.
Table of coffee brew ratios, made in Typst with dynamic calculation of values
#import "@preview/zero:0.5.0": num, format-table
// Configure output
#set text(font: "Libertinus Serif")
#show math.equation: set text(font: "Libertinus Math")
#let min-water = 200
#let max-water = 500
#let min-ratio = 13
#let max-ratio = 20
#let insert-golden-ratio = true
// Compute the table values
#let ratios = range(min-ratio, max-ratio + 1)
#let header = ()
#let contents = ()
#{
for ratio in ratios {
header.push([*1:#ratio*])
}
for water in range(min-water, max-water + 1, step: 50) {
contents.push([*#water*#h(.16em, weak: true)ml])
for ratio in ratios {
contents.push(num(water / ratio, digits: 1))
}
}
}
#if insert-golden-ratio {
let idx = ratios.position(x => x == 16) + 1
let row-len = 2 + ratios.len()
header.insert(idx, [*1:16.#overline[6]*])
for (j, water) in range(min-water, max-water + 1, step: 50).enumerate() {
contents.insert(1 + idx + j * row-len, num(water / 16.6666, digits: 0))
}
}
// Style the table
#let water-rows = int(calc.round((max-water - min-water) / 50) + 1)
#let ratio-cols = header.len()
#let table-fmt = (none, none) + (auto,) * ratio-cols
#show: format-table(..table-fmt)
#let frame(stroke) = (x, y) => (
left: if x != 1 or y in (0, water-rows + 2) { 0pt } else { stroke },
right: if y not in (0, water-rows + 2) { stroke },
top: if (y not in (1, 2, water-rows + 2) or x == 0) { 0pt } else { stroke },
bottom: 0pt,
)
#set table(
fill: (x, y) => if calc.even(y) and x > 0 and y > 1 and y < (water-rows + 2) { rgb("EAF2F5") },
stroke: frame(1pt),
)
// Output the table
#table(
align: center,
columns: (1.5em, auto) + (1fr,) * ratio-cols,
[], [],
table.cell(align: horizon + center, colspan: ratio-cols)[*Brew ratio*],
[], [],
..header,
table.cell(align: horizon + center, rowspan: water-rows, rotate(-90deg, [
*Water*
])),
..contents,
[], [],
table.cell(align: horizon + center, colspan: ratio-cols)[*Grams of coffee by amount of water & desired brew ratio*],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment