### Initialize and Register Glossary Entries in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md This snippet demonstrates the basic setup for the glossarium package. It imports necessary functions, defines a list of glossary entries with keys, short forms, long forms, and descriptions, and then registers these entries to be used in the document. Finally, it prints the glossary. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary, gls, glspl #show: make-glossary #let entry-list = ( ( key: "kuleuven", short: "KU Leuven", long: "Katholieke Universiteit Leuven", description: "A university in Belgium.", ), // Add more terms ) #register-glossary(entry-list) // Your document body #print-glossary( entry-list ) ``` -------------------------------- ### Handling Capitalization with `Gls` and `@Key` Source: https://github.com/typst-community/glossarium/blob/master/README.md Demonstrates how to capitalize terms, particularly when they appear at the beginning of a sentence. It shows the use of the `Gls` and `Glspl` functions, as well as the `@Key` and `@Key:pl` reference syntax. This feature is applicable when the term's key does not start with an uppercase letter. ```typ #Gls("ref") // You can also reference the automatically generated labels: @Ref @Ref:pl ``` -------------------------------- ### Style Glossary References with Typst Source: https://context7.com/typst-community/glossarium/llms.txt Customizes the appearance of glossary references using Typst's show rules. This allows for visual distinction of glossary links from regular text, with examples for styling all links, only glossary references, and differentiating string links. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary #show: make-glossary #let entries = ( (key: "api", short: "API", long: "Application Programming Interface"), ) #register-glossary(entries) // Style all links (includes glossary references) #show link: set text(fill: blue.darken(60%)) // Style only glossary references (after make-glossary) #show ref: it => { let el = it.element if el != none and el.func() == figure and el.kind == "glossarium_entry" { text(fill: blue.darken(60%), weight: "medium", it) } else { it } } // Style string links differently from glossary links #show link: it => { if type(it.dest) == str { text(fill: red, it) // External links in red } else { it // Glossary links unchanged } } See @api for details and visit #link("https://example.com")[our website]. = Glossary #print-glossary(entries) ``` -------------------------------- ### Custom Glossary Printing with User-Defined Functions Source: https://context7.com/typst-community/glossarium/llms.txt Illustrates how to deeply customize the appearance of a glossary using user-provided functions for group headings, entry titles, descriptions, and back-references. It also shows how to define a custom separator between groups. This example requires the glossarium package and defines custom printing logic. ```typst #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary #show: make-glossary #let entries = ( (key: "tcp", short: "TCP", long: "Transmission Control Protocol", group: "Networking"), (key: "udp", short: "UDP", long: "User Datagram Protocol", group: "Networking"), (key: "aes", short: "AES", long: "Advanced Encryption Standard", group: "Security"), (key: "rsa", short: "RSA", long: "Rivest-Shamir-Adleman", group: "Security"), ) #register-glossary(entries) @tcp @udp @aes @rsa = Glossary // Custom group heading #let my-group-heading(group, level: none) = { heading([Category: #group], level: 2, outlined: false) } // Custom entry title #let my-title(entry) = { text(fill: blue, weight: "bold")[#entry.short] if entry.long != none [ -- #entry.long] } // Custom description #let my-description(entry) = { if entry.description != none { emph(entry.description) } } // Custom back-references #let my-back-refs(entry, deduplicate: false) = { let refs = get-entry-back-references(entry, deduplicate: deduplicate) if refs.len() > 0 { [ (see pages: #refs.join(", "))] } } // Custom group separator #let my-group-break() = line(length: 100%, stroke: 0.5pt + gray) #print-glossary( entries, show-all: true, user-print-group-heading: my-group-heading, user-print-title: my-title, user-print-description: my-description, user-print-back-references: my-back-refs, user-group-break: my-group-break, ) ``` -------------------------------- ### Reference Terms with `gls` Function Source: https://github.com/typst-community/glossarium/blob/master/README.md Demonstrates various ways to reference terms using the flexible `gls` function in Typst. It shows how to specify the term, force the first form, disable linking, and prevent usage count updates. These examples highlight the core functionality for term referencing. ```typ #gls("oidc") // Displaying the first form forcibly #gls("oidc", first: true) // Do not add a link #gls("oidc", link: false) // Do not update the usage count. If done on first use, the next reference will trigger printing the full version. #gls("oidc", update: false) ``` -------------------------------- ### Overriding Displayed Text Source: https://github.com/typst-community/glossarium/blob/master/README.md Shows how to override the default text displayed for a glossarium term using the `display` argument within the `gls` function. This allows for custom presentation of terms, regardless of their defined forms. The example uses `gls` with a custom display string. ```typ #gls("oidc", display: "whatever you want") ``` -------------------------------- ### Configuring Default Shorthands Source: https://github.com/typst-community/glossarium/blob/master/README.md Illustrates how to set the default shorthands available when using the Typst reference syntax (`@key`). This is done within the `print-glossary` function, allowing customization of which shorthand forms (e.g., plural, capitalize, short, long) are readily accessible. This configuration impacts the convenience of referencing terms. ```typ print-glossary( entry-list, // default shorthands shorthands: ("plural", "capitalize", "capitalize-plural", "short", "long"), ) ``` -------------------------------- ### Typst: Configure First-Use Term Styles with Glossarium Source: https://context7.com/typst-community/glossarium/llms.txt This snippet demonstrates how to configure and use different first-use style options for terms in Typst documents using the glossarium package. It shows registration of entries with default and custom styles, and how to reference them using the `gls` function. Dependencies include the '@preview/glossarium' package. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, gls #show: make-glossary #let entries = ( // Default style: long (short) (key: "api", short: "API", long: "Application Programming Interface"), // Custom first-use style: short (long) (key: "cpu", short: "CPU", long: "Central Processing Unit", styles: ("short-long",)), // Footnote style: short with long form in footnote (key: "ram", short: "RAM", long: "Random Access Memory", styles: ("footnote",)), ) #register-glossary(entries) // Default: "Application Programming Interface (API)" First API reference: #gls("api") // short-long: "CPU (Central Processing Unit)" First CPU reference: #gls("cpu") // footnote: "RAM" with footnote containing "Random Access Memory" First RAM reference: #gls("ram") // Override entry's default style #gls("api", styles: ("short-long",)) // "API (Application Programming Interface)" #gls("api", styles: ("footnote",)) // "API" with footnote ``` -------------------------------- ### Handling Plurals with `glspl` and `@key:pl` Source: https://github.com/typst-community/glossarium/blob/master/README.md Explains how to handle plural forms of terms using both the `glspl` function and the `@key:pl` reference syntax. It covers the `plural` and `longplural` keys for specifying plural forms and notes the fallback behavior of adding 's' if the `plural` key is missing. This ensures correct grammatical forms are used. ```typ #glspl("potato") // Alternatively, you can reference the automatically generated label: @potato:pl ``` -------------------------------- ### Create Capitalized and Plural References with Gls Functions Source: https://context7.com/typst-community/glossarium/llms.txt Demonstrates the use of Gls, Glspl, and gls functions for creating capitalized, plural, and combined capitalized-plural references in Typst. It requires importing glossarium functions and registering glossary entries. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, gls, Gls, glspl, Glspl #show: make-glossary #let entries = ( ( key: "matrix", short: "matrix", long: "mathematical matrix", plural: "matrices", longplural: "mathematical matrices", ), (key: "cpu", short: "CPU", long: "Central Processing Unit", plural: "CPUs"), ) #register-glossary(entries) // Capitalized reference (first letter uppercase) #Gls("matrix") operations are fundamental. // "Mathematical matrix (matrix)" or "Matrix" // Plural reference We need multiple #glspl("cpu"). // "CPUs" or "Central Processing Units (CPUs)" // Capitalized plural #Glspl("matrix") are used everywhere. // "Matrices" or "Mathematical matrices (matrices)" // Programmatic capitalization and pluralization #gls("cpu", capitalize: true) #gls("cpu", plural: true) #gls("cpu", capitalize: true, plural: true) ``` -------------------------------- ### Use Native Reference Syntax with Modifiers Source: https://context7.com/typst-community/glossarium/llms.txt Explains how to leverage Typst's native reference syntax (@key) with glossarium modifiers for common operations like pluralization, capitalization, and selecting short/long forms. It requires importing glossarium and registering entries. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary #show: make-glossary #let entries = ( ( key: "html", short: "HTML", long: "HyperText Markup Language", description: "The standard markup language for web pages.", longplural: "HyperText Markup Languages", custom: "W3C Standard", ), ) #register-glossary(entries) // Basic reference - shows long form on first use, short form after Learn @html today. // Plural form Multiple @html:pl standards exist. // Uses plural/longplural // Capitalized (for sentence starts) - only works if key starts lowercase @Html is important. // Note: works with lowercase keys // Capitalized plural @Html:pl are everywhere. // Force short form only Use @html:short for brevity. // Force long form The full name is @html:long. // Get description directly Definition: @html:description // Get long plural form Multiple: @html:longplural // Get custom attribute Standard: @html:custom // With supplement text (adds suffix) @html[5] is the latest version. ``` -------------------------------- ### Import Glossarium Package from Typst Preview Source: https://github.com/typst-community/glossarium/blob/master/README.md This code snippet shows how to import the glossarium package from the Typst preview repository. It makes functions like `make-glossary`, `register-glossary`, `print-glossary`, `gls`, and `glspl` available for use in your Typst document. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary, gls, glspl ``` -------------------------------- ### Configure Glossarium Show Rule Source: https://context7.com/typst-community/glossarium/llms.txt Sets up the necessary infrastructure for glossary term references to work correctly with Typst's reference system. This show rule must be applied before any glossary references are made. It supports customization options for linking and display behavior. ```typst #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary, gls, glspl // REQUIRED: Apply this show rule before any glossary usage #show: make-glossary // Optional parameters for customization: #show: make-glossary.with( link: true, // Enable clickable links to glossary entries always-first: none, // Force first-use style (true/false/none) outline-always-first: true, // Use full form in outlines figure-caption-always-first: true, // Use full form in figure captions heading-always-first: true, // Use full form in headings ) ``` -------------------------------- ### Typst Reference Syntax for Terms Source: https://github.com/typst-community/glossarium/blob/master/README.md Illustrates the practical use of Typst's `@key` reference syntax for glossarium terms. It shows default shorthands like plural, capitalize, capitalized plural, short, and long versions, as well as explicitly requesting the long version or plural form. This is the most common method for referencing entries. ```typ // Prints the full version on first usage, short afterwards @oidc // Will always display the long version @oidc:long // Display the plural form @oidc:pl ``` -------------------------------- ### Import Glossarium from Local Typst Package Namespace Source: https://github.com/typst-community/glossarium/blob/master/README.md This code demonstrates how to import the glossarium package when it's set up as a local package on your system. It assumes your local namespace is named 'local' and imports the necessary functions. ```typ #import "@local/glossarium:0.5.10": make-glossary, register-glossary, print-glossary, gls, glspl ``` -------------------------------- ### Add Articles with Agls Functions Source: https://context7.com/typst-community/glossarium/llms.txt Illustrates how to use the agls and Agls functions to prepend the correct article ('a' or 'an') to glossary terms based on their 'artshort' or 'artlong' attributes. This requires importing and setting up glossarium. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, agls, Agls #show: make-glossary #let entries = ( (key: "api", short: "API", long: "Application Programming Interface", artshort: "an", artlong: "an"), (key: "cpu", short: "CPU", long: "Central Processing Unit", artshort: "a", artlong: "a"), (key: "lod", short: "LOD", long: "Level of Detail", artshort: "an", artlong: "a"), ) #register-glossary(entries) // "an API" or "an Application Programming Interface (API)" This is #agls("api") for data access. // "a CPU" or "a Central Processing Unit (CPU)" The system contains #agls("cpu"). // Capitalized article at sentence start: "An LOD..." #Agls("lod") system improves performance. ``` -------------------------------- ### Register Glossary Entries Source: https://context7.com/typst-community/glossarium/llms.txt Registers a list of glossary entries, where each entry is a dictionary defining a term's properties like key, short form, long form, description, and pluralization. It can optionally disable using the key as the default short form. ```typst #let entry-list = ( // Minimal entry (key used as short form) (key: "api"), // Entry with short and long forms ( key: "html", short: "HTML", long: "HyperText Markup Language", ), // Full-featured entry ( key: "cpu", short: "CPU", long: "Central Processing Unit", description: [The primary component that executes instructions in a computer.], plural: "CPUs", longplural: "Central Processing Units", artshort: "a", // Article for short form ("a CPU") artlong: "a", // Article for long form group: "Hardware", // Group for organizing in glossary sort: "cpu", // Custom sort key custom: (unit: "GHz"), // Custom user data ), // Entry with content (supports Typst markup) ( key: "latex", short: [#text(font: "Latin Modern Roman")[LaTeX]], description: [A document preparation system for high-quality typesetting.], ), ) #register-glossary(entry-list) // Optional: disable using key as default short form #register-glossary(entry-list, use-key-as-short: false) ``` -------------------------------- ### Apply Transformations to Glossary Entries with Typst Source: https://context7.com/typst-community/glossarium/llms.txt The `style-entries` function applies a transformation to specific attributes of all registered glossary entries. This is useful for consistent styling, such as applying smallcaps to short forms or italics to descriptions. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary, style-entries #show: make-glossary #let entries = ( (key: "html", short: "HTML", long: "HyperText Markup Language"), (key: "css", short: "CSS", long: "Cascading Style Sheets"), ) #register-glossary(entries) // Apply smallcaps to all short forms #style-entries("short", text => smallcaps(text)) // Apply italic to all descriptions #style-entries("description", text => emph(text)) // Supported attributes: short, long, artshort, artlong, plural, longplural, description, custom // NOT supported: key, sort, group (use user-print-group-heading for groups) @html and @css = Glossary #print-glossary(entries, show-all: true) ``` -------------------------------- ### Import Glossarium as a Vendored Module in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md This snippet illustrates how to use glossarium as a vendored module. After downloading the package files into your project, you can import the `glossarium.typ` file directly, making its functions available. ```typ #import "glossarium.typ": make-glossary, register-glossary, print-glossary, gls, glspl ``` -------------------------------- ### Print Glossary with Customization Options Source: https://context7.com/typst-community/glossarium/llms.txt Demonstrates various ways to customize the output of the `print-glossary` function in Typst. This includes controlling which entries are shown, disabling back-references, filtering by groups, setting minimum references, and customizing sorting and separators. It requires the glossarium package and defines glossary entries. ```typst #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary #show: make-glossary #let entries = ( (key: "api", short: "API", long: "Application Programming Interface", description: "A set of protocols for building software.", group: "Software"), (key: "cpu", short: "CPU", long: "Central Processing Unit", description: "Executes program instructions.", group: "Hardware"), (key: "ram", short: "RAM", long: "Random Access Memory", description: "Volatile memory for active data.", group: "Hardware"), (key: "unused", short: "UNUSED", description: "This term is never referenced."), ) #register-glossary(entries) // Reference some terms See @api and @cpu. The @ram stores data. = Glossary // Basic usage - only shows referenced terms #print-glossary(entries) // Show all terms including unreferenced ones #print-glossary(entries, show-all: true) // Disable back-references (page numbers) #print-glossary(entries, disable-back-references: true) // Deduplicate back-references (one per page) #print-glossary(entries, deduplicate-back-references: true) // Filter by specific groups #print-glossary(entries, groups: ("Hardware",)) // Show only default (ungrouped) entries #print-glossary(entries, groups: ("",)) // Set minimum references required to show entry #print-glossary(entries, minimum-refs: 2) // Custom group heading level #print-glossary(entries, group-heading-level: 2) // Custom description separator #print-glossary(entries, description-separator: " - ") // Custom sorting #print-glossary( entries, group-sortkey: g => g, // Sort groups alphabetically entry-sortkey: e => e.short, // Sort entries by short form ) // Invisible glossary (registers labels without visible output) #print-glossary(entries, invisible: true) // Configure which shorthands are available for @key:modifier syntax #print-glossary( entries, shorthands: ("plural", "capitalize", "capitalize-plural", "short", "long"), ) ``` -------------------------------- ### Register Glossary Terms in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md Demonstrates how to register glossary terms using the `register-glossary` function. It shows various ways to define term properties such as `key`, `short`, `long`, `description`, `plural`, `longplural`, and `group`. The `custom` field allows for arbitrary data associated with a term. ```typst #register-glossary(entry-list) #let entry-list = ( // Use key as short by default ( key: "kuleuven", ), // Add SHORT ( key: "kuleuven", short: "KU Leuven" ), // Add LONG ( key: "unamur", short: "UNamur", long: "Namur University", ), // Add a 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]. ], ), // Add a PLURAL form ( key: "potato", short: "potato", // "plural" will be used when "short" should be pluralized plural: "potatoes", ), // Add a LONGPLURAL form ( 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", ), // Add a GROUP ( key: "kuleuven", short: "KU Leuven", // The terms are displayed by groups in the glossary group: "Universities", ), // Add a CUSTOM entry ( key: "c", short: $c$, description: "Speed of light in vacuum", // The custom key will be ignored by the default print-glossary function custom: (unit: $op("m s")^(-1)$), ), ) ``` -------------------------------- ### Enable Glossarium Functionality in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md This essential Typst code line activates the glossarium package's core functionality. It must be placed before any calls to glossary-related functions like `gls`, `print-glossary`, or `glspl` to enable reference creation using Typst's reference syntax. ```typ #show: make-glossary ``` -------------------------------- ### Create Glossary Term References (gls) Source: https://context7.com/typst-community/glossarium/llms.txt Creates a reference to a glossary term, controlling its display. By default, it shows the long form on first use and the short form subsequently. It supports options to force display styles, override text, disable links, and add suffixes. ```typst #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, gls #show: make-glossary #let entries = ( (key: "oidc", short: "OIDC", long: "OpenID Connect", description: "An authentication protocol."), (key: "jwt", short: "JWT", long: "JSON Web Token"), ) #register-glossary(entries) // Basic usage - first use shows "OpenID Connect (OIDC)", subsequent shows "OIDC" This system uses #gls("oidc") for authentication. // Force first-use style (long form) Always show full: #gls("oidc", first: true) // Force short form only Short only: #gls("oidc", first: false) // Override displayed text Custom display: #gls("oidc", display: "the OIDC protocol") // Disable link to glossary No link: #gls("oidc", link: false) // Don't count this reference (next use will still be "first") Silent reference: #gls("oidc", update: false) // Add suffix to short form With suffix: #gls("oidc", suffix: "'s") // Combine options #gls("jwt", first: true, link: false, suffix: "s") ``` -------------------------------- ### Access Glossary Attributes with Accessor Functions Source: https://context7.com/typst-community/glossarium/llms.txt Details the use of attribute accessor functions (e.g., gls-key, gls-short) to retrieve specific data from glossary entries without creating references or updating usage counts. This requires importing the relevant functions and setting up glossarium. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary #import "@preview/glossarium:0.5.10": gls-key, gls-short, gls-long, gls-plural #import "@preview/glossarium:0.5.10": gls-longplural, gls-description, gls-group, gls-custom #import "@preview/glossarium:0.5.10": gls-artshort, gls-artlong #show: make-glossary #let entries = ( ( key: "cpu", short: "CPU", long: "Central Processing Unit", description: "The brain of a computer.", plural: "CPUs", longplural: "Central Processing Units", artshort: "a", artlong: "a", group: "Hardware", custom: (manufacturer: "Intel", cores: 8), ), ) #register-glossary(entries) // Get individual attributes Key: #gls-key("cpu") // "cpu" Short: #gls-short("cpu") // "CPU" Long: #gls-long("cpu") // "Central Processing Unit" Plural: #gls-plural("cpu") // "CPUs" Long Plural: #gls-longplural("cpu") // "Central Processing Units" Description: #gls-description("cpu") // "The brain of a computer." Group: #gls-group("cpu") // "Hardware" Article (short): #gls-artshort("cpu") // "a" Article (long): #gls-artlong("cpu") // "a" // Access custom dictionary attributes #context gls-custom("cpu", ctx: false).manufacturer // "Intel" #context gls-custom("cpu", ctx: false).cores // 8 // With link enabled #gls-short("cpu", link: true) // Creates clickable link ``` -------------------------------- ### Print Glossary in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md Shows how to display the registered glossary terms using the `print-glossary` function. It explains options like `show-all` to display unreferenced terms and `disable-back-references` to hide them. It also details how to customize group breaks using `user-group-break`. ```typst #print-glossary(entry-list) // Example with options: // #print-glossary(entry-list, show-all: true, disable-back-references: true, user-group-break: pagebreak()) ``` -------------------------------- ### Import Glossary Terms from YAML with Typst Source: https://context7.com/typst-community/glossarium/llms.txt Loads glossary entries from an external YAML file. This function parses a YAML file, extracts glossary definitions, and registers them with the glossarium package. It allows for cleaner separation of term definitions. ```typ // glossary.yml // html: // short: HTML // long: HyperText Markup Language // description: The standard markup language for web pages. // group: Web // css: // short: CSS // long: Cascading Style Sheets // description: Style sheet language for HTML documents. // group: Web #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, print-glossary #show: make-glossary // Custom YAML reader function #let read-glossary-entries(file) = { let entries = yaml(file) return entries.pairs().map(((key, entry)) => ( key: key, short: entry.at("short", default: key), long: entry.at("long", default: none), description: entry.at("description", default: none), group: entry.at("group", default: ""), )) } #let entries = read-glossary-entries("glossary.yml") #register-glossary(entries) Learn about @html and @css today. = Glossary #print-glossary(entries, show-all: true) ``` -------------------------------- ### Style All Links Blue in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md Applies a global style to all links, making them dark blue. This is a general styling rule for all `link` elements in Typst documents. ```typ #show link: set text(fill: blue.darken(60%)) // links are now blue ! ``` -------------------------------- ### Reset Glossary Term Usage Counts Source: https://context7.com/typst-community/glossarium/llms.txt Explains how to use the `reset-counts` function to reset the usage count of glossary terms. This allows terms to be displayed with their full long form again, as if they were being referenced for the first time. It can reset specific terms or all terms at once. This requires the glossarium package. ```typst #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, gls, reset-counts #show: make-glossary #let entries = ( (key: "ml", short: "ML", long: "Machine Learning"), (key: "ai", short: "AI", long: "Artificial Intelligence"), ) #register-glossary(entries) = Chapter 1 First use: #gls("ml") and #gls("ai"). Second use: #gls("ml") and #gls("ai"). // Shows short forms = Chapter 2 // Reset specific terms - next use shows full form again #reset-counts("ml", "ai") Fresh start: #gls("ml") and #gls("ai"). // Shows long forms again = Chapter 3 // Reset all terms at once #reset-counts() All reset: #gls("ml") and #gls("ai"). // Shows long forms ``` -------------------------------- ### Count Glossary References with Typst Source: https://context7.com/typst-community/glossarium/llms.txt Utility functions to count references to glossary terms. `count-refs` counts a specific term, `count-all-refs` counts all terms (optionally filtered by group), and `there-are-refs` checks if any references exist. Useful for conditional display. ```typ #import "@preview/glossarium:0.5.10": make-glossary, register-glossary, gls #import "@preview/glossarium:0.5.10": count-refs, count-all-refs, there-are-refs #show: make-glossary #let entries = ( (key: "html", short: "HTML", long: "HyperText Markup Language", group: "Web"), (key: "css", short: "CSS", long: "Cascading Style Sheets", group: "Web"), (key: "unused", short: "UNUSED", group: "Other"), ) #register-glossary(entries) Using @html and @html and @css once. // Count references to a specific term #context [HTML was referenced #count-refs("html") times.] // 2 // Count all references as array of (key, count) pairs #context [All counts: #count-all-refs()] // (("html", 2), ("css", 1), ("unused", 0)) // Filter by entry list or groups #context count-all-refs(groups: ("Web",)) // Check if any references exist (useful for conditional glossary) #context if there-are-refs() { [= Glossary] print-glossary(entries) } // Check specific groups #context if there-are-refs(groups: ("Web",)) { [= Web Technologies Glossary] } ``` -------------------------------- ### Conditional Link Styling in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md Styles only string-based links (like URLs or mailto links) red, while leaving other link types (like internal references) with their default styling. This prevents conflicts with specific reference styling rules. ```typ #show link: it => { if type(it.dest) == str { // Style links to strings red text(fill: red, it) } else { // Return other links as usual it } } ``` -------------------------------- ### Style Specific Glossarium References in Typst Source: https://github.com/typst-community/glossarium/blob/master/README.md Styles only references to glossary entries, making them dark blue. This rule targets references generated by `@ref` and `@ref:pl` that point to 'glossarium_entry' figures. It ensures other reference types are not affected. ```typ #show: make-glossary #show ref: it => { let el = it.element if el != none and el.func() == figure and el.kind == "glossarium_entry" { // Make the glossarium entry references dark blue text(fill: blue.darken(60%), it) } else { // Other references as usual. it } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.