From 705dc665fcc8a69926a06739dd3af72821ee2a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAda=20Ron=C3=A9n?= Date: Sat, 17 Aug 2024 19:21:54 +0300 Subject: [PATCH] Add reference capability This adds a new argument, `label`, and makes use of the referencing mechanism of Typst. --- documentation.typ | 14 ++++++++++++++ leipzig-gloss.typ | 21 ++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/documentation.typ b/documentation.typ index bcf50a0..39fb0c3 100644 --- a/documentation.typ +++ b/documentation.typ @@ -179,6 +179,20 @@ standard Typst counter functions to control gloss numbering: translation: [There always is in us a will for a great happiness.], )", addl-bindings: (gloss-count: gloss-count)) +References to individual examples can be achieved using the `label` argument and the referencing mechanism of Typst: + +#codeblock( +"See @sorcerers: + +#numbered-gloss( + header: [Middle Welsh; modified from _Grammatical number in Welsh_ (1999) by Silva Nurmio (§~2.1.1)], + source: ([ac], [ny], [allvs], [y], [dewinyon], [atteb], [idav]), + morphemes: ([and], [#neg], [be_able.#smallcaps[pret].3#sg], [#smallcaps[def]], [sorcerer.#pl], [answer.#smallcaps[inf]], [to.3#sg.#smallcaps[m]]), + translation: [and the sorcerers could not answer him], + label: \"sorcerers\", +) + +As we have seen in @sorcerers, […].", addl-bindings: (neg: neg, sg: sg, pl: pl)) == Styling lines of a gloss diff --git a/leipzig-gloss.typ b/leipzig-gloss.typ index 0d063c5..6088a8f 100644 --- a/leipzig-gloss.typ +++ b/leipzig-gloss.typ @@ -1,6 +1,7 @@ #import "abbreviations.typ" #let gloss-count = counter("gloss_count") +#let cmdlabel = label // a workround so we can use `label` as a variable name #let build_gloss(item-spacing, formatters, gloss_line_lists) = { assert(gloss_line_lists.len() > 0, message: "Gloss line lists cannot be empty") @@ -47,6 +48,7 @@ additional-lines: (), //List of list of content translation: none, translation-style: none, + label: none, item-spacing: 1em, gloss-padding: 2.0em, //TODO document these @@ -121,13 +123,18 @@ 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] - ) + #figure( + kind: "lingexample", + supplement: [Example], + numbering: it => [#gloss-count.display()], + stack( + dir: ltr, //TODO this needs to be more flexible + left_padding, + [#gloss_number], + gloss-padding - left_padding - measure([#gloss_number],styles).width, + align(left)[#gloss_items], + ), + ) #if label != none {cmdlabel(label)} ] } )