diff --git a/glossy/README.md b/glossy/README.md index 4e6fe5f..6029dff 100644 --- a/glossy/README.md +++ b/glossy/README.md @@ -186,8 +186,9 @@ Display the glossary using the `glossary()` function: ```typst #glossary( - title: "Web Development Glossary", // Optional: defaults to Glossary - theme: my-theme, // Optionaal: defaults to theme-twocol + title: "Web Development Glossary", // Optional: defaults to Glossary theme: + my-theme, // Optional: defaults to theme-academic + sort: true, // Optional: whether or not to sort the glossary ignore-case: false, // Optional: ignore case when sorting terms groups: ("Web") // Optional: Filter to specific groups ) diff --git a/glossy/src/gloss.typ b/glossy/src/gloss.typ index 3260652..d5d9e99 100644 --- a/glossy/src/gloss.typ +++ b/glossy/src/gloss.typ @@ -541,6 +541,7 @@ #let glossary( title: "Glossary", theme: theme-academic, + sort: true, ignore-case: false, groups: (), ) = context { @@ -601,13 +602,17 @@ group = if group == none { "" } else { group } // sort entries by case insensitivity if requested - let sorted_entries = current_entries - // 1. create array of tuples with (lower [if ignore-case], entry) - .map(e => { if ignore-case { (lower(e.short), e) } else { (e.short, e) } }) - // 2. sort the tuples (by first element then second) - .sorted() // NOTE: sorted() is NOT language-aware - // 3. strip away the tuple's first element, leaving an array of entries - .map(t => t.last()) + let sorted_entries = if sort { + current_entries + // 1. create array of tuples with (lower [if ignore-case], entry) + .map(e => { if ignore-case { (lower(e.short), e) } else { (e.short, e) } }) + // 2. sort the tuples (by first element then second) + .sorted() // NOTE: sorted() is NOT language-aware + // 3. strip away the tuple's first element, leaving an array of entries + .map(t => t.last()) + } else { + current_entries + } // add entries to this group's output map output.insert(group, sorted_entries) diff --git a/glossy/tests/no-sort/glossary.yml b/glossy/tests/no-sort/glossary.yml new file mode 100644 index 0000000..84b3b0b --- /dev/null +++ b/glossy/tests/no-sort/glossary.yml @@ -0,0 +1,23 @@ +first: + short: "DAL" + long: "first" + +second: + short: "cab" + long: "second" + +third: + short: "delta" + long: "third" + +fourth: + short: "COO" + long: "fourth" + +fifth: + short: "cuckoo" + long: "fifth" + +sixth: + short: "ČR" + long: "sixth" diff --git a/glossy/tests/no-sort/ref/1.png b/glossy/tests/no-sort/ref/1.png new file mode 100644 index 0000000..9bc9fab Binary files /dev/null and b/glossy/tests/no-sort/ref/1.png differ diff --git a/glossy/tests/no-sort/test.typ b/glossy/tests/no-sort/test.typ new file mode 100644 index 0000000..554f927 --- /dev/null +++ b/glossy/tests/no-sort/test.typ @@ -0,0 +1,13 @@ +#import "/lib.typ":* + +#show: init-glossary.with(yaml("glossary.yml")) + +@first, @second, @third, @fourth, @fifth, @sixth + +#glossary(ignore-case: false, sort: true) +#line(length: 20em) +#glossary(ignore-case: true, sort: true) +#line(length: 20em) +#glossary(ignore-case: false, sort: false) +#line(length: 20em) +#glossary(ignore-case: true, sort: false)