How to layout glossary into two separate tables (symbols and abbreviations)

Hi there,

I am writing a template for my master’s thesis. On requirement of the template is that the symbols and abbreviations are layed out into a table as depicted in this image:

I took the suggestions from a previous discussion about controlling the look of the glossary and tried to adjust it to my needs. So far, I arrived at this:

let symbols = latin-symbols + greek-symbols
show: make-glossary
register-glossary(symbols)
register-glossary(abbreviations)

print-glossary(
  show-all: false,
  user-print-glossary: (entries, groups, ..) => {
    table(
      // Invisible fourth column for the figure caption
      columns: (1fr, 1fr, 3fr, 0pt),
      table.header([Formelzeichen], [Einheit], [Beschreibung]),
      ..for group in ("latin", "greek") {
        (
          ..for entry in entries.filter(x => x.group == group) {
            (
              entry.short,
              entry.custom.unit,
              entry.description,
              [
                // #show figure.caption: none
                #figure(kind: "glossarium_figure", supplement: "", caption: none)[]
                #label(entry.key)
              ],
            )
          },
        )
      },
    )
  },
  symbols,
)

print-glossary(
  show-all: false,
  user-print-glossary: (entries, groups, ..) => {
    table(
      // Invisible third column for the figure caption
      columns: (1fr, 3fr, 0pt),
      table.header([Abkürzung], [Beschreibung]),
      ..for group in ("abbreviations",) {
        (
          ..for entry in entries.filter(x => x.group == group) {
            (
              entry.short,
              entry.long,
              [
                // #show figure.caption: none
                #figure(kind: "glossarium_figure", supplement: "", caption: none)[]
                #label(entry.key)
              ],
            )
          },
        )
      },
    )
  },
  abbreviations,
)

where my entries look like this:

let _latin-symbols = (
  (
    key: "sym:ap",
    short: $a_p$,
    description: "Schnitttiefe",
    custom: (
      unit: "mm",
    ),
  ),
  (
    key: "sym:ae",
    short: $a_e$,
    description: "Eingriffsweite",
    custom: (
      unit: "mm",
    ),
  ),
  ...
)

let latin-symbols = _latin-symbols.map(item => item + (group: "latin"))

and

let _abbreviations = (
  (
    key: "dp",
    short: "DP",
    long: "polykristalliner Diamant",
  ),
  (
    key: "llm",
    short: "LLM",
    long: "Large Language Model",
  ),
)

let abbreviations = _abbreviations.map(item => item + (group: "abbreviations"))

This kind of works, but there are a few things that are broken, unfortunately (see last image):

  1. The symbols (and abbreviations) are not automatically sorted alphabetically
  2. All symbols and abbreviations appear in the table, even though there are no references to all but one of them, show-all: false has no effect.

Styling the table is just something I didn’t do yet, that’ll come later, when I’ve got the core functionality working.

Is what I’m trying to achieve even possible? :sweat_smile: I would really like to avoid having to keep track of all symbols and abbreviations manually throughout my thesis, so glossarium seemed like the right choice for me.

Hi @engifar! Thanks for reaching out. Glossarium is a bit complicated to manipulate, but one good example to start with would be possible this test glossarium/tests/glossary-table/test.typ at 785e0dbebfa44b5cae844e5e11437157be888f6e · typst-community/glossarium · GitHub

I wrote it based on the previous forum topic. Tell me if you’re able to tweak it to your preferences!

Because it sounded interesting, here’s a quick attempt from me:

#import "@preview/glossarium:0.5.10": *

#let _latin-symbols = (
  (
    key: "sym-ap",
    short: $a_p$,
    description: "Schnitttiefe",
    custom: (
      unit: "mm",
    ),
  ),
  (
    key: "sym-ae",
    short: $a_e$,
    description: "Eingriffsweite",
    custom: (
      unit: "mm",
    ),
  ),
)

#let latin-symbols = _latin-symbols.map(item => item + (group: "latin"))

#let _abbreviations = (
  (
    key: "dp",
    short: "DP",
    long: "polykristalliner Diamant",
  ),
  (
    key: "llm",
    short: "LLM",
    long: "Large Language Model",
  ),
)

#let abbreviations = _abbreviations.map(item => item + (group: "abbreviations"))

#let symbols = latin-symbols
#show: make-glossary
#register-glossary(symbols)
#register-glossary(abbreviations)

#print-glossary(
  user-print-glossary: (entries, groups, show-all: false, ..) => {
    show table.cell.where(y: 0): set text(weight: "bold")
    set table(inset: (top: 10pt, bottom: 15pt),)
    table(
      // Invisible third column for the figure caption
      columns: (1fr, 1fr, 3fr, 0pt),
      table.header([Formelzeichen], [Einheit], [Beschreibung]),
      ..for group in groups {
        let a = entries.map(e => (e.key, count-refs(e.at("key")))).to-dict()
        let b = count-all-refs().to-dict()
        (
          ..for entry in entries.filter(x => x.group == group ) {
            let display-entry = show-all == true or count-refs(entry.at("key")) >= 1
            if display-entry {(
              entry.short,
              entry.custom.unit,
              entry.description,
              [
                #figure(kind: "glossarium_entry", supplement: none, numbering: none, none,) 
                #label(entry.key)
              ]
            )} else {(
                table.cell(inset: 0%+0pt, none),
                table.cell(inset: 0%+0pt, none),
                table.cell(inset: 0%+0pt, none),
                table.cell(inset: 0%+0pt)[
                 #figure(kind: "glossarium_entry", supplement: none, numbering: none, none,) 
                 #label(entry.key)
                ]
              )}
          },
        )
      },
    )
  },
  symbols,
)

#print-glossary(
  user-print-glossary: (entries, groups, show-all: false, ..) => {
    show table.cell.where(y: 0): set text(weight: "bold")
    set table(inset: (top: 10pt, bottom: 15pt),)
    table(
      // Invisible third column for the figure caption
      columns: (1fr, 3fr, 0pt),
      table.header([Abkürzung], [Beschreibung]),
      ..for group in groups {
        let a = entries.map(e => (e.key, count-refs(e.at("key")))).to-dict()
        let b = count-all-refs().to-dict()
        (
          ..for entry in entries.filter(x => x.group == group ) {
            let display-entry = show-all == true or count-refs(entry.at("key")) >= 1
            if display-entry {(
              entry.short,
              entry.long,
              [
                #figure(kind: "glossarium_entry", supplement: none, numbering: none, none,) 
                #label(entry.key)
              ]
            )} else {(
                table.cell(inset: 0%+0pt, none),
                table.cell(inset: 0%+0pt, none),
                table.cell(inset: 0%+0pt)[
                 #figure(kind: "glossarium_entry", supplement: none, numbering: none, none,) 
                 #label(entry.key)
                ]
              )}
          },
        )
      },
    )
  },
  abbreviations,
)


@dp

@llm

@llm

@sym-ae