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