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