How to change enum coloring with both alphabets and numbers?

I need to use numbered and alphabetical enums in my document. I am able to change coloring of numbered enums, but not alphabetical. How can I change coloring of both?


// How to change a,b,c color here on the styling section:

#let marker-num-color = rgb("#0969DA") //rgb("#0074D9")
#set list(marker: ([▸], [▹]).map(text.with(marker-num-color)))
#set enum(numbering: (..n) => text(marker-num-color, numbering("1.", ..n)))

// I don't want to touch code below this as it's generated from markdown to typst

+ #lorem(10)
  - #lorem(10)
  - #lorem(10)
+ #lorem(10)
  - #lorem(10)
+ #lorem(10)
  - #lorem(10)

#block[
#set enum(numbering: "a)", start: 1)
+ #lorem(10)

+ #lorem(10)

+ #lorem(10)

+ #lorem(10)
]


Hi there @Jarko,

You seem to be missing a show rule to globally set the item’s number to the desired colour.

Perhaps adding something like this would work?

In your current code the color of the numbering is overridden by the set rule inside the block. Since this code is generated from markdown my understanding is that you are not able to include the coloring of the markers there?

My proposed solution uses two show-set rules to achieve the coloring of the markers. The first rule will set the text color of the entire enum to blue, and the second rule will set the text color of the enum item body to black again. This only leaves the enum markers in the blue color.

#show enum: set text(blue)
#show enum.item: set text(black)

Note that this fails if you only have an enum with a single item. The rule for enum.item is not applied in this case. I think this is related to `#show enum.item` doesn't apply to `#enum` · Issue #1274 · typst/typst · GitHub.

4 Likes

Thank you very much janekfleper. I really dig your clever out of the box thinking here. With my use case, I can live with the limitation you mentioned. However I will leave this unanswered, in case someone has a solution without the limitation.

In case someone has a solution without the limitation, the solution marker can always be changed to another post, if it ever appears.

1 Like