I have a list like
- 3
- 2
- 1
I'd like to sort it before displaying. How do I do that?
I've tried variations of #show list,
#let a = [
- 3
- 2
- 1
]
#a.children.sorted()
I can't quite work how how to hook in to what I want here.
There's two ways you can do this. First, you probably want to save your list data in an array independently of the list type. Then you can sort it and spread the sorted list with the ..-operator into #list.
If your data consists of integers, you will have to convert it to content first currently. The second approach is using a for-loop, no spreading or mapping required.
#let a = (3, 2, 1)
#let b = a.sorted().map(x => [#x])
#list(..b)
#for x in a.sorted() [
- #x
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With