2023-03-23 21:34:17 -07:00
|
|
|
#let gloss_count = counter("gloss_count")
|
|
|
|
|
2023-07-03 16:32:58 -07:00
|
|
|
#let build_gloss(spacing_between_items, formatters, gloss_line_lists) = {
|
2023-03-23 21:34:17 -07:00
|
|
|
assert(gloss_line_lists.len() > 0, message: "Gloss line lists cannot be empty")
|
|
|
|
|
|
|
|
let len = gloss_line_lists.at(0).len()
|
|
|
|
|
|
|
|
for line in gloss_line_lists {
|
|
|
|
assert(line.len() == len)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(formatters.len() == gloss_line_lists.len(), message: "The number of formatters and the number of gloss line lists should be equal")
|
|
|
|
|
|
|
|
let make_item_box(..args) = {
|
|
|
|
box(stack(dir: ttb, spacing: 0.5em, ..args))
|
|
|
|
}
|
|
|
|
|
|
|
|
for item_index in range(0, len) {
|
|
|
|
let args = ()
|
2023-04-08 00:06:56 -07:00
|
|
|
for (line_idx, formatter) in formatters.enumerate() {
|
2023-03-23 21:34:17 -07:00
|
|
|
let formatter_fn = if formatter == none {
|
|
|
|
(x) => x
|
|
|
|
} else {
|
|
|
|
formatter
|
|
|
|
}
|
|
|
|
|
|
|
|
let item = gloss_line_lists.at(line_idx).at(item_index)
|
|
|
|
args.push(formatter_fn(item))
|
|
|
|
}
|
|
|
|
make_item_box(..args)
|
|
|
|
h(spacing_between_items)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#let gloss(
|
|
|
|
header_text: none,
|
|
|
|
source_text: (),
|
|
|
|
source_text_style: emph,
|
|
|
|
transliteration: none,
|
|
|
|
transliteration_style: none,
|
|
|
|
morphemes: (),
|
|
|
|
morphemes_style: none,
|
|
|
|
additional_gloss_lines: (), //List of list of content
|
|
|
|
translation: none,
|
|
|
|
spacing_between_items: 1em,
|
2023-07-03 16:32:58 -07:00
|
|
|
gloss_padding: 2.0em, //TODO document these
|
|
|
|
left_padding: 0.5em,
|
2023-03-23 21:34:17 -07:00
|
|
|
numbering: false,
|
2023-07-03 16:32:58 -07:00
|
|
|
breakable: false,
|
2023-03-23 21:34:17 -07:00
|
|
|
) = {
|
|
|
|
|
|
|
|
assert(type(source_text) == "array", message: "source_text needs to be an array; perhaps you forgot to type `(` and `)`, or a trailing comma?")
|
|
|
|
assert(type(morphemes) == "array", message: "morphemes needs to be an array; perhaps you forgot to type `(` and `)`, or a trailing comma?")
|
|
|
|
|
|
|
|
assert(source_text.len() == morphemes.len(), message: "source_text and morphemes have different lengths")
|
|
|
|
|
|
|
|
if transliteration != none {
|
|
|
|
assert(transliteration.len() == source_text.len(), message: "source_text and transliteration have different lengths")
|
|
|
|
}
|
|
|
|
|
|
|
|
let gloss_items = {
|
|
|
|
|
|
|
|
if header_text != none {
|
|
|
|
header_text
|
|
|
|
linebreak()
|
|
|
|
}
|
|
|
|
|
|
|
|
let formatters = (source_text_style,)
|
|
|
|
let gloss_line_lists = (source_text,)
|
|
|
|
|
|
|
|
if transliteration != none {
|
|
|
|
formatters.push(transliteration_style)
|
|
|
|
gloss_line_lists.push(transliteration)
|
|
|
|
}
|
|
|
|
|
|
|
|
formatters.push(morphemes_style)
|
|
|
|
gloss_line_lists.push(morphemes)
|
|
|
|
|
|
|
|
for additional in additional_gloss_lines {
|
|
|
|
formatters.push(none) //TODO fix this
|
|
|
|
gloss_line_lists.push(additional)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-03 16:32:58 -07:00
|
|
|
build_gloss(spacing_between_items, formatters, gloss_line_lists)
|
2023-03-23 21:34:17 -07:00
|
|
|
|
|
|
|
if translation != none {
|
|
|
|
linebreak()
|
|
|
|
["#translation"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 07:59:29 -07:00
|
|
|
if numbering {
|
|
|
|
gloss_count.step()
|
|
|
|
}
|
|
|
|
|
2023-03-23 21:34:17 -07:00
|
|
|
let gloss_number = if numbering {
|
|
|
|
[(#gloss_count.display())]
|
|
|
|
} else {
|
|
|
|
none
|
|
|
|
}
|
|
|
|
|
2023-07-03 16:32:58 -07:00
|
|
|
//[#gloss_number #pad(left: 1em)[#gloss_items]]
|
|
|
|
|
|
|
|
style(styles => {
|
|
|
|
block(breakable: breakable)[
|
|
|
|
#stack(
|
|
|
|
dir:ltr, //TODO this needs to be more flexible
|
|
|
|
left_padding,
|
|
|
|
[#gloss_number],
|
|
|
|
gloss_padding - left_padding - measure([#gloss_number],styles).width,
|
|
|
|
[#gloss_items]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
2023-03-23 21:34:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#let numbered_gloss = gloss.with(numbering: true)
|