Hello Jean,
at least for me this code fails to change the order of the toc. The reason for
this is that toc-markup does not in fact contain the markup, but the symbol
under which the formatting markup is saved in layout.
So I suppose you rather want to use the text property:
(sorted-toc-alist
(sort toc-alist
;; Could use comparator-from-key in 2.23
(lambda (item1 item2)
(let ((mkup1 (assoc-get 'text (cdr item1)))
(mkup2 (assoc-get 'text (cdr item2))))
(string<?
(markup->string mkup1)
(markup->string mkup2))))))