1 @c -*- coding: utf-8; mode: texinfo; -*-
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
13 @chapter Scheme tutorial
18 @cindex Scheme, in-line code
19 @cindex accessing Scheme
20 @cindex evaluating Scheme
23 LilyPond uses the Scheme programming language, both as part of the
24 input syntax, and as internal mechanism to glue modules of the program
25 together. This section is a very brief overview of entering data in
26 Scheme. If you want to know more about Scheme, see
27 @uref{http://@/www@/.schemers@/.org}.
29 LilyPond uses the GNU Guile implementation of Scheme, which is
30 based on the Scheme @qq{R5RS} standard. If you are learning Scheme
31 to use with LilyPond, working with a different implementation (or
32 referring to a different standard) is not recommended. Information
33 on guile can be found at @uref{http://www.gnu.org/software/guile/}.
34 The @qq{R5RS} Scheme standard is located at
35 @uref{http://www.schemers.org/Documents/Standards/R5RS/}.
38 * Introduction to Scheme::
39 * Scheme in LilyPond::
40 * Building complicated functions::
43 @node Introduction to Scheme
44 @section Introduction to Scheme
46 We begin with an introduction to Scheme. For this brief introduction,
47 we will use the GUILE interpreter to explore how the language works.
48 Once we are familiar with Scheme, we will show how the language can
49 be integrated in LilyPond files.
55 * Scheme simple data types::
56 * Scheme compound data types::
57 * Calculations in Scheme::
59 * Scheme conditionals::
63 @subsection Scheme sandbox
65 The LilyPond installation includes the Guile implementation of
66 Scheme. On most systems you can experiment in a Scheme sandbox by
67 opening a terminal window and typing @q{guile}. On some systems,
68 notably Windows, you may need to set the environment variable
69 @code{GUILE_LOAD_PATH} to the directory @code{../usr/shr/guile/1.8}
70 in the LilyPond installation. For the full path to this directory
71 see @rlearning{Other sources of information}. Alternatively, Windows
72 users may simply choose @q{Run} from the Start menu and enter
75 Once the guile sandbox is running, you will received a guile prompt:
81 You can enter Scheme expressions at this prompt to experiment with Scheme.
83 @node Scheme variables
84 @subsection Scheme variables
86 Scheme variables can have any valid scheme value, including a Scheme
89 Scheme variables are created with @code{define}:
96 Scheme variables can be evaluated at the guile prompt simply by
97 typing the variable name:
105 Scheme variables can be printed on the display by use of the display function:
113 Note that the value @code{2} and the guile prompt @code{guile} both
114 showed up on the same line. This can be avoided by calling the newline
115 procedure or displaying a newline character.
118 guile> (display a)(newline)
120 guile> (display a)(display "\n")
125 Once a variable has been created, its value can be changed with @code{set!}:
128 guile> (set! a 12345)
134 @node Scheme simple data types
135 @subsection Scheme simple data types
137 The most basic concept in a language is data typing: numbers, character
138 strings, lists, etc. Here is a list of simple Scheme data types that are
139 often used with LilyPond.
143 Boolean values are True or False. The Scheme for True is @code{#t}
144 and False is @code{#f}.
149 Numbers are entered in the standard fashion,
150 @code{1} is the (integer) number one, while @code{-1.5} is a
151 floating point number (a non-integer number).
154 Strings are enclosed in double quotes,
160 Strings may span several lines:
169 and the newline characters at the end of each line will be included
172 Newline characters can also be added by including @code{\n} in the
176 "this\nis a\nmultiline string"
180 Quotation marks and backslashes are added to strings
181 by preceding them with a backslash.
182 The string @code{\a said "b"} is entered as
190 There are additional Scheme data types that are not discussed here.
191 For a complete listing see the Guile reference guide,
192 @uref{http://www.gnu.org/software/guile/manual/html_node/Simple-Data-Types.html}.
194 @node Scheme compound data types
195 @subsection Scheme compound data types
197 There are also compound data types in Scheme. The types commonly used in
198 LilyPond programming include pairs, lists, alists, and hash tables.
200 @unnumberedsubsubsec Pairs
202 The foundational compound data type of Scheme is the @code{pair}. As
203 might be expected from its name, a pair is two values glued together.
204 The operator used to form a pair is called @code{cons}.
212 Note that the pair is displayed as two items surrounded by
213 parentheses and separated by whitespace, a period (@code{.}), and
214 more whitespace. The period is @emph{not} a decimal point, but
215 rather an indicator of the pair.
217 Pairs can also be entered as literal values by preceding them with
218 a single quote character.
226 The two elements of a pair may be any valid Scheme value:
231 guile> '("blah-blah" . 3.1415926535)
232 ("blah-blah" . 3.1415926535)
236 The first and second elements of the pair can be accessed by the
237 Scheme procedures @code{car} and @code{cdr}, respectively.
240 guile> (define mypair (cons 123 "hello there")
251 Note: @code{cdr} is pronounced "could-er", according Sussman and
253 @uref{http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#footnote_Temp_133}
256 @unnumberedsubsubsec Lists
258 TODO -- write about lists
260 A very common Scheme data structure is the @emph{list}. Formally, a
261 list is defined as either the empty list (represented as @code{'()},
262 or a pair whose @code{cdr} is a list.
264 There are many ways of creating lists. Perhaps the most common is
265 with the @code{list} procedure:
268 guile> (list 1 2 3 "abc" 17.5)
272 As can be seen, a list is displayed in the form of individual elements
273 separated by whitespace and enclosed in parentheses. Unlike a pair,
274 there is no period between the elements.
276 A list can also be entered as a literal list by enclosing its
277 elements in parentheses, and adding a quote:
280 guile> '(17 23 "foo" "bar" "bazzle")
281 (17 23 "foo" "bar" "bazzle")
284 Lists are a central part of Scheme. In, fact, Scheme is considered
285 a dialect of lisp, where @q{lisp} is an abbreviation for
286 @q{List Processing}. Scheme expressions are all lists.
288 @unnumberedsubsubsec Association lists (alists)
290 A special type of list is an @emph{association list} or @emph{alist}.
291 An alist is used to store data for easy retrieval.
293 Alists are lists whose elements are pairs. The @code{car} of each
294 element is called the @code{key}, and the @code{cdr} of each element
295 is called the @code{value}. The Scheme procedure @code{assoc} is
296 used to retrieve an entry from the alist, and @code{cdr} is used to
300 guile> (define my-alist '((1 . "A") (2 . "B") (3 . "C")))
302 ((1 . "A") (2 . "B") (3 . "C"))
303 guile> (assoc 2 my-alist)
305 guile> (cdr (assoc 2 my-alist))
310 Alists are widely used in LilyPond to store properties and other data.
312 @unnumberedsubsubsec Hash tables
316 TODO -- write about hash tables
319 @node Calculations in Scheme
320 @subsection Calculations in Scheme
322 We have been using lists all along. A calculation, like @code{(+ 1 2)}
323 is also a list (containing the symbol @code{+} and the numbers 1
324 and@tie{}2). Normally lists are interpreted as calculations, and the
325 Scheme interpreter substitutes the outcome of the calculation. To enter a
326 list, we stop the evaluation. This is done by quoting the list with a
327 quote @code{'} symbol. So, for calculations do not use a quote.
329 Inside a quoted list or pair, there is no need to quote anymore. The
330 following is a pair of symbols, a list of symbols and a list of lists
335 #'(staff clef key-signature)
339 Scheme can be used to do calculations. It uses @emph{prefix}
340 syntax. Adding 1 and@tie{}2 is written as @code{(+ 1 2)} rather than the
341 traditional @math{1+2}.
348 The arrow @result{} shows that the result of evaluating @code{(+ 1 2)}
349 is@tie{}@code{3}. Calculations may be nested; the result of a function may
350 be used for another calculation.
358 These calculations are examples of evaluations; an expression like
359 @code{(* 3 4)} is replaced by its value @code{12}.
361 The same assignment can be done in completely in Scheme as well,
364 #(define twentyFour (* 2 twelve))
367 @c this next section is confusing -- need to rewrite
369 The @emph{name} of a variable is also an expression, similar to a
370 number or a string. It is entered as
377 @cindex quoting in Scheme
379 The quote mark @code{'} prevents the Scheme interpreter from substituting
380 @code{24} for the @code{twentyFour}. Instead, we get the name
383 @node Scheme procedures
384 @subsection Scheme procedures
386 @unnumberedsubsubsec Predicates
388 @unnumberedsubsubsec Return values
390 TODO -- write about scheme procedures
392 @node Scheme conditionals
393 @subsection Scheme conditionals
395 @unnumberedsubsubsec if
397 @unnumberedsubsubsec cond
400 @node Scheme in LilyPond
401 @section Scheme in LilyPond
405 * LilyPond Scheme syntax::
406 * LilyPond variables::
407 * Input variables and Scheme::
408 * Object properties::
409 * LilyPond compound variables::
410 * Internal music representation::
413 @node LilyPond Scheme syntax
414 @subsection LilyPond Scheme syntax
416 In a music file, snippets of Scheme code are introduced with the hash
417 mark @code{#}. So, the previous examples translated to LilyPond are
428 Note that LilyPond comments (@code{%} and @code{%@{ %@}}) cannot
429 be used within Scheme code. Comments in Guile Scheme are entered
433 ; this is a single-line comment
436 This a (non-nestable) Guile-style block comment
437 But these are rarely used by Schemers and never in
442 Multiple consecutive scheme expressions in a music file can be
443 combined using the @code{begin} operator. This permits the number
444 of hash marks to be reduced to one.
452 @c todo -- # introduces a scheme *expression*
453 @c need the concept of an expression
455 If @code{#} is followed by an opening parenthesis, @code{(}, as in
456 the example above, the parser will remain in Scheme mode until
457 a matching closing parenthesis, @code{)}, is found, so further
458 @code{#} symbols to introduce a Scheme section are not required.
460 For the rest of this section, we will assume that the data is entered
461 in a music file, so we add @code{#}s everywhere.
463 @node LilyPond variables
464 @subsection LilyPond variables
467 TODO -- make this read right
470 happens with variables. After defining a variable
477 variables can also be used in expressions, here
480 twentyFour = (* 2 twelve)
484 the number 24 is stored in the variable @code{twentyFour}.
486 @node Input variables and Scheme
487 @subsection Input variables and Scheme
489 The input format supports the notion of variables: in the following
490 example, a music expression is assigned to a variable with the name
494 traLaLa = @{ c'4 d'4 @}
499 There is also a form of scoping: in the following example, the
500 @code{\layout} block also contains a @code{traLaLa} variable, which is
501 independent of the outer @code{\traLaLa}.
503 traLaLa = @{ c'4 d'4 @}
504 \layout @{ traLaLa = 1.0 @}
507 In effect, each input file is a scope, and all @code{\header},
508 @code{\midi}, and @code{\layout} blocks are scopes nested inside that
511 Both variables and scoping are implemented in the GUILE module system.
512 An anonymous Scheme module is attached to each scope. An assignment of
515 traLaLa = @{ c'4 d'4 @}
519 is internally converted to a Scheme definition
521 (define traLaLa @var{Scheme value of `@code{... }'})
524 This means that input variables and Scheme variables may be freely
525 mixed. In the following example, a music fragment is stored in the
526 variable @code{traLaLa}, and duplicated using Scheme. The result is
527 imported in a @code{\score} block by means of a second variable
531 traLaLa = { c'4 d'4 }
533 %% dummy action to deal with parser lookahead
534 #(display "this needs to be here, sorry!")
536 #(define newLa (map ly:music-deep-copy
537 (list traLaLa traLaLa)))
539 (make-sequential-music newLa))
544 @c Due to parser lookahead
546 In this example, the assignment happens after the parser has
547 verified that nothing interesting happens after
548 @code{traLaLa = @{ ... @}}. Without the dummy statement in the
549 above example, the @code{newLa} definition is executed before
550 @code{traLaLa} is defined, leading to a syntax error.
552 The above example shows how to @q{export} music expressions from the
553 input to the Scheme interpreter. The opposite is also possible. By
554 wrapping a Scheme value in the function @code{ly:export}, a Scheme
555 value is interpreted as if it were entered in LilyPond syntax.
556 Instead of defining @code{\twice}, the example above could also have
561 @{ #(ly:export (make-sequential-music (list newLa))) @}
564 Scheme code is evaluated as soon as the parser encounters it. To
565 define some Scheme code in a macro (to be called later), use
566 @ref{Void functions}, or
570 (ly:set-option 'point-and-click #f))
579 Mixing Scheme and LilyPond variables is not possible with the
580 @code{--safe} option.
585 @node Object properties
586 @subsection Object properties
588 This syntax will be used very frequently, since many of the layout
589 tweaks involve assigning (Scheme) values to internal variables, for
593 \override Stem #'thickness = #2.6
596 This instruction adjusts the appearance of stems. The value @code{2.6}
597 is put into the @code{thickness} variable of a @code{Stem}
598 object. @code{thickness} is measured relative to the thickness of
599 staff lines, so these stem lines will be @code{2.6} times the
600 width of staff lines. This makes stems almost twice as thick as their
601 normal size. To distinguish between variables defined in input files (like
602 @code{twentyFour} in the example above) and variables of internal
603 objects, we will call the latter @q{properties} and the former
604 @q{variables.} So, the stem object has a @code{thickness} property,
605 while @code{twentyFour} is an variable.
607 @cindex properties vs. variables
608 @cindex variables vs. properties
610 @c todo -- here we're getting interesting. We're now introducing
611 @c LilyPond variable types. I think this deserves a section all
614 @node LilyPond compound variables
615 @subsection LilyPond compound variables
617 @unnumberedsubsubsec Offsets
619 Two-dimensional offsets (X and Y coordinates) as well as object sizes
620 (intervals with a left and right point) are entered as @code{pairs}. A
621 pair@footnote{In Scheme terminology, the pair is called @code{cons},
622 and its two elements are called @code{car} and @code{cdr} respectively.}
623 is entered as @code{(first . second)} and, like symbols, they must be quoted,
626 \override TextScript #'extra-offset = #'(1 . 2)
629 This assigns the pair (1, 2) to the @code{extra-offset} property of the
630 TextScript object. These numbers are measured in staff-spaces, so
631 this command moves the object 1 staff space to the right, and 2 spaces up.
633 @unnumberedsubsubsec Extents
635 todo -- write something about extents
637 @unnumberedsubsubsec Property alists
639 todo -- write something about property alists
641 @unnumberedsubsubsec Alist chains
643 todo -- write something about alist chains
645 @node Internal music representation
646 @subsection Internal music representation
648 When a music expression is parsed, it is converted into a set of
649 Scheme music objects. The defining property of a music object is that
650 it takes up time. Time is a rational number that measures the length
651 of a piece of music in whole notes.
653 A music object has three kinds of types:
656 music name: Each music expression has a name. For example, a note
657 leads to a @rinternals{NoteEvent}, and @code{\simultaneous} leads to
658 a @rinternals{SimultaneousMusic}. A list of all expressions
659 available is in the Internals Reference manual, under
660 @rinternals{Music expressions}.
663 @q{type} or interface: Each music name has several @q{types} or
664 interfaces, for example, a note is an @code{event}, but it is also a
665 @code{note-event}, a @code{rhythmic-event}, and a
666 @code{melodic-event}. All classes of music are listed in the
667 Internals Reference, under
668 @rinternals{Music classes}.
671 C++ object: Each music object is represented by an object of the C++
675 The actual information of a music expression is stored in properties.
676 For example, a @rinternals{NoteEvent} has @code{pitch} and
677 @code{duration} properties that store the pitch and duration of that
678 note. A list of all properties available can be found in the
679 Internals Reference, under @rinternals{Music properties}.
681 A compound music expression is a music object that contains other
682 music objects in its properties. A list of objects can be stored in
683 the @code{elements} property of a music object, or a single @q{child}
684 music object in the @code{element} property. For example,
685 @rinternals{SequentialMusic} has its children in @code{elements},
686 and @rinternals{GraceMusic} has its single argument in
687 @code{element}. The body of a repeat is stored in the @code{element}
688 property of @rinternals{RepeatedMusic}, and the alternatives in
691 @node Building complicated functions
692 @section Building complicated functions
694 This section explains how to gather the information necessary
695 to create complicated music functions.
698 * Displaying music expressions::
700 * Doubling a note with slurs (example)::
701 * Adding articulation to notes (example)::
705 @node Displaying music expressions
706 @subsection Displaying music expressions
708 @cindex internal storage
709 @cindex displaying music expressions
710 @cindex internal representation, displaying
712 @funindex \displayMusic
714 When writing a music function it is often instructive to inspect how
715 a music expression is stored internally. This can be done with the
716 music function @code{\displayMusic}
720 \displayMusic @{ c'4\f @}
737 (ly:make-duration 2 0 1 1)
739 (ly:make-pitch 0 0 0))
741 'AbsoluteDynamicEvent
746 By default, LilyPond will print these messages to the console along
747 with all the other messages. To split up these messages and save
748 the results of @code{\display@{STUFF@}}, redirect the output to
752 lilypond file.ly >display.txt
755 With a bit of reformatting, the above information is
759 (make-music 'SequentialMusic
760 'elements (list (make-music 'EventChord
761 'elements (list (make-music 'NoteEvent
762 'duration (ly:make-duration 2 0 1 1)
763 'pitch (ly:make-pitch 0 0 0))
764 (make-music 'AbsoluteDynamicEvent
768 A @code{@{ ... @}} music sequence has the name @code{SequentialMusic},
769 and its inner expressions are stored as a list in its @code{'elements}
770 property. A note is represented as an @code{EventChord} expression,
771 containing a @code{NoteEvent} object (storing the duration and
772 pitch properties) and any extra information (in this case, an
773 @code{AbsoluteDynamicEvent} with a @code{"f"} text property.
776 @node Music properties
777 @subsection Music properties
779 The @code{NoteEvent} object is the first object of the
780 @code{'elements} property of @code{someNote}.
784 \displayMusic \someNote
792 (ly:make-duration 2 0 1 1)
794 (ly:make-pitch 0 0 0))))
797 The @code{display-scheme-music} function is the function used by
798 @code{\displayMusic} to display the Scheme representation of a music
802 #(display-scheme-music (first (ly:music-property someNote 'elements)))
807 (ly:make-duration 2 0 1 1)
809 (ly:make-pitch 0 0 0))
812 Then the note pitch is accessed through the @code{'pitch} property
813 of the @code{NoteEvent} object,
816 #(display-scheme-music
817 (ly:music-property (first (ly:music-property someNote 'elements))
820 (ly:make-pitch 0 0 0)
823 The note pitch can be changed by setting this @code{'pitch} property,
825 @funindex \displayLilyMusic
828 #(set! (ly:music-property (first (ly:music-property someNote 'elements))
830 (ly:make-pitch 0 1 0)) ;; set the pitch to d'.
831 \displayLilyMusic \someNote
837 @node Doubling a note with slurs (example)
838 @subsection Doubling a note with slurs (example)
840 Suppose we want to create a function that translates input like
841 @code{a} into @code{a( a)}. We begin by examining the internal
842 representation of the desired result.
845 \displayMusic@{ a'( a') @}
856 (ly:make-duration 2 0 1 1)
858 (ly:make-pitch 0 5 0))
869 (ly:make-duration 2 0 1 1)
871 (ly:make-pitch 0 5 0))
878 The bad news is that the @code{SlurEvent} expressions
879 must be added @q{inside} the note (or more precisely,
880 inside the @code{EventChord} expression).
882 Now we examine the input,
894 (ly:make-duration 2 0 1 1)
896 (ly:make-pitch 0 5 0))))))
899 So in our function, we need to clone this expression (so that we
900 have two notes to build the sequence), add @code{SlurEvents} to the
901 @code{'elements} property of each one, and finally make a
902 @code{SequentialMusic} with the two @code{EventChords}.
905 doubleSlur = #(define-music-function (parser location note) (ly:music?)
906 "Return: @{ note ( note ) @}.
907 `note' is supposed to be an EventChord."
908 (let ((note2 (ly:music-deep-copy note)))
909 (set! (ly:music-property note 'elements)
910 (cons (make-music 'SlurEvent 'span-direction -1)
911 (ly:music-property note 'elements)))
912 (set! (ly:music-property note2 'elements)
913 (cons (make-music 'SlurEvent 'span-direction 1)
914 (ly:music-property note2 'elements)))
915 (make-music 'SequentialMusic 'elements (list note note2))))
919 @node Adding articulation to notes (example)
920 @subsection Adding articulation to notes (example)
922 The easy way to add articulation to notes is to merge two music
923 expressions into one context, as explained in
924 @ruser{Creating contexts}. However, suppose that we want to write
925 a music function that does this.
927 A @code{$variable} inside the @code{#@{...#@}} notation is like
928 a regular @code{\variable} in classical LilyPond notation. We
936 will not work in LilyPond. We could avoid this problem by attaching
937 the articulation to a fake note,
940 @{ << \music s1*0-.-> @}
944 but for the sake of this example, we will learn how to do this in
945 Scheme. We begin by examining our input and desired output,
957 (ly:make-duration 2 0 1 1)
959 (ly:make-pitch -1 0 0))))
970 (ly:make-duration 2 0 1 1)
972 (ly:make-pitch -1 0 0))
979 We see that a note (@code{c4}) is represented as an @code{EventChord}
980 expression, with a @code{NoteEvent} expression in its elements list. To
981 add a marcato articulation, an @code{ArticulationEvent} expression must
982 be added to the elements property of the @code{EventChord}
985 To build this function, we begin with
988 (define (add-marcato event-chord)
989 "Add a marcato ArticulationEvent to the elements of `event-chord',
990 which is supposed to be an EventChord expression."
991 (let ((result-event-chord (ly:music-deep-copy event-chord)))
992 (set! (ly:music-property result-event-chord 'elements)
993 (cons (make-music 'ArticulationEvent
994 'articulation-type "marcato")
995 (ly:music-property result-event-chord 'elements)))
999 The first line is the way to define a function in Scheme: the function
1000 name is @code{add-marcato}, and has one variable called
1001 @code{event-chord}. In Scheme, the type of variable is often clear
1002 from its name. (this is good practice in other programming languages,
1010 is a description of what the function does. This is not strictly
1011 necessary, but just like clear variable names, it is good practice.
1014 (let ((result-event-chord (ly:music-deep-copy event-chord)))
1017 @code{let} is used to declare local variables. Here we use one local
1018 variable, named @code{result-event-chord}, to which we give the value
1019 @code{(ly:music-deep-copy event-chord)}. @code{ly:music-deep-copy} is
1020 a function specific to LilyPond, like all functions prefixed by
1021 @code{ly:}. It is use to make a copy of a music
1022 expression. Here we copy @code{event-chord} (the parameter of the
1023 function). Recall that our purpose is to add a marcato to an
1024 @code{EventChord} expression. It is better to not modify the
1025 @code{EventChord} which was given as an argument, because it may be
1028 Now we have a @code{result-event-chord}, which is a
1029 @code{NoteEventChord} expression and is a copy of
1030 @code{event-chord}. We add the marcato to its @code{'elements}
1034 (set! place new-value)
1037 Here, what we want to set (the @q{place}) is the @code{'elements}
1038 property of @code{result-event-chord} expression.
1041 (ly:music-property result-event-chord 'elements)
1044 @code{ly:music-property} is the function used to access music properties
1045 (the @code{'elements}, @code{'duration}, @code{'pitch}, etc, that we
1046 see in the @code{\displayMusic} output above). The new value is the
1047 former @code{'elements} property, with an extra item: the
1048 @code{ArticulationEvent} expression, which we copy from the
1049 @code{\displayMusic} output,
1052 (cons (make-music 'ArticulationEvent
1053 'articulation-type "marcato")
1054 (ly:music-property result-event-chord 'elements))
1057 @code{cons} is used to add an element to a list without modifying
1058 the original list. This is what we want: the same list as before,
1059 plus the new @code{ArticulationEvent} expression. The order
1060 inside the @code{'elements} property is not important here.
1062 Finally, once we have added the marcato articulation to its @code{elements}
1063 property, we can return @code{result-event-chord}, hence the last line of
1066 Now we transform the @code{add-marcato} function into a music
1070 addMarcato = #(define-music-function (parser location event-chord)
1072 "Add a marcato ArticulationEvent to the elements of `event-chord',
1073 which is supposed to be an EventChord expression."
1074 (let ((result-event-chord (ly:music-deep-copy event-chord)))
1075 (set! (ly:music-property result-event-chord 'elements)
1076 (cons (make-music 'ArticulationEvent
1077 'articulation-type "marcato")
1078 (ly:music-property result-event-chord 'elements)))
1079 result-event-chord))
1082 We may verify that this music function works correctly,
1085 \displayMusic \addMarcato c4
1095 * Tweaking with Scheme::
1098 @c @node Tweaking with Scheme
1099 @c @section Tweaking with Scheme
1101 We have seen how LilyPond output can be heavily modified using
1103 @code{\override TextScript #'extra-offset = ( 1 . -1)}. But
1104 we have even more power if we use Scheme. For a full explanation
1105 of this, see the @ref{Scheme tutorial}, and
1106 @ref{Interfaces for programmers}.
1108 We can use Scheme to simply @code{\override} commands,
1110 TODO Find a simple example
1111 @c This isn't a valid example with skylining
1112 @c It works fine without padText -td
1116 @lilypond[quote,verbatim,ragged-right]
1117 padText = #(define-music-function (parser location padding) (number?)
1119 \once \override TextScript #'padding = #$padding
1123 c4^"piu mosso" b a b
1125 c4^"piu mosso" d e f
1127 c4^"piu mosso" fis a g
1133 We can use it to create new commands:
1135 @c Check this is a valid example with skylining
1136 @c It is - 'padding still works
1139 @lilypond[quote,verbatim,ragged-right]
1140 tempoPadded = #(define-music-function (parser location padding tempotext)
1143 \once \override Score.MetronomeMark #'padding = $padding
1144 \tempo \markup { \bold $tempotext }
1148 \tempo \markup { "Low tempo" }
1150 \tempoPadded #4.0 #"High tempo"
1156 Even music expressions can be passed in:
1158 @lilypond[quote,verbatim,ragged-right]
1159 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
1166 \pattern {d16 dis} { ais16-> b\p }