]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/input.itely
59d5d23b61cceb26ae07a0bda00b50fa7ba047cc
[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 @menu
17 * Input files::                 
18 * Common syntax issues TODO name?::  
19 * Other stuffs TODO move?::     
20 @end menu
21
22
23 @node Input files
24 @section Input files
25
26 The main format of input for LilyPond are text files.  By convention,
27 these files end with @samp{.ly}.
28
29 @menu
30 * File structure::              
31 * A single music expression::   
32 * Multiple scores in a book::   
33 * Extracting fragments of notation::  
34 * Including LilyPond files::    
35 * Text encoding::               
36 * Different editions from one source::  
37 @end menu
38
39
40 @node File structure
41 @subsection File structure
42
43 A @code{.ly} file contains any number of toplevel expressions, where a
44 toplevel expression is one of the following
45
46 @itemize
47 @item
48 An output definition, such as @code{\paper}, @code{\midi}, and
49 @code{\layout}.  Such a definition at the toplevel changes the default
50 settings for the block entered.
51
52 @item
53 A direct scheme expression, such as
54 @code{#(set-default-paper-size "a7" 'landscape)} or
55 @code{#(ly:set-option 'point-and-click #f)}.
56
57 @item
58 A @code{\header} block.  This sets the global header block.  This
59 is the block containing the definitions for book-wide settings, like
60 composer, title, etc.
61
62 @item
63 A @code{\score} block.  This score will be collected with other
64 toplevel scores, and combined as a single @code{\book}.
65
66 This behavior can be changed by setting the variable
67 @code{toplevel-score-handler} at toplevel.  The default handler is
68 defined in the init file @file{scm/@/lily@/.scm}.
69
70 The @code{\score} must begin with a music expression, and may
71 contain only one music expression.
72
73 @item
74 A @code{\book} block logically combines multiple movements
75 (i.e., multiple @code{\score} blocks) in one document.  If there are
76 a number of @code{\scores}, one output file will be created for
77 each @code{\book} block, in which all corresponding movements are
78 concatenated.  The only reason to explicitly specify @code{\book} blocks
79 in a @code{.ly} file is if you wish multiple output files from a single
80 input file.  One exception is within lilypond-book documents, where you
81 explicitly have to add a @code{\book} block if you want more than a
82 single @code{\score} or @code{\markup} in the same example.
83
84 This behavior can be changed by setting the variable
85 @code{toplevel-book-handler} at toplevel.  The default handler is
86 defined in the init file @file{scm/@/lily@/.scm}.
87
88 @item
89 A compound music expression, such as
90 @example
91 @{ c'4 d' e'2 @}
92 @end example
93
94 This will add the piece in a @code{\score} and format it in a
95 single book together with all other toplevel @code{\score}s and music
96 expressions.  In other words, a file containing only the above
97 music expression will be translated into
98
99 @example
100 \book @{
101   \score @{
102     \new Staff @{
103       \new Voice @{
104         @{ c'4 d' e'2 @}
105       @}
106     @}
107   @}
108         \layout @{ @}
109         \header @{ @}
110 @}
111 @end example
112
113 This behavior can be changed by setting the variable
114 @code{toplevel-music-handler} at toplevel.  The default handler is
115 defined in the init file @file{scm/@/lily@/.scm}.
116
117 @item
118 A markup text, a verse for example
119 @example
120 \markup @{
121    2.  The first line verse two.
122 @}
123 @end example
124
125 Markup texts are rendered above, between or below the scores or music
126 expressions, wherever they appear.
127
128 @cindex variables
129
130 @item
131 An variable, such as
132 @example
133 foo = @{ c4 d e d @}
134 @end example
135
136 This can be used later on in the file by entering @code{\foo}.  The
137 name of an variable should have alphabetic characters only; no
138 numbers, underscores or dashes.
139
140 @end itemize
141
142 The following example shows three things that may be entered at
143 toplevel
144
145 @example
146 \layout @{
147   % movements are non-justified by default
148   ragged-right = ##t
149 @}
150
151 \header @{
152    title = "Do-re-mi"
153 @}
154
155 @{ c'4 d' e2 @}
156 @end example
157
158
159 At any point in a file, any of the following lexical instructions can
160 be entered:
161
162 @itemize
163 @item @code{\version}
164 @item @code{\include}
165 @item @code{\sourcefilename}
166 @item @code{\sourcefileline}
167
168 @end itemize
169
170
171 @node A single music expression
172 @subsection A single music expression
173
174 A @code{\score} must contain a single music expression.  However,
175 this music expression may be of any size.  Recall that music
176 expressions may be included inside other expressions to form
177 larger expressions.  All of these examples are single music
178 expressions; note the curly braces @{ @} or angle brackets <<
179 >> at the beginning and ending of the music.
180
181 @example
182 @{ c'4 c' c' c' @}
183 @end example
184
185 @lilypond[ragged-right,verbatim,quote]
186 {
187   { c'4 c' c' c'}
188   { d'4 d' d' d'}
189 }
190 @end lilypond
191
192 @lilypond[ragged-right,verbatim,quote]
193 <<
194   \new Staff { c'4 c' c' c' }
195   \new Staff { d'4 d' d' d' }
196 >>
197 @end lilypond
198
199 @example
200 @{
201   \new GrandStaff <<
202     \new StaffGroup <<
203       \new Staff @{ \flute @}
204       \new Staff @{ \oboe @}
205     >>
206     \new StaffGroup <<
207       \new Staff @{ \violinI @}
208       \new Staff @{ \violinII @}
209     >>
210   >>
211 @}
212 @end example
213
214
215 @node Multiple scores in a book
216 @subsection Multiple scores in a book
217
218 @funindex \book
219 @cindex movements, multiple
220
221 A document may contain multiple pieces of music and texts.  Examples
222 of these are an etude book, or an orchestral part with multiple
223 movements.  Each movement is entered with a @code{\score} block,
224
225 @example
226 \score @{
227   @var{..music..}
228 @}
229 @end example
230
231 and texts are entered with a @code{\markup} block,
232
233 @example
234 \markup @{
235   @var{..text..}
236 @}
237 @end example
238
239 @funindex \book
240
241 All the movements and texts which appear in the same @code{.ly} file 
242 will normally be typeset in the form of a single output file. 
243
244 @example
245 \score @{
246   @var{..}
247 @}
248 \markup @{
249   @var{..}
250 @}
251 \score @{
252   @var{..}
253 @}
254 @end example
255
256 However, if you want multiple output files from the same @code{.ly}
257 file, then you can add multiple @code{\book} blocks, where each such
258 @code{\book} block will result in a separate output.  If you do not
259 specify any @code{\book} block in the file, LilyPond will implicitly
260 treat the full file as a single @code{\book} block, see @ref{File
261 structure}.  One important exception is within lilypond-book documents,
262 where you explicitly have to add a @code{\book} block, otherwise only
263 the first @code{\score} or @code{\markup} will appear in the output.
264
265 The header for each piece of music can be put inside the @code{\score}
266 block.  The @code{piece} name from the header will be printed before
267 each movement.  The title for the entire book can be put inside the
268 @code{\book}, but if it is not present, the @code{\header} which is at
269 the top of the file is inserted.
270
271 @example
272 \header @{
273   title = "Eight miniatures"
274   composer = "Igor Stravinsky"
275 @}
276 \score @{
277   @dots{}
278   \header @{ piece = "Romanze" @}
279 @}
280 \markup @{
281    ..text of second verse..
282 @}
283 \markup @{
284    ..text of third verse..
285 @}
286 \score @{
287   @dots{}
288   \header @{ piece = "Menuetto" @}
289 @}
290 @end example
291
292 @node Extracting fragments of notation
293 @subsection Extracting fragments of notation
294
295 It is possible to quote small fragments of a large score directly from
296 the output.  This can be compared to clipping a piece of a paper score
297 with scissors.
298
299 This is done by definining the measures that need to be cut out
300 separately.  For example, including the following definition
301
302
303 @verbatim
304 \layout {
305   clip-regions
306   = #(list
307       (cons
308        (make-rhythmic-location 5 1 2)
309        (make-rhythmic-location 7 3 4)))
310 }       
311 @end verbatim
312
313 @noindent
314 will extract a fragment starting halfway the fifth measure, ending in
315 the seventh measure.  The meaning of @code{5 1 2} is: after a 1/2 note
316 in measure 5, and @code{7 3 4} after 3 quarter notes in measure 7.
317
318 More clip regions can be defined by adding more pairs of
319 rhythmic-locations to the list. 
320
321 In order to use this feature, LilyPond must be invoked with
322 @code{-dclip-systems}.  The clips are output as EPS files, and are
323 converted to PDF and PNG if these formats are switched on as well.
324
325 For more information on output formats, see @rprogram{Invoking lilypond}.
326
327 @seealso
328
329 Examples: @lsr{non-notation,clip-systems.ly}
330
331
332 @node Including LilyPond files
333 @subsection Including LilyPond files
334
335 @funindex \include
336 @cindex including files
337
338 A large project may be split up into separate files.  To refer to another
339 file, use
340
341 @example
342 \include "otherfile.ly"
343 @end example
344
345 The line @code{\include "file.ly"} is equivalent to pasting the contents
346 of file.ly into the current file at the place where you have the
347 \include.  For example, for a large project you might write separate files
348 for each instrument part and create a @q{full score} file which brings
349 together the individual instrument files.
350
351 The initialization of LilyPond is done in a number of files that are
352 included by default when you start the program, normally transparent to the
353 user.  Run lilypond --verbose to see a list of paths and files that Lily
354 finds.
355
356 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
357 VERSION is in the form @q{2.6.1}) are on the path and available to
358 @code{\include}.  Files in the
359 current working directory are available to \include, but a file of the same
360 name in LilyPond's installation takes precedence.  Files are
361 available to \include from directories in the search path specified as an
362 option when invoking @code{lilypond --include=DIR} which adds DIR to the
363 search path.
364
365 The @code{\include} statement can use full path information, but with the Unix
366 convention @samp{/} rather than the DOS/Windows @samp{\}.  For example,
367 if @file{stuff.ly} is located one directory higher than the current working
368 directory, use
369
370 @example
371 \include "../stuff.ly"
372 @end example
373
374
375 @node Text encoding
376 @subsection Text encoding
377
378 LilyPond uses the Pango library to format multi-lingual texts, and
379 does not perform any input-encoding conversions.  This means that any
380 text, be it title, lyric text, or musical instruction containing
381 non-ASCII characters, must be utf-8.  The easiest way to enter such text is
382 by using a Unicode-aware editor and saving the file with utf-8 encoding.  Most
383 popular modern editors have utf-8 support, for example, vim, Emacs,
384 jEdit, and GEdit do.
385
386 @c  Currently not working
387 @ignore
388 Depending on the fonts installed, the following fragment shows Hebrew
389 and Cyrillic lyrics,
390
391 @cindex Cyrillic
392 @cindex Hebrew
393 @cindex ASCII, non
394
395 @li lypondfile[fontload]{utf-8.ly}
396
397 The @TeX{} backend does not handle encoding specially at all.  Strings
398 in the input are put in the output as-is.  Extents of text items in the
399 @TeX{} backend, are determined by reading a file created via the
400 @file{texstr} backend,
401
402 @example
403 lilypond -dbackend=texstr input/les-nereides.ly
404 latex les-nereides.texstr
405 @end example
406
407 The last command produces @file{les-nereides.textmetrics}, which is
408 read when you execute
409
410 @example
411 lilypond -dbackend=tex input/les-nereides.ly
412 @end example
413
414 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
415 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
416 interpreting non-ASCII strings.
417
418 @end ignore
419
420 To use a Unicode escape sequence, use
421
422 @example
423 #(ly:export (ly:wide-char->utf-8 #x2014))
424 @end example
425
426
427 @seealso
428
429 @lsr{text,utf-8.ly}
430
431
432 @node Different editions from one source
433 @subsection Different editions from one source
434
435 @funindex \tag
436 @cindex tag
437
438 The @code{\tag} command marks music expressions with a name.  These
439 tagged expressions can be filtered out later.  With this mechanism it
440 is possible to make different versions of the same music source.
441
442 In the following example, we see two versions of a piece of music, one
443 for the full score, and one with cue notes for the instrumental part
444
445 @example
446 c1
447 <<
448   \tag #'part <<
449     R1 \\
450     @{
451       \set fontSize = #-1
452       c4_"cue" f2 g4 @}
453   >>
454   \tag #'score R1
455 >>
456 c1
457 @end example
458
459 The same can be applied to articulations, texts, etc.: they are
460 made by prepending
461 @example
462 -\tag #@var{your-tag}
463 @end example
464 to an articulation, for example,
465 @example
466 c1-\tag #'part ^4
467 @end example
468
469 This defines a note with a conditional fingering indication.
470
471 @cindex keepWithTag
472 @cindex removeWithTag
473 By applying the @code{\keepWithTag} and @code{\removeWithTag}
474 commands, tagged expressions can be filtered.  For example,
475 @example
476 <<
477   @var{the music}
478   \keepWithTag #'score @var{the music}
479   \keepWithTag #'part @var{the music}
480 >>
481 @end example
482 would yield
483
484 @lilypondfile[ragged-right,quote]{tag-filter.ly}
485
486 The arguments of the @code{\tag} command should be a symbol
487 (such as @code{#'score} or @code{#'part}), followed by a
488 music expression.  It is possible to put multiple tags on
489 a piece of music with multiple @code{\tag} entries,
490
491 @example
492   \tag #'original-part \tag #'transposed-part @dots{}
493 @end example
494
495
496 @seealso
497
498 Examples: @lsr{parts,tag@/-filter@/.ly}
499
500
501 @refbugs
502
503 Multiple rests are not merged if you create the score with both tagged
504 sections.
505
506
507 @node Common syntax issues TODO name?
508 @section Common syntax issues TODO name?
509
510 @menu
511 * Up and down::                 
512 * Distances and measurements MAYBE MOVE::  
513 @end menu
514
515 @node Up and down
516 @subsection Up and down
517
518 TODO: everything
519
520 By default, lilypnod does a pretty jazz'n job of picking
521 directions.  But in some cases, it may be desirable to force a
522 direction.
523
524 @verbatim
525 -
526 ^ _
527 @end verbatim
528
529
530 @node Distances and measurements MAYBE MOVE
531 @subsection Distances and measurements MAYBE MOVE
532
533 DISCUSS after working on other sections.
534
535 TODO: staff spaces, #UP #DOWN #LEFT #RIGHT.  Maybe move into tweaks?
536
537
538
539
540
541 @node Other stuffs TODO move?
542 @section Other stuffs TODO move?
543
544
545 @menu
546 * Displaying LilyPond notation::  
547 * Skipping corrected music::    
548 @end menu
549
550 @node Displaying LilyPond notation
551 @subsection Displaying LilyPond notation
552
553 @funindex \displayLilyMusic
554 Displaying a music expression in LilyPond notation can be
555 done using the music function @code{\displayLilyMusic}.  For example,
556
557 @example
558 @{
559   \displayLilyMusic \transpose c a, @{ c e g a bes @}
560 @}
561 @end example
562
563 will display
564
565 @example
566 @{ a, cis e fis g @}
567 @end example
568
569 By default, LilyPond will print these messages to the console along
570 with all the other messages.  To split up these messages and save
571 the results of @code{\display@{STUFF@}}, redirect the output to
572 a file.
573
574 @example
575 lilypond file.ly >display.txt
576 @end example
577
578
579 @node Skipping corrected music
580 @subsection Skipping corrected music
581
582
583 @funindex skipTypesetting
584 @funindex showLastLength
585
586 When entering or copying music, usually only the music near the end (where
587 you
588 are adding notes) is interesting to view and correct.  To speed up
589 this correction process, it is possible to skip typesetting of all but
590 the last few measures.  This is achieved by putting
591
592 @verbatim
593 showLastLength = R1*5
594 \score { ... }
595 @end verbatim
596
597 @noindent
598 in your source file.  This will render only the last 5 measures
599 (assuming 4/4 time signature) of every @code{\score} in the input
600 file.  For longer pieces, rendering only a small part is often an order
601 of magnitude quicker than rendering it completely
602
603 Skipping parts of a score can be controlled in a more fine-grained
604 fashion with the property @code{Score.skipTypesetting}.  When it is
605 set, no typesetting is performed at all.
606
607 This property is also used to control output to the MIDI file.  Note that
608 it skips all events, including tempo and instrument changes.  You have
609 been warned.
610
611 @lilypond[quote,fragment,ragged-right,verbatim]
612 \relative c'' {
613   c8 d
614   \set Score.skipTypesetting = ##t
615   e e e e e e e e
616   \set Score.skipTypesetting = ##f
617   c d b bes a g c2 }
618 @end lilypond
619
620 In polyphonic music, @code{Score.skipTypesetting} will affect all
621 voices and staves, saving even more time.
622
623
624