ENIB-Community / glossarium

Glossarium is a simple typst glossary.
MIT License
22 stars 9 forks source link

Typst glossary

Glossarium is based in great part of the work of Sébastien d'Herbais de Thun from his master thesis available at: https://github.com/Dherse/masterproef. His glossary is available under the MIT license here.

Glossarium is a simple, easily customizable typst glossary inspired by LaTeX glossaries package . You can see various examples showcasing the different features in the examples folder.

Screenshot

Manual

Import and setup

This manual assume you have a good enough understanding of typst markup and scripting.

For Typst 0.6.0 or later import the package from the typst preview repository:

#import "@preview/glossarium:0.4.0": make-glossary, print-glossary, gls, glspl 

For Typst before 0.6.0 or to use glossarium as a local module, download the package files into your project folder and import glossarium.typ:

#import "glossarium.typ": make-glossary, print-glossary, gls, glspl 

After importing the package and before making any calls to gls,print-glossary or glspl, please MAKE SURE you add this line

#show: make-glossary

WHY DO WE NEED THAT ? : In order to be able to create references to the terms in your glossary using typst ref syntax @key glossarium needs to setup some show rules before any references exist. This is due to the way typst works, there is no workaround.

Therefore I recommend that you always put the #show: ... statement on the line just below the #import statement.

Printing the glossary

First we have to define the terms. A term is a dictionary composed of 2 required and 2 optional elements:

Then the terms are passed as a list to print-glossary

#print-glossary(
    (
    // minimal term
    (key: "kuleuven", short: "KU Leuven"),

    // a term with a long form and a group
    (key: "unamur", short: "UNamur", long: "Namur University", group: "Universities"),

    // a term with a markup description
    (
      key: "oidc", 
      short: "OIDC", 
      long: "OpenID Connect", 
      description: [OpenID is an open standard and decentralized authentication protocol promoted by the non-profit
      #link("https://en.wikipedia.org/wiki/OpenID#OpenID_Foundation")[OpenID Foundation].],
      group: "Acronyms",
    ),

    // a term with a short plural 
    (
      key: "potato",
      short: "potato",
      // "plural" will be used when "short" should be pluralized
      plural: "potatoes",
      description: [#lorem(10)],
    ),

    // a term with a long plural 
    (
      key: "dm",
      short: "DM",
      long: "diagonal matrix",
      // "longplural" will be used when "long" should be pluralized
      longplural: "diagonal matrices",
      description: "Probably some math stuff idk",
    ),
  )
)

By default, the terms that are not referenced in the document are not shown in the glossary, you can force their appearance by setting the show-all argument to true.

You can also disable the back-references by setting the parameter disable-back-references to true.

By default, group breaks use linebreaks. This behaviour can be changed by setting the user-group-break parameter to pagebreak(), or colbreak(), or any other function that returns the content you want.

You can call this function from anywhere in your document.

Referencing terms.

Referencing terms is done using the key of the terms using the gls function or the reference syntax.

// referencing the OIDC term using gls
#gls("oidc")
// displaying the long form forcibly
#gls("oidc", long: true)

// referencing the OIDC term using the reference syntax
@oidc

Handling plurals

You can use the glspl function and the references supplements to pluralize terms. The plural key will be used when short should be pluralized and longplural will be used when long should be pluralized. If the plural key is missing then glossarium will add an 's' at the end of the short form as a fallback.

#glspl("potato")

Please look at the examples regarding plurals.

Overriding the text shown

You can also override the text displayed by setting the display argument.

#gls("oidc", display: "whatever you want") 

Final tips

I recommend setting a show rule for the links to that your readers understand that they can click on the references to go to the term in the glossary.

#show link: set text(fill: blue.darken(60%))
// links are now blue ! 

Changelog

Unreleased

0.4.1

0.4.0

0.3.0

0.2.6

Added

0.2.5

Fixed

0.2.4

Fixed

Changed

Previous versions did not have a changelog entry