Jump to content

Using Scheme to create a list of all available X11 colors (obsolete in 2.25)

From LilyPond wiki
(Redirected from LSR 394)

LilyPond supports named colors through x11-color, the corresponding color names can be found in the file scm/x11-color.scm. Using scheme, one can easily create a lilypond file displaying (all) supported color names with an example of each color automatically.
The way to do this is loading the scolor.scm file and then creating a \markup for each color definition.

This snippet is obsolete in version 2.25 since the documentation now contains a list of colors that also displays a square with each color. See List of colors.

\version "2.24"

%% http://lsr.di.unimi.it/LSR/Item?id=394
%% see also http://www.lilypond.org/doc/v2.18/Documentation/notation/list-of-colors

%% Remark from 2.22.-updater:
%% #(ly:load "x11-color.scm")
%% does not work as here intended any more.
%% Instead we use (@@ (lily) x11-color-list)
%% NB (following the guile-manual) @@-synatx is "last resort"
%%   -Harm

% To show all available colors (~17 pages), replace
% (take (@@ (lily) x11-color-list) 15) by x11-color-list
#(define-markup-list-command (listcolors layout props) ()
  (interpret-markup-list layout props
    (map (lambda (colorspec)
      (markup #:with-color (x11-color (car colorspec))
              #:filled-box '(-0.5 . 10) '(-1 . 3) 1
              (symbol->string (car colorspec))))
      (take (@@ (lily) x11-color-list) 15))))

\markuplist \column-lines \listcolors
\markup "... (only the first 15 colors are shown)"