Next: , Previous: Hidden notes, Up: Inside the staff


Coloring objects

Individual objects may be assigned colors. Valid color names are listed in the List of colors.

     
     \override NoteHead #'color = #red
     c4 c
     \override NoteHead #'color = #(x11-color 'LimeGreen)
     d
     \override Stem #'color = #blue
     e

[image of music]

The full range of colors defined for X11 can be accessed by using the Scheme function x11-color. The function takes one argument; this can be a symbol in the form 'FooBar or a string in the form "FooBar". The first form is quicker to write and is more efficient. However, using the second form it is possible to access X11 colors by the multi-word form of its name.

If x11-color cannot make sense of the parameter then the color returned defaults to black.

     
     \override Staff.StaffSymbol #'color = #(x11-color 'SlateBlue2)
     \set Staff.instrumentName = \markup {
       \with-color #(x11-color 'navy) "Clarinet"
     }
     
     gis8 a
     \override Beam #'color = #(x11-color "medium turquoise")
     gis a
     \override Accidental #'color = #(x11-color 'DarkRed)
     gis a
     \override NoteHead #'color = #(x11-color "LimeGreen")
     gis a
     % this is deliberate nonsense; note that the stems remain black
     \override Stem #'color = #(x11-color 'Boggle)
     b2 cis

[image of music]

Exact RGB colors can be specified using the Scheme function rgb-color.

     
     \override Staff.StaffSymbol #'color = #(x11-color 'SlateBlue2)
     \set Staff.instrumentName = \markup {
       \with-color #(x11-color 'navy) "Clarinet"
     }
       
     \override Stem #'color = #(rgb-color 0 0 0)
     gis8 a
     \override Stem #'color = #(rgb-color 1 1 1)
     gis8 a
     \override Stem #'color = #(rgb-color 0 0 0.5) 
     gis4 a

[image of music]

See also

Notation Reference: List of colors, The tweak command.

Snippets: Editorial annotations.

Known issues and warnings

An X11 color is not necessarily exactly the same shade as a similarly named normal color.

Not all X11 colors are distinguishable in a web browser, i.e., a web browser might not display a difference between 'LimeGreen and 'ForestGreen. For web use normal colors are recommended (i.e., #blue, #green, #red).

Notes in a chord cannot be colored with \override; use \tweak instead, see The tweak command.

This page is for LilyPond-2.11.58 (development-branch).

Report errors to http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs.

Your suggestions for the documentation are welcome.

Other languages: français, español.