]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/internals.itely
* mf/parmesan-custodes.mf (dir_down): remove _ from glyph names.
[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 Technical manual
11 @chapter Technical manual
12
13
14 When LilyPond is run, it reads an input file which is parsed.  During
15 parsing, Music objects are created. This music is interpreted, which
16 is done by contexts, that produce graphical objects.  This section
17 discusses details of these three concepts, and how they are glued
18 together with the embedded Scheme interpreter.
19
20 @menu
21 * Interpretation context::      
22 * Scheme integration::          
23 * Music storage format::        
24 * Lexical details::             
25 * Output details::              
26 @end menu
27
28
29 @node Interpretation context
30 @section Interpretation context
31
32 @menu
33 * Creating contexts::           
34 * Default contexts::            
35 * Context properties::          
36 * Context evaluation::          
37 * Defining contexts::           
38 * Engravers and performers::    
39 * Defining new contexts::       
40 @end menu
41
42
43 Interpretation contexts are objects that only exist during program
44 run.  During the interpretation phase (when @code{interpreting music}
45 is printed on the standard output), the music expression in a
46 @code{\score} block is interpreted in time order, the same order in
47 which we hear and play the music.  During this phase, the interpretation
48 context holds the state for the current point within the music, for
49 example
50 @itemize @bullet
51 @item What notes are playing at this point?
52
53 @item What symbols will be printed at this point?
54
55 @item What is the current key signature, time signature, point within
56 the measure, etc.?
57 @end itemize
58
59 Contexts are grouped hierarchically: A @internalsref{Voice} context is
60 contained in a @internalsref{Staff} context (because a staff can contain
61 multiple voices at any point), a @internalsref{Staff} context is contained in
62 @internalsref{Score}, @internalsref{StaffGroup}, or
63 @internalsref{ChoirStaff} context.
64
65 Contexts associated with sheet music output are called @emph{notation
66 contexts}, those for sound output are called @emph{performance
67 contexts}.  The default definitions of the standard notation and
68 performance contexts can be found in @file{ly/engraver-init.ly} and
69 @file{ly/performer-init.ly}, respectively.
70
71
72 @node Creating contexts
73 @subsection Creating contexts
74 @cindex @code{\context}
75 @cindex context selection
76
77 Contexts for a music expression can be selected manually, using the
78 following music expression.
79
80 @example
81 \context @var{contexttype} [= @var{contextname}] @var{musicexpr}
82 @end example
83
84 @noindent
85 This means that @var{musicexpr} should be interpreted within a context
86 of type @var{contexttype} (with name @var{contextname} if specified).
87 If no such context exists, it will be created.
88
89 @lilypond[verbatim,singleline]
90 \score {
91   \notes \relative c'' {
92     c4 <d4 \context Staff = "another" e4> f
93   }
94 }
95 @end lilypond
96
97 @noindent
98 In this example, the @code{c} and @code{d} are printed on the default
99 staff.  For the @code{e}, a context @code{Staff} called @code{another}
100 is specified; since that does not exist, a new context is created.
101 Within @code{another}, a (default) Voice context is created for the
102 @code{e4}.  A context is ended when when all music referring it has
103 finished, so after the third quarter, @code{another} is removed.
104
105
106 @node Default contexts
107 @subsection Default contexts
108
109 Every top level music is interpreted by the @code{Score} context; in
110 other words, you may think of @code{\score} working like
111
112 @example
113 \score @{
114   \context Score @var{music}
115 @}
116 @end example
117
118 Music expressions  inherit their context from the enclosing music
119 expression. Hence, it is not necessary to explicitly specify
120 @code{\context} for most expressions.  In
121 the following example, only the sequential expression has an explicit
122 context. The notes contained therein inherit the @code{goUp} context
123 from the enclosing music expression.
124
125 @lilypond[verbatim,singleline]
126   \notes \context Voice = goUp { c'4 d' e' }
127 @end lilypond
128
129
130 Second, contexts are created automatically to be able to interpret the
131 music expressions.  Consider the following example.
132
133 @lilypond[verbatim, singleline]
134   \score { \notes { c'4-( d' e'-) } }
135 @end lilypond
136
137 @noindent
138 The sequential music is interpreted by the Score context initially,
139 but when a note is encountered, contexts are setup to accept that
140 note.  In this case, a Thread, Voice, and Staff context are created.
141 The rest of the sequential music is also interpreted with the same
142 Thread, Voice, and Staff context, putting the notes on the same staff,
143 in the same voice.
144
145 @node Context properties
146 @subsection Context properties
147
148 Contexts have properties.  These properties are set from the @file{.ly}
149 file using the following expression:
150 @cindex @code{\property}
151 @cindex context properties
152 @cindex properties, context
153
154 @example
155 \property @var{contextname}.@var{propname} = @var{value}
156 @end example
157
158 @noindent
159 Sets the @var{propname} property of the context @var{contextname} to
160 the specified Scheme expression @var{value}.  Both @var{propname} and
161 @var{contextname} are strings, which can often be written unquoted.
162
163 @cindex inheriting
164 Properties that are set in one context are inherited by all of the
165 contained contexts.  This means that a property valid for the
166 @internalsref{Voice} context can be set in the @internalsref{Score} context
167 (for example) and thus take effect in all @internalsref{Voice} contexts.
168
169 @cindex @code{Current}
170 If you do not wish to specify the name of the context in the
171 @code{\property}-expression itself, you can refer to the abstract context
172 name, @code{Current}.  The @code{Current} context is the latest
173 used context.  This will typically mean the @internalsref{Thread}
174 context, but you can force another context with the
175 @code{\property}-command.  Hence the expressions
176
177 @example
178 \property @var{contextname}.@var{propname} = @var{value}
179 @end example
180
181 @noindent
182 and
183
184 @example
185 \context @var{contextname}
186 \property Current.@var{propname} = @var{value}
187 @end example
188
189 @noindent
190 do the same thing.  The main use for this is in predefined variables.
191 This construction allows the specification of a property-setting
192 without restriction to a specific context.
193
194 Properties can be unset using the following statement.
195 @example
196 \property @var{contextname}.@var{propname} \unset
197 @end example
198
199 @cindex properties, unsetting
200 @cindex @code{\unset} 
201
202 @noindent
203 This removes the definition of @var{propname} in @var{contextname}.  If
204 @var{propname} was not defined in @var{contextname} (but was inherited
205 from a higher context), then this has no effect.
206
207 @refbugs
208
209 The syntax of @code{\unset} is asymmetric: @code{\property \unset} is not
210 the inverse of @code{\property \set}.
211
212
213 @node Context evaluation
214 @subsection Context evaluation
215
216 Contexts can be modified during interpretation with Scheme code. The
217 syntax for this is
218 @example
219   \applycontext @var{function}
220 @end example
221
222 @var{function} should be a Scheme function taking a single argument,
223 being the context to apply it to. The following code will print the
224 current bar number on the standard output during the compile.
225
226 @example
227     \applycontext
228       #(lambda (x)
229          (format #t "\nWe were called in barnumber ~a.\n"
230           (ly:get-context-property x 'currentBarNumber)))
231 @end example
232
233
234
235 @node Defining contexts
236 @subsection Defining contexts
237
238 @cindex context definition
239 @cindex translator definition
240
241 The most common way to create a new context definition is by extending
242 an existing one.  An existing context from the paper block is copied
243 by referencing a context identifier:
244
245 @example
246 \paper @{
247   \translator @{
248     @var{context-identifier}
249   @}
250 @}
251 @end example
252
253 @noindent
254 Every predefined context has a standard identifier. For example, the
255 @code{Staff} context can be referred to as @code{\StaffContext}.
256
257 The context can then be modified by setting or changing properties,
258 e.g.
259 @example
260 \translator @{
261   \StaffContext
262   Stem \set #'thickness = #2.0
263   defaultBarType = #"||"
264 @}
265 @end example
266 These assignments happen before interpretation starts, so a @code{\property}
267 command will override any predefined settings.
268
269 @cindex engraver
270
271 @refbugs
272
273 It is not possible to collect multiple property assignments in a
274 variable, and apply to one @code{\translator} definition by
275 referencing that variable.
276
277 @node Engravers and performers
278 @subsection  Engravers and performers
279
280
281 Each context is composed of a number of building blocks, or plug-ins
282 called engravers.  An engraver is a specialized C++ class that is
283 compiled into the executable. Typically, an engraver is responsible
284 for one function: the @code{Slur_engraver} creates only @code{Slur}
285 objects, and the @code{Skip_event_swallow_translator} only swallows
286 (silently gobbles) @code{SkipEvent}s.
287
288
289
290 @cindex engraver
291 @cindex plug-in
292
293 An existing context definition can be changed by adding or removing an
294 engraver. The syntax for these operations is 
295 @example
296 \consists @var{engravername}
297 \remove @var{engravername}
298 @end example
299
300 @cindex \consists
301 @cindex \remove
302
303 @noindent
304 Here @var{engravername} is a string, the name of an engraver in the
305 system. In the following example, the @code{Clef_engraver} is removed
306 from the Staff context. The result is a staff without a clef, where
307 the central C is at its default position, the center line.
308
309 @lilypond[verbatim,singleline]
310 \score {
311   \notes {
312     c'4 f'4
313   }
314   \paper {
315     \translator {
316       \StaffContext
317       \remove Clef_engraver
318     }
319   }
320 }
321 @end lilypond
322
323 A list of all engravers is in the internal documentation,
324 see @internalsref{All engravers}.
325
326 @node Defining new contexts
327 @subsection Defining new contexts
328
329
330 It is also possible to define new contexts from scratch.  To do this,
331 you must define give the new context a name.  In the following
332 example, a very simple Staff context is created: one that will put
333 note heads on a staff symbol.
334
335 @example
336 \translator @code{
337   \type "Engraver_group_engraver"
338   \name "SimpleStaff"
339   \alias "Staff"
340   \consists "Staff_symbol_engraver"
341   \consists "Note_head_engraver"
342   \consistsend "Axis_group_engraver"
343 }@
344 @end example
345
346 @noindent
347 The argument of @code{\type} is the name for a special engraver that
348 handles cooperation between simple engravers such as
349 @code{Note_head_engraver} and @code{Staff_symbol_engraver}.  This
350 should always be  @code{Engraver_group_engraver} (unless you are
351 defining a Score context from scratch, in which case
352 @code{Score_engraver}   must be used).
353
354 The complete list of context  modifiers is as follows:
355 @itemize @bullet
356 @item @code{\alias} @var{alternate-name}:
357 This specifies a different name.  In the above example,
358 @code{\property Staff.X = Y} will also work on @code{SimpleStaff}s
359
360 @item @code{\consistsend} @var{engravername}:
361 Analogous to @code{\consists}, but makes sure that
362 @var{engravername} is always added to the end of the list of
363 engravers.
364
365 Engravers that group context objects into axis groups or alignments
366 need to be at the end of the list. @code{\consistsend} insures that
367 engravers stay at the end even if a user adds or removes engravers.
368     
369 @item @code{\accepts} @var{contextname}:
370 This context can contains @var{contextname} contexts.  The first
371 @code{\accepts} is created as a default context when events (eg. notes
372 or rests) are encountered.
373
374 @item @code{\denies}:
375 The opposite of @code{\accepts}.
376
377 @item @code{\name} @var{contextname}:
378 This sets the type name of the context, e.g. @code{Staff},
379 @code{Voice}.  If the name is not specified, the translator will not
380 do anything.
381 @end itemize
382
383
384 @node Scheme integration
385 @section Scheme integration
386
387 @cindex Scheme
388 @cindex GUILE
389 @cindex Scheme, in-line code
390 @cindex accessing Scheme
391 @cindex evaluating Scheme
392 @cindex LISP
393
394 LilyPond internally uses GUILE, a Scheme-interpreter, to represent
395 data throughout the whole program, and glue together different program
396 modules. For advanced usage, it is sometimes necessary to access and
397 program the Scheme interpreter.
398
399 Scheme is a full-blown programming language, from the LISP
400 family. and a full discussion is outside the scope of this document.
401 Interested readers are referred to the website
402 @uref{http://www.schemers.org/} for more information on Scheme.
403
404 The GUILE library for extension is documented at
405 @uref{http://www.gnu.org/software/guile}.
406 @ifinfo
407 When it is installed, the following link should take you to its manual
408 @ref{(guile.info)guile}
409 @end ifinfo
410
411 @menu
412 * Inline Scheme::               
413 * Input variables and Scheme::  
414 * Scheme datatypes::            
415 * Assignments::                 
416 @end menu
417
418 @node Inline Scheme
419 @subsection Inline Scheme
420
421 Scheme expressions can be entered in the input file by entering a
422 hash-sign (@code{#}).  The expression following the hash-sign is
423 evaluated as Scheme. For example, the boolean value @var{true} is
424 @code{#t} in Scheme, so for LilyPond @var{true} looks like @code{##t},
425 and can be used in property assignments:
426 @example
427   \property Staff.autoBeaming = ##f
428 @end example
429
430
431 @node Input variables and Scheme
432 @subsection Input variables and Scheme
433
434
435 The input format supports the notion of variable: in the following
436 example, a music expression is assigned to a variable with the name
437 @code{traLaLa}.
438 @example
439   traLaLa = \notes @{ c'4 d'4 @}
440 @end example
441
442 @noindent
443
444 There is also a form of scoping: in the following example, the
445 @code{\paper} block also contains a @code{traLaLa} variable, which is
446 independent of the outer @code{\traLaLa}.
447 @example
448   traLaLa = \notes @{ c'4 d'4 @}
449   \paper @{ traLaLa = 1.0 @}
450 @end example
451 @c
452 In effect, each input file is a scope, and all @code{\header},
453 @code{\midi} and @code{\paper} blocks are scopes nested inside that
454 toplevel scope.
455
456 Both variables and scoping are implemented in the GUILE module system.
457 An anonymous Scheme module is attached to each scope. An assignment of
458 the form
459 @example
460  traLaLa = \notes @{ c'4 d'4 @} 
461 @end example
462
463 @noindent
464 is internally converted to a Scheme definition
465 @example
466  (define traLaLa @var{Scheme value of ``@code{\notes ... }''})
467 @end example
468
469 This means that input variables and Scheme variables may be freely
470 mixed.  In the following example, a music fragment is stored in the
471 variable @code{traLaLa}, and duplicated using Scheme. The result is
472 imported in a @code{\score} by means of a second variable
473 @code{twice}
474 @example
475   traLaLa = \notes @{ c'4 d'4 @}
476   
477   #(define newLa (map ly:music-deep-copy
478     (list traLaLa traLaLa)))
479   #(define twice
480     (make-sequential-music newLa))
481
482   \score @{ \twice @}
483 @end example
484
485 In the above example, music expressions can be `exported' from the
486 input to the Scheme interpreter. The opposite is also possible. By
487 wrapping a Scheme value in the function @code{ly:export}, a Scheme
488 value is interpreted as if it were entered in LilyPond syntax: instead
489 of defining @code{\twice}, the example above could also have been
490 written as
491 @example
492   @dots{}
493   \score @{ #(ly:export (make-sequential-music newLa)) @}
494 @end example
495
496
497
498
499
500 @node Scheme datatypes
501 @subsection Scheme datatypes
502
503 Scheme is used to glue together different program modules. To aid this
504 glue function, many lilypond specific object types can be passed as
505 Scheme value. 
506
507 The following list are all lilypond specific types, that
508 can exist during parsing:
509 @table @code
510 @item Duration
511 @item Identifier
512 @item Input
513 @item Moment
514 @item Music
515 @item Music_output_def
516 @item Pitch
517 @item Score
518 @item Translator_def
519 @end table
520
521
522 During a run, transient objects are also created and destroyed.
523
524 @table @code
525 @item Grob: short for `Graphical object'.
526 @item Scheme_hash_table 
527 @item Music_iterator
528
529 @item Molecule: Device-independent page output object,
530 including dimensions.  
531
532 @item Syllable_group
533
534 @item Spring_smob
535
536 @item Translator: An object that produces audio objects or Grobs.  This is
537 not yet user-accessible.
538
539 @item Font_metric: An object representing a font.
540 @end table
541
542 Many functions are defined to manipulate these data structures. They
543 are all listed and documented in the internals manual, see
544 @internalsref{All scheme functions}.
545
546
547 @node Assignments
548 @subsection Assignments
549 @cindex Assignments
550
551 Variables allow objects to be assigned to names during the parse
552 stage.  To assign a variable, use
553 @example
554 @var{name}@code{=}@var{value}
555 @end example
556 To refer to a variable, precede its name with a backslash:
557 `@code{\}@var{name}'.  @var{value} is any valid Scheme value or any of
558 the input-types listed above.  Variable assignments can appear at top
559 level in the LilyPond file, but also in @code{\paper} blocks.
560
561 A variable can be created with any string for its name, but for
562 accessing it in the LilyPond syntax, its name must consist of
563 alphabetic characters only, and may not be a keyword of the syntax.
564 There are no restrictions for naming and accessing variables in the
565 Scheme interpreter,
566
567 The right hand side of a variable assignment is parsed completely
568 before the assignment is done, so variables may be  redefined in terms
569 of its old value, e.g.
570 @c
571 @example
572 foo = \foo * 2.0
573 @end example
574
575 When a variable is referenced in LilyPond syntax, the information it
576 points to is copied.  For this reason, an variable reference must
577 always be the first item in a block.
578
579 @example
580 \paper @{
581   foo = 1.0
582   \paperIdent % wrong and invalid
583 @}
584 @end example
585
586 @example
587 \paper @{
588   \paperIdent % correct
589   foo = 1.0
590 @}
591 @end example
592
593       
594
595 @node Music storage format
596 @section Music storage format
597
598 Music in LilyPond is entered as music expressions. This section
599 discusses different types of music expressions, and explains
600 information is stored internally. This internal storage is accessible
601 through the Scheme interpreter, so music expressions may be
602 manipulated using Scheme functions. 
603
604 @menu
605 * Music expressions::           
606 * Internal music representation::  
607 * Manipulating music expressions::  
608 @end menu
609
610 @node Music expressions
611 @subsection Music expressions
612 @cindex music expressions
613
614 Notes, rests, lyric syllables are music expressions.  Small music
615 expressions may be combined to form larger ones, for example by
616 enclosing a list of expressions in @code{\sequential @{ @}} or @code{<
617 >}.  In the following example, a compound expression is formed out of
618 the quarter note @code{c} and a quarter note @code{d}:
619
620 @example 
621 \sequential @{ c4 d4 @} 
622 @end example 
623
624 @cindex Sequential music
625 @cindex @code{\sequential}
626 @cindex sequential music
627 @cindex @code{<}
628 @cindex @code{>}
629 @cindex Simultaneous music
630 @cindex @code{\simultaneous}
631
632 The two basic compound music expressions are simultaneous and
633 sequential music.
634
635 @example
636 \sequential @code{@{} @var{musicexprlist} @code{@}}
637 \simultaneous @code{@{} @var{musicexprlist} @code{@}}
638 @end example
639
640 For both, there is a shorthand:
641
642 @example
643 @code{@{} @var{musicexprlist} @code{@}}
644 @end example
645
646 @noindent
647 for sequential and
648
649 @example
650 @code{<} @var{musicexprlist} @code{>}
651 @end example
652
653 @noindent
654 for simultaneous music.
655 In principle, the way in which you nest sequential and simultaneous to
656 produce music is not relevant.  In the following example, three chords
657 are expressed in two different ways:
658
659 @lilypond[fragment,verbatim,center,quote]
660 \notes \context Voice {
661   <a c'> <b d'> <c' e'>
662   < { a b c' } { c' d' e' } >
663 }
664 @end lilypond
665 However, using @code{<} and @code{>} for entering chords leads to
666 various peculiarities. For this reason, a special syntax
667 for chords was introduced in version 1.7: @code{<< >>}.
668
669
670
671
672
673 Other compound music expressions include
674 @example
675 \repeat @var{expr}
676 \transpose @var{from} @var{to} @var{expr}
677 \apply @var{func} @var{expr}
678 \context @var{type} = @var{id} @var{expr}
679 \times @var{fraction} @var{expr}
680 @end example
681
682 @node Internal music representation
683 @subsection Internal music representation
684
685
686
687
688
689
690 When a music expression is parsed, it is converted into a set of
691 Scheme music objects. The defining property of a music object is that
692 it takes up time. Time is a rational number that measures the length
693 of a piece of music, in whole notes.
694
695 A music object has three kinds of types
696 @itemize @bullet
697 @item
698   Music name: each music expression has a name, for example, a note
699 leads to a @internalsref{NoteEvent}, and @code{\simultaneous} leads to
700 a @internalsref{SimultaneousMusic}. A list of all expressions
701 available is in the internals manual, under @internalsref{Music
702 expressions}.
703
704 @item
705   Each music name has several `types' or interface. For example, a
706   note is an @code{event}, but it is also a @code{note-event}, a
707   @code{rhythmic-event} and a @code{melodic-event}.
708
709   All classes of music are listed in the internals manual, under
710   @internalsref{Music classes}. 
711 @item
712 Each music object is represented by a C++ object.  For technical
713 reasons, different music objects may be represented by different C++
714 object types. For example, a note is @code{Event} object, while
715 @code{\grace} creates a @code{Grace_music} object.
716
717 We expect that distinctions between different C++ types will disappear
718 in the future.
719 @end itemize
720
721 The actual information of a music expression is stored in properties.
722 For example, a @internalsref{NoteEvent} has @code{pitch} and
723 @code{duration} properties that store the pitch and duration of that
724 note.  A list of all properties available is in the internals manual,
725 under @internalsref{Music properties}.
726
727 A compound music expresssion is a music object that contains other
728 music objects in its properties. A list of objects can be stored in
729 the @code{elements} property of a music object, or a single `child'
730 music object is stored in the @code{element} object. For example,
731 @internalsref{SequentialMusic} has its children in @code{elements},
732 and @internalsref{GraceMusic} has its single argument in
733 @code{element}. The body of a repeat is in @code{element} property of
734 @internalsref{RepeatedMusic}, and the alternatives in @code{elements}.
735
736 @node Manipulating music expressions
737 @subsection Manipulating music expressions
738
739 Music objects and their properties can be accessed and manipulated
740 directly, through the @code{\apply} mechanism.  Scheme functions can
741 read and write properties using the functions
742 @code{ly:get-music-property} and @code{ly:set-music-property!}.
743
744 The syntax for @code{\apply} 
745 @example
746 \apply #@var{func} @var{music}
747 @end example
748
749 @noindent
750 This means that the scheme function @var{func} is called with
751 @var{music} as its argument.  The return value of @var{func} is the
752 result of the entire expresssion.
753
754 An example is a function that reverses the order of elements in
755 its argument:
756 @example
757   #(define (rev-music-1 m)
758      (ly:set-music-property! 'elements (reverse
759        (ly:get-music-property mus 'elements)))
760    )
761   \apply #rev-music-1 @{ c4 d4 @}
762 @end example
763
764 The use of such a function is very limited. The effect of this
765 function is void,  when it is applied to an argument which is does not
766 have multiple  children, for example
767
768 @example
769   \apply #rev-music-1 \grace @{ c4 d4 @}
770 @end example
771
772 @noindent
773 does not do anything: @code{\grace} is stored as
774 @internalsref{GraceMusic}, which has no @code{elements}, only a single
775 @code{element}. Every generally applicable function for @code{\apply}
776 must --like music expressions themselves-- be recursive.
777
778 The following example is such a recursive function: it first extracts
779 the @code{elements} of an expression, reverses them and puts them
780 back. Then it recurses, both on @code{elements} and @code{element}
781 children.
782 @example
783 #(define (reverse-music music)
784   (let* ((elements (ly:get-mus-property music 'elements))
785          (child (ly:get-mus-property music 'element))
786          (reversed (reverse elements)))
787
788     ; set children
789     (ly:set-mus-property! music 'elements reversed)
790
791     ; recurse
792     (if (ly:music? child) (reverse-music child))
793     (map reverse-music reversed)
794     
795     music))
796 @end example
797
798 A slightly more elaborate example is in
799 @inputfileref{input/test,reverse-music.ly}.
800
801 Some of the input syntax is also implemented as recursive music
802 functions. For example, the syntax for polyphony
803 @example
804   < a \\ b>
805 @end example
806
807 @noindent
808 is actually  implemented as a recursive function that replaces the
809 above by the internal equivalent of
810 @example
811   < \context Voice = "1" @{ \voiceOne a @}
812     \context Voice = "2" @{ \voiceTwo a @} >
813 @end example
814
815 Other applications of @code{\apply} are writing out repeats
816 automatically (@inputfileref{input/test,unfold-all-repeats.ly}),
817 saving keystrokes (@inputfileref{input/test,music-box.ly}) and
818 exporting
819 LilyPond input to other formats  (@inputfileref{input/test,to-xml.ly})
820
821 @seealso
822
823 @file{scm/music-functions.scm}, @file{scm/music-types.scm},
824 @inputfileref{input/test,add-staccato.ly},
825 @inputfileref{input/test,duration-check.ly}.
826 @inputfileref{input/test,unfold-all-repeats.ly},
827 @inputfileref{input/test,music-box.ly}.
828
829 @node Lexical details
830 @section Lexical details
831
832 @menu
833 * Strings::                     
834 @end menu
835
836 @node Strings
837 @subsection Strings
838 @cindex string
839 @cindex concatenate
840
841 Begins and ends with the @code{"} character.  To include a @code{"}
842 character in a string write @code{\"}.  Various other backslash
843 sequences have special interpretations as in the C language.  A string
844 that contains no spaces can be written without the quotes.  Strings can
845 be concatenated with the @code{+} operator.
846
847
848
849 @node Output details
850 @section Output details
851
852 LilyPond's default output format is @TeX{}.  Using the option @option{-f}
853 (or @option{--format}) other output formats can be selected also, but
854 currently none of them work reliably.
855
856 At the beginning of the output file, various global parameters are defined.
857 It also contains a large @code{\special} call to define PostScript routines
858 to draw items not representable with @TeX{}, mainly slurs and ties.  A DVI
859 driver must be able to understand such embedded PostScript, or the output
860 will be rendered incompletely.
861
862 Then the file @file{lilyponddefs.tex} is loaded to define the macros used
863 in the code which follows.  @file{lilyponddefs.tex} includes various other
864 files, partially depending on the global parameters.
865
866 Now the music is output system by system (a `system' consists of all
867 staves belonging together).  From @TeX{}'s point of view, a system is an
868 @code{\hbox} which contains a lowered @code{\vbox} so that it is centered
869 vertically on the baseline of the text.  Between systems,
870 @code{\interscoreline} is inserted vertically to have stretchable space.
871 The horizontal dimension of the @code{\hbox} is given by the
872 @code{linewidth} parameter from LilyPond's @code{\paper} block.
873
874
875 After the last system LilyPond emits a stronger variant of
876 @code{\interscoreline} only if the macro
877 @code{\lilypondpaperlastpagefill} is not defined (flushing the systems
878 to the top of the page).  You can avoid that by setting the variable
879 @code{lastpagefill} in LilyPond's @code{\paper} block.
880
881 It is possible to fine-tune the vertical offset further by defining the
882 macro @code{\lilypondscoreshift}.  Example:
883
884 @example
885 \def\lilypondscoreshift@{0.25\baselineskip@}
886 @end example
887
888 @noindent
889 @code{\baselineskip} is the distance from one text line to the next.
890
891 The code produced by LilyPond should be run through La@TeX{}, not
892 plain @TeX{}.
893
894 Here an example how to embed a small LilyPond file @code{foo.ly} into
895 running La@TeX{} text without using the @code{lilypond-book} script
896 (@pxref{lilypond-book manual}).
897
898 @example
899 \documentclass@{article@}
900
901 \def\lilypondpaperlastpagefill@{@}
902 \lineskip 5pt
903 \def\lilypondscoreshift@{0.25\baselineskip@}
904
905 \begin@{document@}
906 This is running text which includes an example music file
907 \input@{foo.tex@}
908 right here.
909 \end@{document@}
910 @end example
911
912 The file @file{foo.tex} has been simply produced with
913
914 @example
915 lilypond foo.ly
916 @end example
917
918 It is important to set the @code{indent} parameter to zero in the
919 @code{\paper} block of @file{foo.ly}.
920
921 The call to @code{\lineskip} assures that there is enough vertical space
922 between the LilyPond box and the surrounding text lines.
923
924 @c EOF