How to adjust the style for the terms only in a term list?

Hi,

I’m looking for some solutions to adjust the terms’ style in a term list. Basically, I want the terms are shown in red, but the descriptions shown as normal text. Although I can add some text() function to each term but I still want to achieve this via show-set rules. Can anyone help me?

I figured it out. The default layout of terms is “approximately” equals to

show terms: body => {
  body.children.map(it => pad(left: body.indent + body.hanging-indent, {
    box(inset: (left: -body.hanging-indent), it.term)
    body.separator
    it.description
  })).join()
}

So you can adjust the style of it.term in this show-set rule

3 Likes

There’s also the term.item element for configuring the appearance per item which may reduce some of the boilerplate.

1 Like

The solution should be documented. I mean that every object needs to have all its attributes stated in the documentation, so people could figure this out by reading the documentation.

2 Likes

Yes, I agree. If an element have a default style written in typst, the style needs to be documented.

Thank you for posting your solution. As an update, there is a GitHub issue wherein @laurmaedje provides a more comprehensive version (See [here]).

TL;DR, here is the snippet provided:

#show terms: it => pad(left: it.indent + it.hanging-indent, stack(
  ..it.children.map(item => {
    h(-it.hanging-indent)
    item.term
    it.separator
    item.description
  }),
  spacing: if it.tight { 
    par.leading 
  } else if it.spacing == auto {
    1.2em // block.below doesn't work yet
  } else { 
    it.spacing 
  },
))