This seems quite straightforward, but I've spent far too much time struggling.

I frequently using markup of the form:

\markup \with-url#"https:\\youtu.be .....  t=214" {ref}

This creates a hyperlinked text that links directly to a spot in a video on Youtube. Each instance needs a different value after t=.

Ideally, I would like a function that can be invoke with a number or string (that's not a big deal), so that my input would look something like:

c2^\refer "346", or maybe c2^#(refer 346), or some such thing.

I have struggled with including \markup in a scheme function, or trying define-markup-function all with no success.

1 Answer 1


This should do the trick:

vid = "videoid"
baseURL = #(format #f "https://youtube.com/watch?v=~a" vid)

#(define-markup-command (refer layout props ts) (number?)
   (interpret-markup layout props
                     (markup #:with-url (format #f "~a&t=~a" baseURL ts) "ref")))

refer =
#(define-music-function (ts) (number?)
     -\markup\refer #ts

{ c2\refer 234 }
  • First --- MANY thanks. I never ceased to be amazed at the combination of willingness and competence. A couple of details - I am using the youtube shortened URL, so I replaced the use of (format ...) for the baseURL with the actual shortened one. And thanks for showing me the use of (format #f.... I guess at some point I should get some actual Scheme documentation. The closest I've come is writing LISP code, but that was back in the 1960s. I modified the definition of refer to take minutes and seconds and do the arithmetic to convert it to seconds, for Youtube wants. THANKS!!
    – Ken Ledeen
    Apr 8, 2023 at 3:02
  • @KenLedeen You’re welcome :). As far as I know YouTube does also take timestamps like t=1m34s, so you might just paste the timestamp together in this format and leave the arithmetic part (although it is not hard) to YouTube.
    – Lazy
    Apr 8, 2023 at 8:12
  • and now for a followup question that reveals the limit of my knowledge. from the example above, which works perfectly, I assumed that I could invoke \refer from inside my own markup commands. For example \markup \refer 3 14 But this doesn’t work. I get error messages like: ...ince.ly:234:16: error: syntax error, unexpected SYMBOL \markup \refer 1 2 My usage seems entirely consistent with the way it’s used in the defined music function. what am I not understanding?
    – Ken Ledeen
    Apr 24, 2023 at 15:58
  • @KenLedeen Resolving arguments to markup function does use much less parsing magic. So for Lilypond to know you are passing a number you actually need to pass a scheme number, e.g. do \markup\refer #1.
    – Lazy
    Apr 24, 2023 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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