I try to create n little colored squares aligned in a horizontal line. I seem to fail in every way that I try. Adding squares to a list seems impossible. My latest attempt was to map from a range to squares:
#let n = 5
#range(n).map(ang => [#square(fill: color.hsl(ang * 1deg, 100%, 50%))])
I get the following output (sorry, I cannot copy the code).

the squares are not rendered somehow. What am I doing wrong here?
I want to align the squares inside a math function (in color though)
$ f( #sym.qed #sym.qed ... ) $
The function .map()
always returns an array, see Array Type β Typst Documentation. If you want to turn the array into content, you could for example use the function .join()
or pass the array elements to the function stack()
. There might be even more options to actually show the squares, but this should be enough to get you started.
#let n = 5
#let squares = range(n).map(ang => [#square(fill: color.hsl(ang * 1deg, 100%, 50%))])
#squares.join()
#stack(dir: ltr, spacing: 1em, ..squares)
Note that you could also change the color of the symbol sym.qed
if you donβt want to draw arbitrary shapes. If all symbols should have the same color, you can use a show-set rule
#show sym.qed: set text(red)
$ f( #sym.qed #sym.qed ... ) $
If you want to color the qed symbols individually, you can define a function that returns the symbol in a specific color
#let c-qed(color) = text(color, sym.qed)
$ f( #c-qed(blue) #c-qed(red) ... ) $
3 Likes
thank you very much!
That is really helpful!
Note you can also use a for loop instead. Basically, these two are equivalent:
range(n).map(i => ...).join()
// and
for i in range(n) { ... }
2 Likes
Hi @Lukipuki, if you feel the response you got has sufficiently answered your question, be sure to give it a checkmark
. This will help others find the solution in the future. If something is missing, please let us know what so we can resolve your issue. Thanks!