]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/input.itely
Merge branch 'master' into dev/jmandereau
[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
552 @node Distances and measurements MAYBE MOVE
553 @subsection Distances and measurements MAYBE MOVE
554
555 DISCUSS after working on other sections.
556
557 TODO: staff spaces, #UP #DOWN #LEFT #RIGHT.  Maybe move into tweaks?
558
559
560 @node When to add a -
561 @subsection When to add a -
562
563 One of these works, the other doesn't.
564
565 @verbatim
566 \version "2.11.38"
567 { c'\mp\fermata\accent-\markup { "forcefully"} }
568 % { c'\mp\fermata\accent\markup { "forcefully"} }
569 @end verbatim
570
571
572 @node Other stuffs TODO move?
573 @section Other stuffs TODO move?
574
575
576 @menu
577 * Displaying LilyPond notation::  
578 * Skipping corrected music::    
579 * context list FIXME::          
580 * another thing FIXME::         
581 * Input modes FIXME::           
582 @end menu
583
584 @node Displaying LilyPond notation
585 @subsection Displaying LilyPond notation
586
587 @funindex \displayLilyMusic
588 Displaying a music expression in LilyPond notation can be
589 done using the music function @code{\displayLilyMusic}.  For example,
590
591 @example
592 @{
593   \displayLilyMusic \transpose c a, @{ c e g a bes @}
594 @}
595 @end example
596
597 will display
598
599 @example
600 @{ a, cis e fis g @}
601 @end example
602
603 By default, LilyPond will print these messages to the console along
604 with all the other messages.  To split up these messages and save
605 the results of @code{\display@{STUFF@}}, redirect the output to
606 a file.
607
608 @example
609 lilypond file.ly >display.txt
610 @end example
611
612
613 @node Skipping corrected music
614 @subsection Skipping corrected music
615
616
617 @funindex skipTypesetting
618 @funindex showLastLength
619
620 When entering or copying music, usually only the music near the end (where
621 you
622 are adding notes) is interesting to view and correct.  To speed up
623 this correction process, it is possible to skip typesetting of all but
624 the last few measures.  This is achieved by putting
625
626 @verbatim
627 showLastLength = R1*5
628 \score { ... }
629 @end verbatim
630
631 @noindent
632 in your source file.  This will render only the last 5 measures
633 (assuming 4/4 time signature) of every @code{\score} in the input
634 file.  For longer pieces, rendering only a small part is often an order
635 of magnitude quicker than rendering it completely
636
637 Skipping parts of a score can be controlled in a more fine-grained
638 fashion with the property @code{Score.skipTypesetting}.  When it is
639 set, no typesetting is performed at all.
640
641 This property is also used to control output to the MIDI file.  Note that
642 it skips all events, including tempo and instrument changes.  You have
643 been warned.
644
645 @lilypond[quote,fragment,ragged-right,verbatim]
646 \relative c'' {
647   c8 d
648   \set Score.skipTypesetting = ##t
649   e e e e e e e e
650   \set Score.skipTypesetting = ##f
651   c d b bes a g c2 }
652 @end lilypond
653
654 In polyphonic music, @code{Score.skipTypesetting} will affect all
655 voices and staves, saving even more time.
656
657
658 @node context list FIXME
659 @subsection context list FIXME
660
661 >> > > - list of contexts: my *danger unmaintainable* 
662 >> > > alarm just went off.  I'm 
663
664 I knew it would... And leaving out some of them is perfectly fine
665 with me.
666 I do think that a list like this, with the main contexts and a
667 brief
668 description of  what they do (perhaps also with a note about what
669 default
670 behaviour is associated with each of them, but this may be
671 unmanageable),
672 should be there, and then we could simply list the remaining ones
673 without
674 further explanation and with links to the IR.
675
676
677 The Master Of All Contexts
678 ==========================
679
680     * Score
681         This is the top level notation context. No other context
682 can
683         contain a Score context. This context handles the
684         administration of time signatures. It also makes sure that
685         items such as clefs, time signatures, and key-signatures
686 are
687         aligned across staves.
688         You cannot explicitly instantiate a Score context (since
689 it is
690         not contained in any other context). It is instantiated
691         automatically when an output definition (a \score or
692 \layout
693         block) is processed. 
694         (it should also be made clear somewhere what the
695 difference is between
696         \score and \Score).
697
698 Top-level contexts: Staff containers
699 ====================================
700     * StaffGroup
701         Groups staves while adding a bracket on the left side,
702         grouping the staves together. The bar lines of the
703 contained
704         staves are connected vertically. StaffGroup only consists
705 of a
706         collection of staves, with a bracket in front and spanning
707 bar
708         lines.
709     * ChoirStaff
710         Identical to StaffGroup except that the contained staves
711 are
712         not connected vertically.
713     * GrandStaff
714         A group of staves, with a brace on the left side, grouping
715 the
716         staves together. The bar lines of the contained staves are
717         connected vertically.
718     * PianoStaff
719         Just like GrandStaff but with a forced distance between
720 the
721         staves, so cross staff beaming and slurring can be used.
722     * DrumStaff
723         Handles typesetting for percussion. Can contain DrumVoice
724     * InnerStaffGroup
725     * InnerChoirStaff
726
727 Staff-level contexts
728 ====================
729     * Staff
730         Handles clefs, bar lines, keys, accidentals. It can
731 contain
732         Voice contexts.
733     * RhythmicStaff
734         Like Staff but for printing rhythms. Pitches are
735         ignored; the notes are printed on one line.
736     * TabStaff
737         Context for generating tablature. By default lays the
738 music
739         expression out as a guitar tablature, printed on six
740 lines.
741     * VaticanaStaff
742         Same as Staff, except that it is accommodated for
743         typesetting a piece in gregorian style. 
744     * MensuralStaff
745         Same as Staff, except that it is accommodated for
746         typesetting a piece in mensural style. 
747
748 Voice-level (bottom) contexts
749 =============================
750 What is generated by default here?  The voice-level contexts
751 initiate
752 certain properties and start engravers. 
753
754     * Voice 
755         Corresponds to a voice on a staff. This context handles
756 the
757         conversion of dynamic signs, stems, beams, super- and
758         subscripts, slurs, ties, and rests.
759         You have to instantiate this explicitly if you want to
760 have
761         multiple voices on the same staff. 
762         Bottom context.
763     * VaticanaVoice
764         Same as Voice, except that it is accommodated for
765         typesetting a piece in gregorian style.  
766     * MensuralVoice
767         Same as Voice, except that it is accommodated for
768         typesetting a piece in mensural style. 
769     * Lyrics
770         Corresponds to a voice with lyrics. Handles the printing
771 of a
772         single line of lyrics.
773         Bottom context.
774     * DrumVoice
775         A voice on a percussion staff.
776     * FiguredBass
777          
778     * ChordNames
779         Typesets chord names.  This context is a `bottom' context;
780 it
781         cannot contain other contexts.
782
783 ------------------------------
784 Then the following, which I don't know what to do with:
785
786     * TabVoice
787     * GregorianTranscriptionVoice
788     * GregorianTranscriptionStaff
789
790     * FretBoards
791         Engraves fretboards from chords. Not easy... Not
792 documented.
793     * NoteNames
794
795     * CueVoice Not documented
796     * Global
797         Hard coded entry point for LilyPond. Cannot be tuned.
798     * Devnull
799         Silently discards all musical information given to this
800 context.
801
802
803 @node another thing FIXME
804 @subsection another thing FIXME
805
806 Another thing that is needed, is an overview of the various naming
807 conventions: 
808
809     scheme functions: lowercase-with-hyphens (incl. one-word
810 names)
811     scheme functions: ly:plus-scheme-style
812     music events, music classes and music properties:
813 as-scheme-functions
814     Grob interfaces: scheme-style
815     backend properties: scheme-style (but X and Y!)
816     contexts (and MusicExpressions and grobs): Capitalized or
817 CamelCase
818     context properties: lowercaseFollowedByCamelCase
819     engravers:
820 Capitalized_followed_by_lowercase_and_with_underscores
821
822 Which of these are conventions and which are rules?
823 Which are rules of the underlying language, and which are
824 LP-specific?
825
826
827 @node Input modes FIXME
828 @subsection Input modes FIXME
829
830 \notemode
831
832 \notemode turns the front end of LilyPond into note mode
833 (which is the default parsing mode).
834 It's certainly useful in certain situations, for example if you
835 are in \lyricmode or \chordmode or ... and want to insert
836 something that only can be done with \notemode syntax.
837
838 See for example
839 http://lists.gnu.org/archive/html/lilypond-user/2007-03/msg00418.html
840 http://lists.gnu.org/archive/html/lilypond-user/2007-03/msg00218.html
841 http://lists.gnu.org/archive/html/lilypond-user/2006-12/msg00236.html
842 http://lists.gnu.org/archive/html/lilypond-user/2006-11/msg00061.html
843
844
845 \chords
846 \drums
847 \fretmode ?
848
849
850
851