How can I set a global font for e.g. "source-style" when using leipzig-glossing?

According to the leipzig-glossing documentation, a style can be set to the source element by the following:

#example(
  (
    source: ([yī],[līm],[dé]),
    source-style: text.with(font: "Noto Sans Mono", size: 9pt),
    morphemes: ([3#smallcaps(sg)], [drink], [tea]),
    translation: text[He drinks tea],
  )
)

That works perfectly to layout as I want. However, the documentaion gives no indication as to whether it is possible, and if so, how to make that source-style global so that one doesn’t have to include it in every example.

Can anyone help please? With a paper with dozens of examples, having to include that line in every one is sub-optimal.

Many thanks.

:slight_smile:
Mark

Ok, normally you’d use .with to pre-apply a function argument but we can’t do that here.

I think you need to interpose your own function that adds the extra argument.

You can do it like this:

#let default-settings = (source-style: text.with(font: "Noto Sans Mono", size: 9pt))
#let myexample(..args) = {
  let named-args = args.named()
  // transform all positional args
  example(..named-args, ..args.pos().map(arg => default-settings + arg))
}

The + is a merge of dictionaries. The order of addition ensures that setting source-style in the parameter overrides the default setting.

I think this handles subexamples as well, but I’m not familiar with how they are passed.

1 Like

Thank you very much. I have to admit that I don’t really understand how it works, but it works perfectly for my needs. In the fifth line, I changed example to numbered-example. I use numbered-example as that not only gives numbering, but automatically handles sub-examples. Your code works perfectly with them too.

With your code added, I have to say leipzig-glossing.typ is very easy to use.

:slight_smile:
Mark

1 Like