Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ You can also reference the automatically generated labels:

Please note that these are only generated if the `key` does not start with an uppercase letter.

To customize capitalization once for both `@Ref` syntax and direct calls such as
`#Gls("ref")`, configure `user-capitalize` on `make-glossary`:

```typ
#show: make-glossary.with(
user-capitalize: text => text
.split(" ")
.map(word => upper(word.first()) + word.slice(1))
.join(" "),
)
```

### Overriding the text shown

You can also override the text displayed by setting the `display` argument.
Expand Down
Binary file modified tests/user-capitalization/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion tests/user-capitalization/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(key: "bar"),
(key: "baz"),
(key: "qux", short: $xi zeta eta$),
(key: "syscall", short: "system call"),
)
#register-glossary(entry-list)
#show: make-glossary.with(
Expand All @@ -12,7 +13,7 @@
if type(txt) == content and txt.func() == math.equation {
txt.body.children.filter(x => x != [ ]).join("-")
} else if type(txt) == str {
upper(txt.at(0)) + txt.slice(1)
txt.split(" ").map(word => upper(word.at(0)) + word.slice(1)).join(" ")
} else if type(txt) == none {
txt
}
Expand All @@ -25,3 +26,7 @@
@bar, @Bar

@qux, @Qux

@syscall, @Syscall

#gls("syscall"), #Gls("syscall"), #gls("syscall", capitalize: true)
22 changes: 15 additions & 7 deletions themes/default.typ
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@
}
return upper(text.first()) + text.slice(1)
}
#let __glossarium_user_capitalize = state(
"__glossarium_user_capitalize",
default-capitalize,
)
#let __uncapitalize(text) = {
return lower(text.first()) + text.slice(1)
}
Expand Down Expand Up @@ -706,9 +710,12 @@
capitalize: false,
plural: false,
article: false,
user-capitalize: default-capitalize,
user-capitalize: none,
user-plural: default-plural,
) = {
if user-capitalize == none {
user-capitalize = __glossarium_user_capitalize.at(here())
}
let entry = __get_entry_with_key(here(), key)

// Attributes
Expand Down Expand Up @@ -834,7 +841,7 @@
capitalize: false,
plural: false,
article: false,
user-capitalize: default-capitalize,
user-capitalize: none,
user-plural: default-plural,
) = context _gls(
key,
Expand All @@ -861,7 +868,7 @@
styles: none,
link: true,
update: true,
user-capitalize: default-capitalize,
user-capitalize: none,
user-plural: default-plural,
) = gls(
key,
Expand Down Expand Up @@ -895,7 +902,7 @@
link: true,
update: true,
capitalize: false,
user-capitalize: default-capitalize,
user-capitalize: none,
user-plural: default-plural,
) = gls(
key,
Expand All @@ -918,7 +925,7 @@
styles: none,
link: true,
update: true,
user-capitalize: default-capitalize,
user-capitalize: none,
user-plural: default-plural,
) = gls(
key,
Expand Down Expand Up @@ -953,7 +960,7 @@
link: true,
update: true,
capitalize: false,
user-capitalize: default-capitalize,
user-capitalize: none,
user-plural: default-plural,
) = gls(
key,
Expand All @@ -979,7 +986,7 @@
styles: none,
link: true,
update: true,
user-capitalize: default-capitalize,
user-capitalize: none,
user-plural: default-plural,
) = gls(
key,
Expand Down Expand Up @@ -1106,6 +1113,7 @@
user-capitalize: default-capitalize,
user-plural: default-plural,
) = {
__glossarium_user_capitalize.update(_ => user-capitalize)
[#metadata("glossarium:make-glossary")<glossarium:make-glossary>]
// Set figure body alignment
show __glossarium_entry_selector: it => {
Expand Down