typst-community / glossarium

Glossarium is a simple typst glossary.
MIT License
41 stars 11 forks source link

A warning when a defined term is used without being marked up as a defined term. #69

Open gerob311 opened 1 month ago

gerob311 commented 1 month ago

For example, something like:

#let entry-list = (
  (
      key: "computer",
      short: "computer",
      plural: "computers",
      description: [An @electronic device for performing computations.]
  )
)
#register-glossary(entry-list)

Computers are useful for things.

#print-glossary(entry-list, warn-on-nondefined-term: true)

A warning should be raised in the logs about a term being used that was not marked up as a defined term. This warning could be removed as follows:

#ndt("Computers") are useful for things.

Where ndt is short for "non-defined term", and means that the author is explicitly stating that in this instance, the definition in the glossary is not meant by the usage of the word.

This would of course mean that a collection of all forms of a term (long, short, plural, longplural) would need to be maintained so that they can be looked up, rather than just looking up by key.

quachpas commented 4 weeks ago

Hello @gerob311, I am unsure about what exactly you are asking. If I understand well, you would like warnings to be raised if a term that exists in the glossary is used without referencing it, is that correct? Unfortunately, warnings are not implemented yet in Typst, so the package cannot do that.

gerob311 commented 2 weeks ago

@quachpas, yes, that's the idea. It comes from something a previous employer did, where we used ConTeXt, and rolled our own glossary. We had a Ruby script which examined a document, looked up terms in our master glossary document, and created a glossary from terms that were marked up as defined terms (and raised an error if the term wasn't in the master glossary). Such a script isn't necessary with Glossarium, but it did also warn us when we used terms that hadn't been marked up. I thought that if it was possible, it would be nice if everything just happened in the Typst compiler, rather than needing another script.

I wonder if this would be possible with a plugin, rather than just a template. Or perhaps later down the track as Typst evolves.

quachpas commented 2 weeks ago

Thanks! ATM, I don't think it's possible within the same compilation process without raising panic (not warnings). What I do recommend is examining your document by glossary key, which are usually stem, e.g., "computer" for "Computers". A simple ripgrep through the code should give you all instances of usage. Something like

rg '(^|[^@])key'

where key is the word you are looking for