How do you apply a style to Glossarium references, that is different to other reference types?

I’m having a play with Glossarium, and I’m trying to figure out how to apply a style to glossary references, without it affecting other links. For example, I might like web links to appear blue and underlined, but I want my glossary references to be in smallcaps. So far I have determined that the target of a glossary reference is the figure function, so I’ve been able to do this:

#show ref: it => {
	let head = heading
	let el = it.element
	if el != none and el.func() == heading {
	// Override heading references.
		text(fill: red)[#link(el.location())[#it: #el.body]]
	} else if el != none and el.func() == figure {
		smallcaps(it)
	} else {
		// Other references as usual.
		it
	}
}

This is close, but the problem is that this means that references to actual figures in the body of the document will have the same style as Glossarium references. How do I get even more specific than that?

Hi @Ogre,

You were very close, as you already discovered that Glossarium uses the figure element. Figures can have different kinds—the built-in kinds are image, table, and raw. However, custom kinds can also be used, Glossarium uses the glossarium_entry kind.

You can check for this with el.kind == "glossarium_entry".

#show ref: it => {
	let head = heading
	let el = it.element
	if el != none and el.func() == heading {
	// Override heading references.
		text(fill: red)[#link(el.location())[#it: #el.body]]
	} else if el != none and el.func() == figure and el.kind == "glossarium_entry" {
		smallcaps(it)
	} else {
		// Other references as usual.
		it
	}
}

If you’re wondering how to figure this out, you have two options: either read the source code of Glossarium :slight_smile: or if you use the Typst web app, simply hover your mouse pointer over the it in #show ref: it => {.

1 Like

Hi @flokl,

Thanks for your help. I think it was the existence of the kind property that I wasn’t able to find.

I also didn’t know you could hover over code to get information in the web app. I’ve mostly been using the VSCode plugin.

It works the same in VS Code with Tinymist as it does in the web app. Just hover your mouse over a variable and a tooltip will show all of the values that the variable has.