\version "2.12.0" #(define counter-alist '()) #(define-markup-command (counter layout props name) (string?) (let* ((oldval (assoc-ref counter-alist name)) (newval (if (number? oldval) (+ oldval 1) 1))) (set! counter-alist (assoc-set! counter-alist name newval)) (interpret-markup layout props (markup (number->string newval))))) #(define-markup-command (setcounter layout props name value) (string? number?) (set! counter-alist (assoc-set! counter-alist name (- value 1))) (interpret-markup layout props (make-counter-markup name))) \markup {This is a counter: \counter #"testing" } \markup {It is increasing: \counter #"testing" } \markup {It is increasing: \counter #"testing" } \markup {Setting to a specific value works, too:} \markup {Set to 15: \setcounter #"testing" #15 } \markup {It is increasing: \counter #"testing" } \markup {It is increasing: \counter #"testing" } \markup {It is increasing: \counter #"testing" } \markup {It is increasing: \counter #"testing" } \markup {It is increasing: \counter #"testing" }