]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/internals.itely
doc fixes, rune pats
[lilypond.git] / Documentation / user / internals.itely
1 @c -*-texinfo-*-
2 @c Note:
3 @c
4 @c A menu is needed before every deeper *section nesting of @nodes
5 @c Run M-x texinfo-all-menus-update
6 @c to automagically fill in these menus
7 @c before saving changes
8
9
10 @node Advanced Topics
11 @chapter Advanced Topics
12
13
14 When translating the input to notation, there are number of distinct
15 phases.  We list them here:
16
17 @c todo: moved from refman. 
18
19 The purpose of LilyPond is explained informally by the term `music
20 typesetter'.  This is not a fully correct name: not only does the
21 program print musical symbols, it also makes aesthetic decisions.
22 Symbols and their placements are @emph{generated} from a high-level
23 musical description.  In other words, LilyPond would be best described
24 by `music compiler' or `music to notation compiler'.
25
26 LilyPond is linked to GUILE, GNU's Scheme library for extension
27 programming. The Scheme library provides the glue that holds together
28 the low-level routines and separate modules which are written in C++.
29
30 When lilypond is run to typeset sheet music, the following happens:
31 @itemize @bullet
32 @item GUILE Initialization: various scheme files are read
33 @item parsing: first standard @code{ly} initialization  files are read, and
34 then the user @file{ly} file is read.
35 @item interpretation: the music in the file is processed ``in playing
36 order'', i.e. the order that  you  use to read sheet music, or the
37 order in which notes are played. The result of this step is a typesetting
38 specification.
39
40 @item typesetting:
41 The typesetting specification is solved: positions and formatting is
42 calculated.
43
44 @item the visible results ("virtual ink") are written to the output file.
45 @end itemize
46
47 During these stages different types of data play the the main role:
48 during parsing, @strong{Music} objects are created.  During the
49 interpretation, @strong{contexts} are constructed, and with these
50 contexts a network of @strong{graphical objects} (``grobs'') is
51 created. These grobs contain unknown variables, and the network forms a
52 set of equations. After solving the equations and filling in these
53 variables, the printed output is written to an output file.
54
55 These threemanship of tasks (parsing, translating, typesetting) and
56 data-structures (music, context, graphical objects) permeates the entire
57 design of the program.
58
59
60
61 @table @b
62
63 @item Parsing:
64
65 The LY file is read, and converted to a list of @code{Scores}, which
66 each contain @code{Music} and paper/midi-definitions. Here @code{Music},
67 @code{Pitch} and @code{Duration}  objects are created.
68
69 @item Interpreting music
70 @cindex interpreting music
71
72 All music events are "read" in the same order as they would be played
73 (or read from paper). At every step of the interpretation, musical
74 events are delivered to
75 interpretation contexts,
76 @cindex engraver
77 which use them to build @code{Grob}s (or MIDI objects, for MIDI output).
78
79 In this stage @code{Music_iterators} do a traversal of the @code{Music}
80 structure. The music events thus encountered are reported to
81 @code{Translator}s, a set of objects that collectively form interpretation
82 contexts.
83
84
85 @item Prebreaking
86
87 @cindex prebreaking
88
89 At places where line breaks may occur, clefs and bars are prepared for
90 a possible line break. 
91
92 @item Preprocessing
93
94 @cindex preprocessing
95
96 In this stage, all information that is needed to determine line breaking
97 is computed. 
98
99 @item Break calculation:
100
101 The lines and horizontal positions of the columns are determined.
102
103 @item Breaking
104
105 Relations between all grobs are modified to reflect line breaks: When a
106 spanner, e.g. a slur, crosses a line-break, then the spanner is "broken
107 into pieces", for every line that the spanner is in, a copy of the grob
108 is made. A substitution process redirects all grob-reference so that
109 each spanner grob will only reference other grobs in the same line.
110
111 @item Outputting:
112
113 All vertical dimensions and spanning objects are computed, and all grobs
114 are output, line by line. The output is encoded in the form of
115 @code{Molecule}s
116
117 @end table
118
119 The data types that are mentioned here are all discussed in this
120 section.
121
122
123
124 @c FIXME: Note entry vs Music entry at top level menu is confusing.
125 @c . {Music entry}
126 @menu
127 * Interpretation context::      
128 * Syntactic details::           
129 * Lexical details::             
130 @end menu
131
132 @node Interpretation context
133 @section Interpretation context
134
135 @menu
136 * Creating contexts::           
137 * Default contexts::            
138 * Context properties::          
139 * Engravers and performers::    
140 * Changing context definitions::  
141 * Defining new contexts::       
142 @end menu
143
144
145 Interpretation contexts are objects that only exist during a run of
146 LilyPond.  During the interpretation phase of LilyPond (when it prints
147 "interpreting music"), the music expression in a @code{\score} block is
148 interpreted in time order. This is the same order that humans hear and
149 play the music.
150
151 During this interpretation, the interpretation context holds the
152 state for the current point within the music. It contains information
153 like
154
155 @itemize @bullet
156   @item What notes are playing at this point?
157   @item What symbols will be printed at this point?
158   @item What is the current key signature, time signature, point within
159        the measure, etc.?
160 @end itemize
161
162 Contexts are grouped hierarchically: A @internalsref{Voice} context is
163 contained in a @internalsref{Staff} context (because a staff can contain
164 multiple voices at any point), a @internalsref{Staff} context is contained in
165 @internalsref{Score}, @internalsref{StaffGroup}, or @internalsref{ChoirStaff} context.
166
167 Contexts associated with sheet music output are called @emph{notation
168 contexts}, those for sound output are called @emph{performance
169 contexts}. The default definitions of the standard notation and
170 performance contexts can be found in @file{ly/engraver-init.ly} and
171 @file{ly/performer-init.ly}, respectively.
172
173 @node Creating contexts
174 @subsection Creating contexts
175
176 @cindex @code{\context}
177 @cindex context selection
178
179 Contexts for a music expression can be selected manually, using the
180 following music expression.
181
182 @example
183   \context @var{contexttype} [= @var{contextname}] @var{musicexpr}
184 @end example
185
186 This instructs lilypond to interpret @var{musicexpr} within the context
187  of type @var{contexttype} and with name @var{contextname}.  If this
188 context does not exist, it will be created.  
189
190 @lilypond[verbatim,singleline]
191 \score {
192   \notes \relative c'' {
193     c4 <d4 \context Staff = "another" e4> f
194   }
195 }
196
197 @end lilypond
198
199 In this example, the @code{c} and @code{d} are printed on the
200 default staff.  For the @code{e}, a context Staff called
201 @code{another} is specified; since that does not exist, a new
202 context is created.  Within @code{another}, a (default) Voice context
203 is created for the @code{e4}.  When all music referring to a
204 context is finished, the context is ended as well.  So after the
205 third quarter, @code{another} is removed.
206
207
208
209 @node Default contexts
210 @subsection Default contexts
211
212 Most music expressions don't need an explicit @code{\context}
213 declaration: they inherit the 
214 notation context from their parent. Each note is a music expression, and
215 as you can see in the following example, only the sequential music
216 enclosing the three notes has an explicit context. 
217
218 @lilypond[verbatim,singleline]
219 \score { \notes \context Voice = goUp { c'4 d' e' } } 
220 @end lilypond
221
222 There are some quirks that you must keep in mind when dealing with
223 defaults:
224
225 First, every top level music is interpreted by the Score context, in other
226 words, you may think of @code{\score} working like
227 @example
228         \score @{
229                 \context Score @var{music}
230         @}
231 @end example
232
233 Second, contexts are created automatically to be able to interpret the
234 music expressions. Consider the following example.
235
236 @lilypond[verbatim, singleline]
237 \score { \context Score \notes { c'4 (  d' )e' } }
238 @end lilypond
239
240 The sequential music is interpreted by the Score context initially
241 (notice that the @code{\context} specification is redundant), but when a
242 note is encountered, contexts are setup to accept that note. In this
243 case, a Thread, Voice and Staff are created. The rest of the sequential
244 music is also interpreted with the same Thread, Voice and Staff context,
245 putting the notes on the same staff, in the same voice.
246
247 This is a convenient mechanism, but do not expect opening chords to work
248 without @code{\context}. For every note, a separate staff is
249 instantiated.
250
251 @cindex explicit context
252 @cindex starting with chords
253 @cindex chords, starting with
254
255 @lilypond[verbatim, singleline]
256 \score { \notes <c'4 es'> } 
257 @end lilypond
258
259 Of course, if the chord is preceded by a normal note in sequential
260 music, the chord will be interpreted by the Thread of the preceding
261 note:
262 @lilypond[verbatim,singleline]
263 \score { \notes { c'4 <c'4 es'> }  }
264 @end lilypond
265
266
267
268 @node Context properties
269 @subsection Context properties
270
271 Notation contexts have properties. These properties are from
272 the @file{.ly} file using the following  expression:
273 @cindex @code{\property}
274 @example
275   \property @var{contextname}.@var{propname} =  @var{value}
276 @end example
277
278 Sets the @var{propname} property of the context @var{contextname} to the
279 specified Scheme expression @var{value}.  All @var{propname} and
280 @var{contextname} are strings, which are typically unquoted.
281
282 Properties that are set in one context are inherited by all of the
283 contained contexts.  This means that a property valid for the
284 @internalsref{Voice} context can be set in the @internalsref{Score} context (for
285 example) and thus take effect in all @internalsref{Voice} contexts.
286
287 Properties can be unset using the following expression:
288 @example
289   \property @var{contextname}.@var{propname} \unset
290 @end example
291
292 @cindex properties, unsetting
293 @cindex @code{\unset} 
294
295 This removes the definition of @var{propname} in @var{contextname}. If
296 @var{propname} was not defined in @var{contextname} (but was inherited
297 from a higher context), then this has no effect.
298
299
300 @refbugs
301
302 The syntax of @code{\unset} is asymmetric: @code{\property \unset} is not
303 the inverse of @code{\property \set}.
304
305 @node Engravers and performers
306 @subsection Engravers and performers
307
308 [TODO]
309
310 Basic building blocks of translation are called engravers; they are
311 special C++ classes.
312
313
314
315 @node Changing context definitions
316 @subsection Changing context definitions
317
318 @cindex context definition
319 @cindex translator definition
320
321 The most common way to define a context is by extending an existing
322 context.  You can change an existing context from the paper block, by
323 first initializing a translator with an existing context identifier:
324 @example
325 \paper @{
326   \translator @{
327     @var{context-identifier}
328   @} @}
329 @end example
330 Then you can add and remove engravers using the following syntax:
331 @example
332  \remove @var{engravername}
333  \consists @var{engravername}
334 @end example
335
336
337 Here @var{engravername} is a string, the name of an engraver in the
338 system.
339
340
341 @lilypond[verbatim,singleline]
342 \score {  \notes {
343         c'4 c'4 }
344   \paper {
345     \translator  { \StaffContext
346         \remove Clef_engraver
347        } } }
348 @end lilypond
349
350 @cindex engraver
351
352 You can also set properties in a translator definition. The syntax is as
353 follows:
354 @example
355  @var{propname} = @var{value}
356  @var{propname} \set  @var{grob-propname} = @var{pvalue}
357  @var{propname} \override @var{grob-propname} =  @var{pvalue}
358  @var{propname} \revert @var{grob-propname} 
359 @end example
360 @var{propname} is a string, @var{grob-propname} a symbol, @var{value}
361 and @code{pvalue} are Scheme expressions. These type of property
362 assignments happen before interpretation starts, so a @code{\property}
363 command will override any predefined settings.
364
365
366  To simplify editing translators, all standard contexts have standard
367 identifiers called @var{name}@code{Context}, e.g. @code{StaffContext},
368 @code{VoiceContext}, see @file{ly/engraver-init.ly}.
369
370 @node Defining new contexts
371 @subsection Defining new contexts
372
373 If you want to build a context from scratch, you must also supply the
374 following extra information:
375 @itemize @bullet
376   @item  A name, specified by @code{\name @var{contextname}}.
377
378   @item A cooperation module. This is specified by   @code{\type
379 @var{typename}}.
380 @end itemize
381
382 This is an example:
383 @example
384 \translator @code{
385   \type "Engraver_group_engraver"
386   \name "SimpleStaff"
387   \alias "Staff"
388   \consists "Staff_symbol_engraver"
389   \consists "Note_head_engraver"
390   \consistsend "Axis_group_engraver"
391 }@
392 @end example
393
394 The argument of @code{\type} is the name for a special engraver that
395 handles cooperation between simple engravers such as
396 @code{Note_head_engraver} and @code{Staff_symbol_engraver}. Alternatives
397 for this engraver are the following:
398 @table @code
399 @cindex @code{Engraver_group_engraver}
400   @item @code{Engraver_group_engraver}  
401     The standard cooperation engraver.
402
403 @cindex @code{Score_engraver}
404
405   @item @code{Score_engraver}  
406     This is cooperation module that should be in the top level context,
407 and only the top level context.
408
409 @end table 
410
411 Other modifiers   are
412
413 @itemize @bullet
414   @item @code{\alias} @var{alternate-name}
415     This specifies a different name. In the above example,
416 @code{\property Staff.X = Y} will also work on @code{SimpleStaff}s
417
418   @item  @code{\consistsend} @var{engravername} 
419     Analogous to @code{\consists}, but makes sure that
420     @var{engravername} is always added to the end of the list of
421     engravers.
422
423     Some engraver types need to be at the end of the list; this
424     insures they stay there even if a user adds or removes engravers.
425 End-users generally don't need this command.
426     
427   @item  @code{\accepts} @var{contextname}
428     Add @var{contextname} to the list of contexts this context can
429     contain in the context hierarchy. The first listed context is the
430     context to create by default.
431
432   @item @code{\denies}. The opposite of @code{\accepts}. Added for
433 completeness, but is never used in practice.
434  
435   
436   @item  @code{\name} @var{contextname} 
437     This sets the type name of the context, e.g. @internalsref{Staff},
438     @internalsref{Voice}.  If the name is not specified, the translator won't do
439     anything. 
440 @end itemize
441
442 In the @code{\paper} block, it is also possible to define translator
443 identifiers.  Like other block identifiers, the identifier can only
444 be used as the very first item of a translator.  In order to define
445 such an identifier outside of @code{\score}, you must do
446
447 @quotation
448 @example 
449 \paper @{
450   foo = \translator @{ @dots{} @}
451 @}
452 \score @{
453   \notes @{
454     @dots{}
455   @}
456   \paper @{
457     \translator @{ \foo @dots{} @}
458   @}
459 @} 
460 @end example 
461
462 @end quotation
463
464
465 @cindex paper types, engravers, and pre-defined translators
466
467       
468 @node Syntactic details
469 @section Syntactic details
470 @cindex Syntactic details
471
472 This section describes details that were too boring to be put elsewhere.
473
474 @menu
475 * Identifiers::                 
476 * Music expressions::           
477 * Manipulating music expressions::  
478 * Span requests::               
479 * Assignments::                 
480 * Lexical modes::               
481 * Ambiguities::                 
482 @end menu
483
484 @c .  {Identifiers}
485 @node Identifiers
486 @subsection Identifiers
487 @cindex  Identifiers
488
489 @ignore
490  What has this section got to do with identifiers?
491  It seems more appropriate in the introduction to Chapter 4,
492  "Internals".
493
494    /MB
495 @end ignore
496
497 All of the information in a LilyPond input file, is internally
498 represented as a Scheme value. In addition to normal Scheme data types
499 (such as pair, number, boolean, etc.), LilyPond has a number of
500 specialized data types,
501
502 @itemize @bullet
503 @item Input
504 @item c++-function
505 @item Music
506 @item Identifier
507 @item Translator_def
508 @item Duration
509 @item Pitch
510 @item Score
511 @item Music_output_def
512 @item Moment (rational number)
513 @end itemize
514
515 LilyPond also includes some transient object types. Objects of these
516 types are built during a LilyPond run, and do not `exist' per se within
517 your input file. These objects are created as a result of your input
518 file, so you can include commands in the input to manipulate them,
519 during a lilypond run.
520
521 @itemize @bullet
522 @item Grob: short for Graphical object. 
523 @item Molecule: device-independent page output object,
524 including dimensions.  Produced by some Grob functions
525 @item Translator: object that produces audio objects or Grobs. This is
526 not yet user accessible.
527 @item Font_metric: object representing a font.
528 @end itemize
529
530
531 @node Music expressions
532 @subsection Music expressions
533
534 @cindex music expressions
535
536 Music in LilyPond is entered as a music expression.  Notes, rests, lyric
537 syllables are music expressions, and you can combine music expressions
538 to form new ones, for example by enclosing a list of expressions in
539 @code{\sequential @{ @}} or @code{< >}.  In the following example, a
540 compound expression is formed out of the quarter note @code{c} and a
541 quarter note @code{d}:
542
543 @example 
544 \sequential @{ c4 d4 @} 
545 @end example 
546
547 @cindex Sequential music
548 @cindex @code{\sequential}
549 @cindex sequential music
550 @cindex @code{<}
551 @cindex @code{>}
552 @cindex Simultaneous music
553 @cindex @code{\simultaneous}
554
555 The two basic compound  music expressions are simultaneous  and
556 sequential music.
557
558 @example
559   \sequential @code{@{} @var{musicexprlist} @code{@}}
560   \simultaneous @code{@{} @var{musicexprlist} @code{@}}
561 @end example
562 For both, there is a shorthand:
563 @example
564   @code{@{} @var{musicexprlist} @code{@}}
565 @end example
566 for sequential and
567 @example
568   @code{<} @var{musicexprlist} @code{>}
569 @end example
570 for simultaneous music.
571 In principle, the way in which you nest sequential and simultaneous to
572 produce music is not relevant.  In the following example, three chords
573 are expressed in two different ways:
574
575 @lilypond[fragment,verbatim,center]
576   \notes \context Voice {
577     <a c'> <b  d' > <c' e'>
578     < { a b  c' } { c' d' e' } >
579   }
580 @end lilypond
581
582
583 Other compound music expressions include
584 @example
585  \repeat @var{expr}
586  \transpose @var{pitch} @var{expr}
587  \apply @var{func} @var{expr}
588  \context @var{type} = @var{id} @var{expr}
589  \times @var{fraction} @var{expr}
590 @end example
591
592
593 @c . {Manipulating music expressions}
594 @node Manipulating music expressions
595 @subsection  Manipulating music expressions
596
597 The @code{\apply} mechanism gives you access to the internal
598 representation of music. You can write Scheme-functions that operate
599 directly on it. The syntax is 
600 @example
601         \apply #@var{func} @var{music}
602 @end example
603 This means that @var{func} is applied to @var{music}.  The function
604 @var{func} should return a music expression.
605
606 This example replaces the text string of a script. It also shows a dump
607 of the music it processes, which is useful if you want to know more
608 about how music is stored.
609
610 @lilypond[verbatim,singleline]
611 #(define (testfunc x)
612         (if (equal? (ly-get-mus-property x 'text) "foo")
613                 (ly-set-mus-property x 'text "bar"))
614         ;; recurse
615         (ly-set-mus-property x 'elements
616           (map testfunc (ly-get-mus-property x 'elements)))
617         (display x)
618         x        
619 )
620 \score { \notes
621   \apply #testfunc { c'4_"foo" }
622
623 @end lilypond
624
625 For more information on what is possible, see the automatically
626 generated documentation.
627
628
629 Directly accessing internal representations is dangerous: the
630 implementation is subject to changes, so you should avoid this feature
631 if possible.
632
633 A final example is a function that reverses a piece of music in time:
634
635 @lilypond[verbatim,singleline]
636 #(define (reverse-music music)
637   (let* ((elements (ly-get-mus-property music 'elements))
638          (reversed (reverse elements))
639          (span-dir (ly-get-mus-property music 'span-direction)))
640     (ly-set-mus-property music 'elements reversed)
641     (if (dir? span-dir)
642         (ly-set-mus-property music 'span-direction (- span-dir)))
643     (map reverse-music reversed)
644     music))
645
646 music = \notes { c'4 d'4( e'4 f'4 }
647
648 \score { \context Voice {
649     \music
650     \apply #reverse-music \music
651   }
652 }
653 @end lilypond
654
655 More examples are given in the distributed example files in
656 @code{input/test/}.
657
658 @c .   {Span requests}
659 @menu
660 * Span requests::               
661 @end menu
662
663 @node Span requests
664 @subsection Span requests
665 @cindex Span requests
666
667 Notational constructs that start and end on different notes can be
668 entered using span requests. The syntax is as follows:
669
670
671 @example
672   \spanrequest @var{startstop} @var{type}
673 @end example
674
675
676 @cindex @code{\start}
677 @cindex @code{\stop}
678
679 This defines a spanning request. The @var{startstop} parameter is either
680 -1 (@code{\start}) or 1 (@code{\stop}) and @var{type} is a string that
681 describes what should be started.  Much of the syntactic sugar is a
682 shorthand for @code{\spanrequest}, for example,
683
684 @lilypond[fragment,verbatim,center]
685   c'4-\spanrequest \start "slur"
686   c'4-\spanrequest \stop "slur"
687 @end lilypond
688
689 Among the supported types are @code{crescendo}, @code{decrescendo},
690 @code{beam}, @code{slur}. This is an internal command.  Users are
691 encouraged to use the shorthands which are defined in the initialization
692 file @file{spanners.ly}.
693
694
695 @c .   {Assignments}
696 @node Assignments
697 @subsection Assignments
698 @cindex Assignments
699
700 Identifiers allow objects to be assigned to names during the parse
701 stage.  To assign an identifier, you use @var{name}@code{=}@var{value}
702 and to refer to an identifier, you precede its name with a backslash:
703 `@code{\}@var{name}'.  @var{value} is any valid Scheme value or any of
704 the input-types listed above.  Identifier assignments can appear at top
705 level in the LilyPond file, but also in @code{\paper} blocks.
706
707 An identifier can be created with any string for its name, but you will
708 only be able to refer to identifiers whose names begin with a letter,
709 being entirely alphabetical.  It is impossible to refer to an identifier
710 whose name is the same as the name of a keyword.
711
712 The right hand side of an identifier assignment is parsed completely
713 before the assignment is done, so it is allowed to redefine an
714 identifier in terms of its old value, e.g.
715
716 @example
717 foo = \foo * 2.0
718 @end example
719
720 When an identifier is referenced, the information it points to is
721 copied.  For this reason, an identifier reference must always be the
722 first item in a block.
723 @example
724 \paper  @{
725   foo = 1.0
726   \paperIdent % wrong and invalid
727 @}
728
729 \paper @{
730   \paperIdent % correct
731   foo = 1.0 @}
732 @end example
733
734
735 @c .  {Lexical modes}
736 @node Lexical modes
737 @subsection Lexical modes
738 @cindex Lexical modes
739 @cindex input mode
740 @cindex mode, input 
741 @cindex @code{\notes}
742 @cindex @code{\chords}
743 @cindex @code{\lyrics}
744
745 To simplify entering notes, lyrics, and chords, LilyPond has three
746 special input modes in addition to the default mode: note, lyrics and
747 chords mode.  These input modes change the way that normal, unquoted
748 words are interpreted: for example, the word @code{cis} may be
749 interpreted as a C-sharp, as a lyric syllable `cis' or as a C-sharp
750 major triad respectively.
751
752 A mode switch is entered as a compound music expression
753 @example
754 @code{\notes} @var{musicexpr}
755 @code{\chords} @var{musicexpr}
756 @code{\lyrics} @var{musicexpr}.
757 @end example
758
759 In each of these cases, these expressions do not add anything to the
760 meaning of their arguments.  They just instruct the parser in what mode
761 to parse their arguments.
762
763 Different input modes may be nested.
764
765 @c .  {Ambiguities}
766 @node Ambiguities
767 @subsection Ambiguities
768 @cindex ambiguities
769 @cindex grammar
770
771
772 The grammar contains a number of ambiguities. We hope to resolve them at
773 some time.
774
775 @itemize @bullet
776   @item  The assignment
777
778 @example 
779 foo = bar 
780 @end example 
781          is interpreted as the string identifier assignment. However,
782 it can also be interpreted as making a string identifier @code{\foo}
783 containing @code{"bar"}, or a music identifier @code{\foo} containing
784 the syllable `bar'.  The former interpretation is chosen.
785
786   @item  If you do a nested repeat like
787
788        @quotation
789
790 @example 
791 \repeat @dots{}
792 \repeat @dots{}
793 \alternative 
794 @end example 
795
796        @end quotation
797
798        then it is ambiguous to which @code{\repeat} the
799        @code{\alternative} belongs.  This is the classic if-then-else
800        dilemma.  It may be solved by using braces.
801
802 @end itemize
803
804 @c .  {Lexical details}
805 @node Lexical details
806 @section Lexical details
807
808 Even more boring details, now on lexical side of the input parser.
809
810 @menu
811 * Direct Scheme::               
812 * Reals::                       
813 * Strings::                     
814 @end menu
815
816
817 @node Direct Scheme
818 @subsection Direct Scheme
819
820 @cindex Scheme
821 @cindex GUILE
822 @cindex Scheme, in-line code
823
824
825
826 @cindex GUILE
827 @cindex Scheme
828 @cindex accessing Scheme
829 @cindex evaluating Scheme
830 @cindex LISP
831
832 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
833 language from the LISP family. You can learn more about Scheme at
834 @uref{http://www.scheme.org}. It is used to represent data throughout
835 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
836 code following the hash-sign is evaluated as Scheme.  The boolean value
837 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
838 @code{##t}.
839
840 LilyPond contains a Scheme interpreter (the GUILE library) for
841 internal use. In some places, Scheme expressions also form valid syntax:
842 wherever it is allowed,
843 @example
844   #@var{scheme}
845 @end example
846 evaluates the specified Scheme code.  Example:
847 @example
848   \property Staff.TestObject \override #'foobar =  #(+ 1 2)
849 @end example
850 @code{\override} expects two Scheme expressions, so there are two Scheme
851 expressions. The first one is a symbol (@code{foobar}), the second one
852 an integer (namely, 3).
853
854 In-line scheme may be used at the top level. In this case the result is
855 discarded.
856
857 Scheme is a full-blown programming language, and a full discussion is
858 outside the scope of this document. Interested readers are referred to
859 the website @uref{http://www.schemers.org/} for more information on
860 Scheme.
861
862
863 @node Reals
864 @subsection Reals
865 @cindex real numbers
866
867 Formed from an optional minus sign and a sequence of digits followed
868 by a @emph{required} decimal point and an optional exponent such as
869 @code{-1.2e3}.  Reals can be built up using the usual operations:
870 `@code{+}', `@code{-}', `@code{*}', and
871 `@code{/}', with parentheses for grouping.
872
873 @cindex @code{\mm},
874 @cindex @code{\in}
875 @cindex @code{\cm}
876 @cindex @code{\pt}
877 @cindex dimensions
878
879 A real constant can be followed by one of the dimension keywords:
880 @code{\mm} @code{\pt}, @code{\in}, or @code{\cm}, for millimeters,
881 points, inches and centimeters, respectively.  This converts the number
882 a number that is the internal representation of that dimension.
883
884
885 @node Strings
886 @subsection Strings
887 @cindex string
888 @cindex concatenate
889
890 Begins and ends with the @code{"} character.  To include a @code{"}
891 character in a string write @code{\"}.  Various other backslash
892 sequences have special interpretations as in the C language.  A string
893 that contains no spaces can be written without the quotes.  Strings can
894 be concatenated with the @code{+} operator.
895