I would like to create a shorthand for a compound markup command, say MVE

#(define-markup-command (shorthand layout props text) (number-or-markup?) (interpret-markup layout props #{ \markup \bold \italic #text #}))

However, this errors out with "error: not a markup" when passed a number. How would I type-coerce the argument into markup?

  • Adding a nested \markup is "unexpected".
  • \simple only takes strings to begin with.
  • Yes I know passing "number" avoids the issue but it's not ergonomic.

Well, instead of #text you could write #(if (number? text) (number->string text) text). The obvious idea #(format #f "~a" text) would fail if text happened to be a markup that isn't a string.


Based on user73384 finding the core conversion function (number->string), I'm using

#(define-markup-command (to-markup layout props text) (number-or-markup?) (interpret-markup layout props #{ #(if (number? text) (number->string text) text) #}))

as a helper.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.