Skip to content

Instantly share code, notes, and snippets.

@mkpoli
Last active April 22, 2024 02:09
Show Gist options
  • Select an option

  • Save mkpoli/da80878e775c62b05eff0cc916d730e5 to your computer and use it in GitHub Desktop.

Select an option

Save mkpoli/da80878e775c62b05eff0cc916d730e5 to your computer and use it in GitHub Desktop.
Linguistics example sentence in Typst
#let examples = counter("example")
#let std-numbering = numbering
#let named_examples = state("named-examples", (:))
#let ex(text, tran, name: none, numbering: "1)", asterisk: false) = {
examples.step()
context {
let current_numbering = examples.get()
if name != none {
named_examples.update(x => {
if name in x {
panic("Duplicate example name: " + name)
}
x.insert(name, current_numbering)
return x
})
}
grid(
columns: (auto, 1fr),
rows: (auto, auto),
column-gutter: 1em,
row-gutter: 1em,
grid.cell(
rowspan: 2,
std-numbering(numbering, ..examples.get())
),
{
if asterisk { "*" }
text
},
tran
)
}
}
#let refex(name, numbering: "1") = context {
"Example "
std-numbering(numbering, ..named_examples.final().at(name))
}
#import "example.typ": ex
#ex(
name: "hello",
[こんにちは],
[Hello]
)
#refex("hello")
#ex(
[ありがとう],
[Thanks]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment