]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/input.itely
Merge branch 'original' into HEAD
[lilypond.git] / Documentation / user / input.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @node Input syntax
11 @chapter Input syntax
12
13 This section deals with general lilypond input syntax issues,
14 rather than specific notation.
15
16 FIXME: don't complain about anything in this chapter.  It's still
17 under heavy development.
18
19 FIXME: add comments
20 @verbatim
21 % %{
22 @end verbatim
23 to 3.1.
24
25 @menu
26 * Input files::                 
27 * Common syntax issues TODO name?::  
28 * Other stuffs TODO move?::     
29 @end menu
30
31
32 @node Input files
33 @section Input files
34
35 The main format of input for LilyPond are text files.  By convention,
36 these files end with @code{.ly}.
37
38 @menu
39 * File structure::              
40 * A single music expression::   
41 * Multiple scores in a book::   
42 * Extracting fragments of notation::  
43 * Including LilyPond files::    
44 * Text encoding::               
45 * Different editions from one source::  
46 @end menu
47
48
49 @node File structure
50 @subsection File structure
51
52 A @code{.ly} file contains any number of toplevel expressions, where a
53 toplevel expression is one of the following
54
55 @itemize
56 @item
57 An output definition, such as @code{\paper}, @code{\midi}, and
58 @code{\layout}.  Such a definition at the toplevel changes the default
59 settings for the block entered.
60
61 @item
62 A direct scheme expression, such as
63 @code{#(set-default-paper-size "a7" 'landscape)} or
64 @code{#(ly:set-option 'point-and-click #f)}.
65
66 @item
67 A @code{\header} block.  This sets the global header block.  This
68 is the block containing the definitions for book-wide settings, like
69 composer, title, etc.
70
71 @item
72 A @code{\score} block.  This score will be collected with other
73 toplevel scores, and combined as a single @code{\book}.
74
75 This behavior can be changed by setting the variable
76 @code{toplevel-score-handler} at toplevel.  The default handler is
77 defined in the init file @file{scm/@/lily@/.scm}.
78
79 The @code{\score} must begin with a music expression, and may
80 contain only one music expression.
81
82 @item
83 A @code{\book} block logically combines multiple movements
84 (i.e., multiple @code{\score} blocks) in one document.  If there are
85 a number of @code{\scores}, one output file will be created for
86 each @code{\book} block, in which all corresponding movements are
87 concatenated.  The only reason to explicitly specify @code{\book} blocks
88 in a @code{.ly} file is if you wish multiple output files from a single
89 input file.  One exception is within lilypond-book documents, where you
90 explicitly have to add a @code{\book} block if you want more than a
91 single @code{\score} or @code{\markup} in the same example.
92
93 This behavior can be changed by setting the variable
94 @code{toplevel-book-handler} at toplevel.  The default handler is
95 defined in the init file @file{scm/@/lily@/.scm}.
96
97 @item
98 A compound music expression, such as
99 @example
100 @{ c'4 d' e'2 @}
101 @end example
102
103 This will add the piece in a @code{\score} and format it in a
104 single book together with all other toplevel @code{\score}s and music
105 expressions.  In other words, a file containing only the above
106 music expression will be translated into
107
108 @example
109 \book @{
110   \score @{
111     \new Staff @{
112       \new Voice @{
113         @{ c'4 d' e'2 @}
114       @}
115     @}
116   @}
117         \layout @{ @}
118         \header @{ @}
119 @}
120 @end example
121
122 This behavior can be changed by setting the variable
123 @code{toplevel-music-handler} at toplevel.  The default handler is
124 defined in the init file @file{scm/@/lily@/.scm}.
125
126 @item
127 A markup text, a verse for example
128 @example
129 \markup @{
130    2.  The first line verse two.
131 @}
132 @end example
133
134 Markup texts are rendered above, between or below the scores or music
135 expressions, wherever they appear.
136
137 @cindex variables
138
139 @item
140 An variable, such as
141 @example
142 foo = @{ c4 d e d @}
143 @end example
144
145 This can be used later on in the file by entering @code{\foo}.  The
146 name of an variable should have alphabetic characters only; no
147 numbers, underscores or dashes.
148
149 @end itemize
150
151 The following example shows three things that may be entered at
152 toplevel
153
154 @example
155 \layout @{
156   % movements are non-justified by default
157   ragged-right = ##t
158 @}
159
160 \header @{
161    title = "Do-re-mi"
162 @}
163
164 @{ c'4 d' e2 @}
165 @end example
166
167
168 At any point in a file, any of the following lexical instructions can
169 be entered:
170
171 @itemize
172 @item @code{\version}
173 @item @code{\include}
174 @item @code{\sourcefilename}
175 @item @code{\sourcefileline}
176
177 @end itemize
178
179
180 @node A single music expression
181 @subsection A single music expression
182
183 A @code{\score} must contain a single music expression.  However,
184 this music expression may be of any size.  Recall that music
185 expressions may be included inside other expressions to form
186 larger expressions.  All of these examples are single music
187 expressions; note the curly braces @{ @} or angle brackets <<
188 >> at the beginning and ending of the music.
189
190 @example
191 @{ c'4 c' c' c' @}
192 @end example
193
194 @lilypond[ragged-right,verbatim,quote]
195 {
196   { c'4 c' c' c'}
197   { d'4 d' d' d'}
198 }
199 @end lilypond
200
201 @lilypond[ragged-right,verbatim,quote]
202 <<
203   \new Staff { c'4 c' c' c' }
204   \new Staff { d'4 d' d' d' }
205 >>
206 @end lilypond
207
208 @example
209 @{
210   \new GrandStaff <<
211     \new StaffGroup <<
212       \new Staff @{ \flute @}
213       \new Staff @{ \oboe @}
214     >>
215     \new StaffGroup <<
216       \new Staff @{ \violinI @}
217       \new Staff @{ \violinII @}
218     >>
219   >>
220 @}
221 @end example
222
223
224 @node Multiple scores in a book
225 @subsection Multiple scores in a book
226
227 @funindex \book
228 @cindex movements, multiple
229
230 A document may contain multiple pieces of music and texts.  Examples
231 of these are an etude book, or an orchestral part with multiple
232 movements.  Each movement is entered with a @code{\score} block,
233
234 @example
235 \score @{
236   @var{..music..}
237 @}
238 @end example
239
240 and texts are entered with a @code{\markup} block,
241
242 @example
243 \markup @{
244   @var{..text..}
245 @}
246 @end example
247
248 @funindex \book
249
250 All the movements and texts which appear in the same @code{.ly} file 
251 will normally be typeset in the form of a single output file. 
252
253 @example
254 \score @{
255   @var{..}
256 @}
257 \markup @{
258   @var{..}
259 @}
260 \score @{
261   @var{..}
262 @}
263 @end example
264
265 However, if you want multiple output files from the same @code{.ly}
266 file, then you can add multiple @code{\book} blocks, where each such
267 @code{\book} block will result in a separate output.  If you do not
268 specify any @code{\book} block in the file, LilyPond will implicitly
269 treat the full file as a single @code{\book} block, see @ref{File
270 structure}.  One important exception is within lilypond-book documents,
271 where you explicitly have to add a @code{\book} block, otherwise only
272 the first @code{\score} or @code{\markup} will appear in the output.
273
274 The header for each piece of music can be put inside the @code{\score}
275 block.  The @code{piece} name from the header will be printed before
276 each movement.  The title for the entire book can be put inside the
277 @code{\book}, but if it is not present, the @code{\header} which is at
278 the top of the file is inserted.
279
280 @example
281 \header @{
282   title = "Eight miniatures"
283   composer = "Igor Stravinsky"
284 @}
285 \score @{
286   @dots{}
287   \header @{ piece = "Romanze" @}
288 @}
289 \markup @{
290    ..text of second verse..
291 @}
292 \markup @{
293    ..text of third verse..
294 @}
295 \score @{
296   @dots{}
297   \header @{ piece = "Menuetto" @}
298 @}
299 @end example
300
301 @node Extracting fragments of notation
302 @subsection Extracting fragments of notation
303
304 It is possible to quote small fragments of a large score directly from
305 the output.  This can be compared to clipping a piece of a paper score
306 with scissors.
307
308 This is done by definining the measures that need to be cut out
309 separately.  For example, including the following definition
310
311
312 @verbatim
313 \layout {
314   clip-regions
315   = #(list
316       (cons
317        (make-rhythmic-location 5 1 2)
318        (make-rhythmic-location 7 3 4)))
319 }       
320 @end verbatim
321
322 @noindent
323 will extract a fragment starting halfway the fifth measure, ending in
324 the seventh measure.  The meaning of @code{5 1 2} is: after a 1/2 note
325 in measure 5, and @code{7 3 4} after 3 quarter notes in measure 7.
326
327 More clip regions can be defined by adding more pairs of
328 rhythmic-locations to the list. 
329
330 In order to use this feature, LilyPond must be invoked with
331 @code{-dclip-systems}.  The clips are output as EPS files, and are
332 converted to PDF and PNG if these formats are switched on as well.
333
334 For more information on output formats, see @rprogram{Invoking lilypond}.
335
336 @seealso
337
338 Examples: @c @lsr{non-notation,clip-systems.ly}
339
340
341 @node Including LilyPond files
342 @subsection Including LilyPond files
343
344 @funindex \include
345 @cindex including files
346
347 A large project may be split up into separate files.  To refer to another
348 file, use
349
350 @example
351 \include "otherfile.ly"
352 @end example
353
354 The line @code{\include "file.ly"} is equivalent to pasting the contents
355 of file.ly into the current file at the place where you have the
356 \include.  For example, for a large project you might write separate files
357 for each instrument part and create a @q{full score} file which brings
358 together the individual instrument files.
359
360 The initialization of LilyPond is done in a number of files that are
361 included by default when you start the program, normally transparent to the
362 user.  Run lilypond --verbose to see a list of paths and files that Lily
363 finds.
364
365 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
366 VERSION is in the form @q{2.6.1}) are on the path and available to
367 @code{\include}.  Files in the
368 current working directory are available to \include, but a file of the same
369 name in LilyPond's installation takes precedence.  Files are
370 available to \include from directories in the search path specified as an
371 option when invoking @code{lilypond --include=DIR} which adds DIR to the
372 search path.
373
374 The @code{\include} statement can use full path information, but with the Unix
375 convention @code{/} rather than the DOS/Windows @code{\}.  For example,
376 if @file{stuff.ly} is located one directory higher than the current working
377 directory, use
378
379 @example
380 \include "../stuff.ly"
381 @end example
382
383
384 @node Text encoding
385 @subsection Text encoding
386
387 LilyPond uses the Pango library to format multi-lingual texts, and
388 does not perform any input-encoding conversions.  This means that any
389 text, be it title, lyric text, or musical instruction containing
390 non-ASCII characters, must be utf-8.  The easiest way to enter such text is
391 by using a Unicode-aware editor and saving the file with utf-8 encoding.  Most
392 popular modern editors have utf-8 support, for example, vim, Emacs,
393 jEdit, and GEdit do.
394
395 @c  Currently not working
396 @ignore
397 Depending on the fonts installed, the following fragment shows Hebrew
398 and Cyrillic lyrics,
399
400 @cindex Cyrillic
401 @cindex Hebrew
402 @cindex ASCII, non
403
404 @li lypondfile[fontload]{utf-8.ly}
405
406 The @TeX{} backend does not handle encoding specially at all.  Strings
407 in the input are put in the output as-is.  Extents of text items in the
408 @TeX{} backend, are determined by reading a file created via the
409 @file{texstr} backend,
410
411 @example
412 lilypond -dbackend=texstr input/les-nereides.ly
413 latex les-nereides.texstr
414 @end example
415
416 The last command produces @file{les-nereides.textmetrics}, which is
417 read when you execute
418
419 @example
420 lilypond -dbackend=tex input/les-nereides.ly
421 @end example
422
423 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
424 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
425 interpreting non-ASCII strings.
426
427 @end ignore
428
429 To use a Unicode escape sequence, use
430
431 @example
432 #(ly:export (ly:wide-char->utf-8 #x2014))
433 @end example
434
435
436 @seealso
437
438 @c @lsr{text,utf-8.ly}
439
440
441 @node Different editions from one source
442 @subsection Different editions from one source
443
444 @funindex \tag
445 @cindex tag
446
447 The @code{\tag} command marks music expressions with a name.  These
448 tagged expressions can be filtered out later.  With this mechanism it
449 is possible to make different versions of the same music source.
450
451 In the following example, we see two versions of a piece of music, one
452 for the full score, and one with cue notes for the instrumental part
453
454 @example
455 c1
456 <<
457   \tag #'part <<
458     R1 \\
459     @{
460       \set fontSize = #-1
461       c4_"cue" f2 g4 @}
462   >>
463   \tag #'score R1
464 >>
465 c1
466 @end example
467
468 The same can be applied to articulations, texts, etc.: they are
469 made by prepending
470 @example
471 -\tag #@var{your-tag}
472 @end example
473 to an articulation, for example,
474 @example
475 c1-\tag #'part ^4
476 @end example
477
478 This defines a note with a conditional fingering indication.
479
480 @cindex keepWithTag
481 @cindex removeWithTag
482 By applying the @code{\keepWithTag} and @code{\removeWithTag}
483 commands, tagged expressions can be filtered.  For example,
484 @example
485 <<
486   @var{the music}
487   \keepWithTag #'score @var{the music}
488   \keepWithTag #'part @var{the music}
489 >>
490 @end example
491 would yield
492
493 @lilypondfile[ragged-right,quote]{tag-filter.ly}
494
495 The arguments of the @code{\tag} command should be a symbol
496 (such as @code{#'score} or @code{#'part}), followed by a
497 music expression.  It is possible to put multiple tags on
498 a piece of music with multiple @code{\tag} entries,
499
500 @example
501   \tag #'original-part \tag #'transposed-part @dots{}
502 @end example
503
504
505 @seealso
506
507 Examples: @c @lsr{parts,tag@/-filter@/.ly}
508
509
510 @knownissues
511
512 Multiple rests are not merged if you create the score with both tagged
513 sections.
514
515
516 @node Common syntax issues TODO name?
517 @section Common syntax issues TODO name?
518
519 @menu
520 * Controlling direction and placement::  
521 * Distances and measurements MAYBE MOVE::  
522 * When to add a -::             
523 @end menu
524
525 @node Controlling direction and placement
526 @subsection Controlling direction and placement
527
528 TODO: everything
529
530 By default, lilypnod does a pretty jazz'n job of picking
531 directions.  But in some cases, it may be desirable to force a
532 direction.
533
534 @verbatim
535 -
536 ^ _
537 @end verbatim
538
539 Also cover
540 #UP
541 #DOWN
542 #LEFT
543 #RIGHT.
544
545 Maybe rename section to "directions".
546
547 Also mention \override Foo #'direction = #'DOWN.
548
549 also mention the typical \fooDown, \fooNeutral predefined commands.
550
551 also mention that some directions are (without other tweaking)
552 always up or always down (like dynamics or fermata), while other
553 things can alternate between up or down based on the stem direction
554 (like slurs or accents).
555
556
557 @node Distances and measurements MAYBE MOVE
558 @subsection Distances and measurements MAYBE MOVE
559
560 DISCUSS after working on other sections.
561
562 TODO: staff spaces, #UP #DOWN #LEFT #RIGHT.  Maybe move into tweaks?
563
564
565 @node When to add a -
566 @subsection When to add a -
567
568 One of these works, the other doesn't.
569
570 @verbatim
571 \version "2.11.38"
572 { c'\mp\fermata\accent-\markup { "forcefully"} }
573 % { c'\mp\fermata\accent\markup { "forcefully"} }
574 @end verbatim
575
576
577 @node Other stuffs TODO move?
578 @section Other stuffs TODO move?
579
580
581 @menu
582 * Displaying LilyPond notation::  
583 * Skipping corrected music::    
584 * context list FIXME::          
585 * another thing FIXME::         
586 * Input modes FIXME::           
587 @end menu
588
589 @node Displaying LilyPond notation
590 @subsection Displaying LilyPond notation
591
592 @funindex \displayLilyMusic
593 Displaying a music expression in LilyPond notation can be
594 done using the music function @code{\displayLilyMusic}.  For example,
595
596 @example
597 @{
598   \displayLilyMusic \transpose c a, @{ c e g a bes @}
599 @}
600 @end example
601
602 will display
603
604 @example
605 @{ a, cis e fis g @}
606 @end example
607
608 By default, LilyPond will print these messages to the console along
609 with all the other messages.  To split up these messages and save
610 the results of @code{\display@{STUFF@}}, redirect the output to
611 a file.
612
613 @example
614 lilypond file.ly >display.txt
615 @end example
616
617
618 @node Skipping corrected music
619 @subsection Skipping corrected music
620
621
622 @funindex skipTypesetting
623 @funindex showLastLength
624
625 When entering or copying music, usually only the music near the end (where
626 you
627 are adding notes) is interesting to view and correct.  To speed up
628 this correction process, it is possible to skip typesetting of all but
629 the last few measures.  This is achieved by putting
630
631 @verbatim
632 showLastLength = R1*5
633 \score { ... }
634 @end verbatim
635
636 @noindent
637 in your source file.  This will render only the last 5 measures
638 (assuming 4/4 time signature) of every @code{\score} in the input
639 file.  For longer pieces, rendering only a small part is often an order
640 of magnitude quicker than rendering it completely
641
642 Skipping parts of a score can be controlled in a more fine-grained
643 fashion with the property @code{Score.skipTypesetting}.  When it is
644 set, no typesetting is performed at all.
645
646 This property is also used to control output to the MIDI file.  Note that
647 it skips all events, including tempo and instrument changes.  You have
648 been warned.
649
650 @lilypond[quote,fragment,ragged-right,verbatim]
651 \relative c'' {
652   c8 d
653   \set Score.skipTypesetting = ##t
654   e e e e e e e e
655   \set Score.skipTypesetting = ##f
656   c d b bes a g c2 }
657 @end lilypond
658
659 In polyphonic music, @code{Score.skipTypesetting} will affect all
660 voices and staves, saving even more time.
661
662
663 @node context list FIXME
664 @subsection context list FIXME
665
666 >> > > - list of contexts: my *danger unmaintainable* 
667 >> > > alarm just went off.  I'm 
668
669 I knew it would... And leaving out some of them is perfectly fine
670 with me.
671 I do think that a list like this, with the main contexts and a
672 brief
673 description of  what they do (perhaps also with a note about what
674 default
675 behaviour is associated with each of them, but this may be
676 unmanageable),
677 should be there, and then we could simply list the remaining ones
678 without
679 further explanation and with links to the IR.
680
681
682 The Master Of All Contexts
683 ==========================
684
685     * Score
686         This is the top level notation context. No other context
687 can
688         contain a Score context. This context handles the
689         administration of time signatures. It also makes sure that
690         items such as clefs, time signatures, and key-signatures
691 are
692         aligned across staves.
693         You cannot explicitly instantiate a Score context (since
694 it is
695         not contained in any other context). It is instantiated
696         automatically when an output definition (a \score or
697 \layout
698         block) is processed. 
699         (it should also be made clear somewhere what the
700 difference is between
701         \score and \Score).
702
703 Top-level contexts: Staff containers
704 ====================================
705     * StaffGroup
706         Groups staves while adding a bracket on the left side,
707         grouping the staves together. The bar lines of the
708 contained
709         staves are connected vertically. StaffGroup only consists
710 of a
711         collection of staves, with a bracket in front and spanning
712 bar
713         lines.
714     * ChoirStaff
715         Identical to StaffGroup except that the contained staves
716 are
717         not connected vertically.
718     * GrandStaff
719         A group of staves, with a brace on the left side, grouping
720 the
721         staves together. The bar lines of the contained staves are
722         connected vertically.
723     * PianoStaff
724         Just like GrandStaff but with a forced distance between
725 the
726         staves, so cross staff beaming and slurring can be used.
727     * DrumStaff
728         Handles typesetting for percussion. Can contain DrumVoice
729     * InnerStaffGroup
730     * InnerChoirStaff
731
732 Staff-level contexts
733 ====================
734     * Staff
735         Handles clefs, bar lines, keys, accidentals. It can
736 contain
737         Voice contexts.
738     * RhythmicStaff
739         Like Staff but for printing rhythms. Pitches are
740         ignored; the notes are printed on one line.
741     * TabStaff
742         Context for generating tablature. By default lays the
743 music
744         expression out as a guitar tablature, printed on six
745 lines.
746     * VaticanaStaff
747         Same as Staff, except that it is accommodated for
748         typesetting a piece in gregorian style. 
749     * MensuralStaff
750         Same as Staff, except that it is accommodated for
751         typesetting a piece in mensural style. 
752
753 Voice-level (bottom) contexts
754 =============================
755 What is generated by default here?  The voice-level contexts
756 initiate
757 certain properties and start engravers. 
758
759     * Voice 
760         Corresponds to a voice on a staff. This context handles
761 the
762         conversion of dynamic signs, stems, beams, super- and
763         subscripts, slurs, ties, and rests.
764         You have to instantiate this explicitly if you want to
765 have
766         multiple voices on the same staff. 
767         Bottom context.
768     * VaticanaVoice
769         Same as Voice, except that it is accommodated for
770         typesetting a piece in gregorian style.  
771     * MensuralVoice
772         Same as Voice, except that it is accommodated for
773         typesetting a piece in mensural style. 
774     * Lyrics
775         Corresponds to a voice with lyrics. Handles the printing
776 of a
777         single line of lyrics.
778         Bottom context.
779     * DrumVoice
780         A voice on a percussion staff.
781     * FiguredBass
782          
783     * ChordNames
784         Typesets chord names.  This context is a `bottom' context;
785 it
786         cannot contain other contexts.
787
788 ------------------------------
789 Then the following, which I don't know what to do with:
790
791     * TabVoice
792     * GregorianTranscriptionVoice
793     * GregorianTranscriptionStaff
794
795     * FretBoards
796         Engraves fretboards from chords. Not easy... Not
797 documented.
798     * NoteNames
799
800     * CueVoice Not documented
801     * Global
802         Hard coded entry point for LilyPond. Cannot be tuned.
803     * Devnull
804         Silently discards all musical information given to this
805 context.
806
807
808 @node another thing FIXME
809 @subsection another thing FIXME
810
811 Another thing that is needed, is an overview of the various naming
812 conventions: 
813
814     scheme functions: lowercase-with-hyphens (incl. one-word
815 names)
816     scheme functions: ly:plus-scheme-style
817     music events, music classes and music properties:
818 as-scheme-functions
819     Grob interfaces: scheme-style
820     backend properties: scheme-style (but X and Y!)
821     contexts (and MusicExpressions and grobs): Capitalized or
822 CamelCase
823     context properties: lowercaseFollowedByCamelCase
824     engravers:
825 Capitalized_followed_by_lowercase_and_with_underscores
826
827 Which of these are conventions and which are rules?
828 Which are rules of the underlying language, and which are
829 LP-specific?
830
831
832 @node Input modes FIXME
833 @subsection Input modes FIXME
834
835 \notemode
836
837 \notemode turns the front end of LilyPond into note mode
838 (which is the default parsing mode).
839 It's certainly useful in certain situations, for example if you
840 are in \lyricmode or \chordmode or ... and want to insert
841 something that only can be done with \notemode syntax.
842
843 See for example
844 http://lists.gnu.org/archive/html/lilypond-user/2007-03/msg00418.html
845 http://lists.gnu.org/archive/html/lilypond-user/2007-03/msg00218.html
846 http://lists.gnu.org/archive/html/lilypond-user/2006-12/msg00236.html
847 http://lists.gnu.org/archive/html/lilypond-user/2006-11/msg00061.html
848
849
850 \chords
851 \drums
852 \fretmode ?
853
854
855
856