nl = \break % it's true, ok!

a = \axyz % this is wrong with output time adds 1 2 4 8 16 ..
\axyz16 \axyz4 % etc.

Is it possible to build variable to replace notes? Maybe with Scheme?

I would like to markup some notes within info like this:

a = \az^\markup \translate #'(-1 . 0) "+5"
b = \bz^"+12"


Please any ideas?

Something with Scheme function like

(lambda (la-la? (x? y?))) newLa
  • 1
    I'm somehow having trouble trying to understand what you're asking. Could you include some more specifics?
    – Richard
    Mar 2, 2022 at 12:13
  • I just search possibllity make variable for note names or chord names to use in score. If I write \var16 or \var4 or \var[time] this is not avaliable usally
    – semiono
    Mar 2, 2022 at 13:44
  • link
    – semiono
    Mar 2, 2022 at 13:50
  • Did I get you right? You need to store a chord and reuse it with different durations. Maybe all you need is the shorthand (q) for repeating a chord? <c e g'>4 q8 q8 You could also write a lilypond-function using \shiftDurations.
    – rfbw
    Mar 2, 2022 at 16:15
  • \shiftDurations - Thanks! I will study that. q - I know
    – semiono
    Mar 2, 2022 at 19:41

1 Answer 1


If I understand you correctly you want to be able to have a variable with music and potentially some additional stuff like TextScripts.

You can use functions like this

var =
#(define-music-function (dur) (ly:duration?)
     a $dur ^\markup \translate #'(-1 . 0) "+5"

\displayMusic {
  \var4 \var2 \var8. \var16

The one disadvantage of this is that you cannot use this without specifying a duration.

You can also use music function to replace certain notes by different music like this:

mapMyNote =
#(define-music-function (music) (ly:music?)
   (define (walk music)
     (let* ((elts (ly:music-property music 'elements))
            (elt (ly:music-property music 'element)))
      (if (music-is-of-type? music 'note-event)
          (if (= (ly:pitch-notename (ly:music-property music 'pitch)) 5) ; a
                \transpose #(ly:make-pitch -1 0) #(ly:make-pitch (ly:pitch-octave (ly:music-property music 'pitch)) 0)
                <a c' e'> $(ly:music-property music 'duration) ^"+5"
               (if (not (null? elt))
                   (ly:music-set-property! music 'element (walk elt)))
               (ly:music-set-property! music 'elements (map walk elts))
           (if (not (null? elt))
               (ly:music-set-property! music 'element (walk elt)))
           (ly:music-set-property! music 'elements (map walk elts))
    (walk music))

\mapMyNote { a a' }

EDIT: @semiono Aha. Seeing this is about microtonality: Something like this might also be useful:

#(define-event-function (ct) (number?)
   -\tweak self-alignment-X #CENTER
   -\tweak parent-alignment-X #CENTER
   -\tweak font-size #-3.4
   -\markup \bold #(format #f (if (integer? ct) "~@d" "~@f") ct)

{ c' d' e'\t2 f'^\t-2 g'\t2.3 }
  • link Really useful for me! I do microtonal experiments and put the value of cents in the mark :)
    – semiono
    Mar 2, 2022 at 21:33
  • Thank you again! But e\t2 or e^"+2" practically does not reduce the text except for alignment. Originally I did this aa\aax ab\abx with aax = \aa translate ~"+5" etc. Nevertheless Lisp/Scheme great tool :)
    – semiono
    Mar 3, 2022 at 21:30
  • @semiono Something like this can be useful if you need a) a larger amount of cent values or b) if you ever want to change the formatting of these.
    – Lazy
    Mar 3, 2022 at 21:36

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