Art credits: a major mangling of the figures ToC?

Then you can technically change sorting to .sorted(key: it => int(it.last().first())), but since all items initially sorted by page, and then transformed to a dictionary, the artist insertion order is preserved, so you don’t need to sort anything, only group by artist.

#show figure.where(kind: "art"): set figure(supplement: none)
#show figure.caption.where(kind: "art"): none

#let art-toc() = context {
  "Internal Art:"
  let items = query(figure.where(kind: "art")).map(fig => (
    artist: fig.caption.body.text,
    page: str(fig.location().page()),
  ))
  let artist-pages = (:)
  for (artist, page) in items {
    let pages = artist-pages.at(artist, default: ())
    artist-pages += ((artist): pages + (page,))
  }
  artist-pages
    .pairs()
    // .sorted(key: it => int(it.last().first()))
    .map(((artist, pgs)) => {
      pgs = if pgs.len() == 1 [p. #pgs.first()] else [pp. #pgs.join(", ")]
      [ #artist (#pgs)]
    })
    .join[,]
}

#art-toc()

#range(6).map(_ => pagebreak()).join()

#figure(rect(), caption: "Artist A", kind: "art")

#range(1).map(_ => pagebreak()).join()

#figure(rect(), caption: "Artist B", kind: "art")

#range(2).map(_ => pagebreak()).join()

#figure(rect(), caption: "Artist C", kind: "art")

#range(2).map(_ => pagebreak()).join()

#figure(rect(), caption: "Artist B", kind: "art")
1 Like