1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
4 @c A menu is needed before every deeper *section nesting of @node's; run
5 @c M-x texinfo-all-menus-update
6 @c to automatically fill in these menus before saving changes
11 This section deals with general lilypond issues, rather than
16 * A single music expression::
17 * Titles and headers::
20 * Multiple movements::
28 The main format of input for LilyPond are text files. By convention,
29 these files end with ``@code{.ly}''.
32 * File structure (introduction)::
34 * Including LilyPond files::
39 @node File structure (introduction)
40 @subsection File structure (introduction)
42 A basic example of a lilypond input file is
47 @{ @} % this is a single music expression;
48 % all the music goes in here.
56 There are many variations of this basic pattern, but this
57 example serves as a useful starting place.
59 The major part of this manual is concerned with entering various
60 forms of music in LilyPond. However, many music expressions are not
61 valid input on their own, for example, a @code{.ly} file containing
68 will result in a parsing error. Instead, music should be inside other
69 expressions, which may be put in a file by themselves. Such
70 expressions are called toplevel expressions. The next section enumerates
75 @subsection File structure
77 A @code{.ly} file contains any number of toplevel expressions, where a
78 toplevel expression is one of the following
82 An output definition, such as @code{\paper}, @code{\midi}, and
83 @code{\layout}. Such a definition at the toplevel changes the default
84 settings for the block entered.
87 A direct scheme expression, such as
88 @code{#(set-default-paper-size "a7" 'landscape)} or
89 @code{#(ly:set-option 'point-and-click #f)}.
92 A @code{\header} block. This sets the global header block. This
93 is the block containing the definitions for book-wide settings, like
97 An @code{\addquote} statement. See @ref{Quoting other voices}
101 A @code{\score} block. This score will be collected with other
102 toplevel scores, and combined as a single @code{\book}.
104 This behavior can be changed by setting the variable
105 @code{toplevel-score-handler} at toplevel. The default handler is
106 defined in the init file @file{scm/@/lily@/.scm}.
108 The @code{\score} must begin with a music expression, and may
109 contain only one music expression.
112 A @code{\book} block logically combines multiple movements
113 (i.e., multiple @code{\score} blocks) in one document. If there are
114 a number of @code{\scores}, a single output file will be created
115 in which all movements are concatenated.
117 This behavior can be changed by setting the variable
118 @code{toplevel-book-handler} at toplevel. The default handler is
119 defined in the init file @file{scm/@/lily@/.scm}.
122 A compound music expression, such as
127 This will add the piece in a @code{\score} and format it in a
128 single book together with all other toplevel @code{\score}s and music
129 expressions. In other words, a file containing only the above
130 music expression will be translated into
146 This behavior can be changed by setting the variable
147 @code{toplevel-music-handler} at toplevel. The default handler is
148 defined in the init file @file{scm/@/lily@/.scm}.
151 A markup text, a verse for example
154 2. The first line verse two.
158 Markup texts are rendered above, between or below the scores or music
159 expressions, wherever they appear.
162 An identifier, such as
167 This can be used later on in the file by entering @code{\foo}. The
168 name of an identifier should have alphabetic characters only; no
169 numbers, underscores or dashes.
173 The following example shows three things that may be entered at
178 % movements are non-justified by default
190 At any point in a file, any of the following lexical instructions can
194 @item @code{\version}
195 @item @code{\include}
196 @item @code{\renameinput}
200 @node Including LilyPond files
201 @subsection Including LilyPond files
203 @cindex @code{\include}
204 @cindex including files
206 A large project may be split up into separate files. To refer to another
210 \include "otherfile.ly"
213 The line @code{\include "file.ly"} is equivalent to pasting the contents
214 of file.ly into the current file at the place where you have the
215 \include. For example, for a large project you might write separate files
216 for each instrument part and create a ``full score'' file which brings
217 together the individual instrument files.
219 The initialization of LilyPond is done in a number of files that are
220 included by default when you start the program, normally transparent to the
221 user. Run lilypond --verbose to see a list of paths and files that Lily
224 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
225 VERSION is in the form ``2.6.1'') are on the path and available to
226 @code{\include}. Files in the
227 current working directory are available to \include, but a file of the same
228 name in LilyPond's installation takes precedence. Files are
229 available to \include from directories in the search path specified as an
230 option when invoking @code{lilypond --include=DIR} which adds DIR to the search
233 The @code{\include} statement can use full path information, but with the Unix
234 convention @code{"/"} rather than the DOS/Windows @code{"\"}. For example,
235 if @file{stuff.ly} is located one directory higher than the current working
239 \include "../stuff.ly"
244 @subsection Text encoding
246 LilyPond uses the Pango library to format multi-lingual texts, and
247 does not perform any input-encoding conversions. This means that any
248 text, be it title, lyric text, or musical instruction containing
249 non-ASCII characters, must be utf-8. The easiest way to enter such text is
250 by using a Unicode-aware editor and saving the file with utf-8 encoding. Most
251 popular modern editors have utf-8 support, for example, vim, Emacs,
254 Depending on the fonts installed, the following fragment shows Hebrew
261 @lilypondfile[fontload]{utf-8.ly}
263 The @TeX{} backend does not handle encoding specially at all. Strings
264 in the input are put in the output as-is. Extents of text items in the
265 @TeX{} backend, are determined by reading a file created via the
266 @file{texstr} backend,
269 lilypond -b texstr input/les-nereides.ly
270 latex les-nereides.texstr
273 The last command produces @file{les-nereides.textmetrics}, which is
274 read when you execute
277 lilypond -b tex input/les-nereides.ly
280 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
281 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
282 interpreting non-ASCII strings.
284 To use a Unicode escape sequence, use
287 #(ly:export (ly:wide-char->utf-8 #x2014))
293 @inputfileref{input/regression,utf-8.ly}
297 @node A single music expression
298 @section A single music expression
300 A @code{\score} must contain a single music expression. However,
301 this music expression may be of any size. Recall that music
302 expressions may be included inside other expressions to form
303 larger expressions. All of these examples are single music
304 expressions; note the curly braces @{ @} or angle brackets <<
305 >> at the beginning and ending of the music.
311 @lilypond[ragged-right,verbatim,quote]
318 @lilypond[ragged-right,verbatim,quote]
320 \new Staff { c'4 c' c' c' }
321 \new Staff { d'4 d' d' d' }
329 \new Staff @{ \flute @}
330 \new Staff @{ \oboe @}
333 \new Staff @{ \violinI @}
334 \new Staff @{ \violinII @}
341 @node Titles and headers
342 @section Titles and headers
344 Almost all printed music includes a title and the composer's name;
345 some pieces include a lot more information.
353 @node Creating titles
354 @subsection Creating titles
356 Titles are created for each @code{\score} block, and over a
359 The contents of the titles are taken from the @code{\header} blocks.
360 The header block for a book supports the following
363 The dedicatee of the music, centered at the top of the first page.
366 The title of the music, centered just below the dedication.
369 Subtitle, centered below the title.
372 Subsubtitle, centered below the subtitle.
375 Name of the poet, flush-left below the subtitle.
378 Name of the composer, flush-right below the subtitle.
381 Meter string, flush-left below the poet.
384 Name of the opus, flush-right below the composer.
387 Name of the arranger, flush-right below the opus.
390 Name of the instrument, centered below the arranger. Also
391 centered at the top of pages (other than the first page).
394 Name of the piece, flush-left below the instrument.
396 @cindex page breaks, forcing
398 This forces the title to start on a new page (set to ##t or ##f).
401 Copyright notice, centered at the bottom of the first page. To
402 insert the copyright symbol, see @ref{Text encoding}.
405 Centered at the bottom of the last page.
409 Here is a demonstration of the fields available. Note that you
410 may use any @ref{Text markup} commands in the header.
412 @lilypond[quote,verbatim,line-width=11.0\cm]
415 paper-height = 10.0\cm
420 dedication = "dedicated to me"
421 title = \markup \center-align { "Title first line" "Title second line, longer" }
422 subtitle = "the subtitle,"
423 subsubtitle = #(string-append "subsubtitle LilyPond version " (lilypond-version))
425 composer = \markup \center-align { "composer" \small "(1847-1973)" }
426 texttranslator = "Text Translator"
427 meter = \markup { \teeny "m" \tiny "e" \normalsize "t" \large "e" \huge "r" }
428 arranger = \markup { \fontsize #8.5 "a" \fontsize #2.5 "r" \fontsize #-2.5 "r" \fontsize #-5.3 "a" \fontsize #7.5 "nger" }
429 instrument = \markup \bold \italic "instrument"
453 As demonstrated before, you can use multiple @code{\header} blocks.
454 When same fields appear in different blocks, the latter is used.
455 Here is a short example.
459 composer = "Composer"
467 piece = "New piece" % overwrite previous one
472 If you define the @code{\header} inside the @code{\score} block, then
473 normally only the @code{piece} and @code{opus} headers will be printed.
474 Note that the music expression must come before the @code{\header}.
476 @lilypond[quote,verbatim,line-width=11.0\cm]
480 title = "title" % not printed
487 @cindex @code{printallheaders}
489 You may change this behavior (and print all the headers when defining
490 @code{\header} inside @code{\score}) by using
500 @subsection Custom titles
502 A more advanced option is to change the definitions of the following
503 variables in the @code{\paper} block. The init file
504 @file{ly/titling-init.ly} lists the default layout.
507 @cindex @code{bookTitleMarkup}
508 @item bookTitleMarkup
509 This is the title put over an entire @code{\book} block. Typically,
510 it has the composer and the title of the piece
512 @cindex @code{scoreTitleMarkup}
513 @item scoreTitleMarkup
514 This is the title put over a @code{\score} block within a
515 @code{\book}. Typically, it has the name of the movement (@code{piece}
518 @cindex @code{oddHeaderMarkup}
519 @item oddHeaderMarkup
520 This is the page header for odd-numbered pages.
522 @cindex @code{evenHeaderMarkup}
523 @item evenHeaderMarkup
524 This is the page header for even-numbered pages. If unspecified,
525 the odd header is used instead.
527 By default, headers are defined such that the page number is on the
528 outside edge, and the instrument is centered.
530 @cindex @code{oddFooterMarkup}
531 @item oddFooterMarkup
532 This is the page footer for odd-numbered pages.
534 @cindex @code{evenFotterMarkup}
535 @item evenFooterMarkup
536 This is the page footer for even-numbered pages. If unspecified,
537 the odd header is used instead.
539 By default, the footer has the copyright notice on the first, and
540 the tagline on the last page.
550 The following definition will put the title flush left, and the
551 composer flush right on a single line.
555 bookTitleMarkup = \markup {
557 \fromproperty #'header:title
558 \fromproperty #'header:composer
567 The @code{breakbefore=##t} header requires that there is a @code{piece} header as well. It may be used as a normal header, or left blank (@code{=""}) as in the example above, but it must be present.
571 @node Paper and pages
572 @section Paper and pages
574 This section deals with the display of music on physical paper.
583 @subsection Paper size
587 @cindex @code{papersize}
589 To change the paper size, there are two commands,
591 #(set-default-paper-size "a4")
593 #(set-paper-size "a4")
597 The first command sets the size of all pages. The second command sets the size
598 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
599 block is at the top of the file, then it will apply to all pages. If the
600 @code{\paper} block is inside a @code{\book}, then the paper size will only
603 Support for the following paper sizes are included by default,
604 @code{a6}, @code{a5}, @code{a4}, @code{a3}, @code{legal}, @code{letter},
605 @code{11x17} (also known as tabloid).
607 Extra sizes may be added by editing the definition for
608 @code{paper-alist} in the initialization file @file{scm/paper.scm}.
613 If the symbol @code{landscape} is supplied as an argument to
614 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
615 and wider line widths will be set correspondingly.
618 #(set-default-paper-size "a6" 'landscape)
621 Setting the paper size will adjust a number of @code{\paper} variables
622 (such as margins). To use a particular paper size with altered
623 @code{\paper} variables, set the paper size before setting the variables.
626 @node Page formatting
627 @subsection Page formatting
629 @cindex page formatting
634 LilyPond will do page layout, set margins, and add headers and
635 footers to each page.
637 @cindex @code{annotate-spacing}
638 @cindex Spacing, display of properties
640 To graphically display the dimensions of properties that may
641 be altered for page formatting, use
645 annotate-spacing = ##t
650 All units dimensions are measured in staff spaces. The pairs
651 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
652 @var{b} the upper edge of the interval.
654 The default layout responds to the following settings in the
657 @cindex @code{\paper}
661 @cindex @code{first-page-number}
662 @item first-page-number
663 The value of the page number of the first page. Default is@tie{}1.
665 @cindex @code{printfirst-page-number}
666 @item printfirst-page-number
667 If set to true, will print the page number in the first page. Default is
670 @cindex @code{print-page-number}
671 @item print-page-number
672 If set to false, page numbers will not be printed.
674 @cindex @code{paper-width}
676 The width of the page.
678 @cindex @code{paper-height}
680 The height of the page.
682 @cindex @code{top-margin}
684 Margin between header and top of the page.
686 @cindex @code{bottom-margin}
688 Margin between footer and bottom of the page.
690 @cindex @code{left-margin}
692 Margin between the left side of the page and the beginning of the music.
694 @cindex @code{line-width}
696 The length of the systems.
698 @cindex @code{head-separation}
699 @item head-separation
700 Distance between the top-most music system and the page header.
702 @cindex @code{foot-separation}
703 @item foot-separation
704 Distance between the bottom-most music system and the page footer.
706 @cindex @code{page-top-space}
707 Distance from the top of the printable area to the center of the first
708 staff. This only works for staves which are vertically small. Big staves
709 are set with the top of their bounding box aligned to the top of the
712 @cindex @code{ragged-bottom}
714 If set to true, systems will not be spread vertically across the page. This
715 does not affect the last page.
717 This should be set to true for pieces that have only two or three
718 systems per page, for example orchestral scores.
720 @cindex @code{ragged-last-bottom}
721 @item ragged-last-bottom
722 If set to false, systems will be spread vertically to fill the last page.
724 Pieces that amply fill two pages or more should have this set to
727 @cindex @code{system-count}
729 This variable, if set, specifies into how many lines a score should be
732 @cindex @code{between-system-space}
733 @item between-system-space
734 This dimensions determines the distance between systems. It is the
735 ideal distance between the center of the bottom staff of one system
736 and the center of the top staff of the next system.
738 Increasing this will provide a more even appearance of the page at the
739 cost of using more vertical space.
741 @cindex @code{between-system-padding}
742 @item between-system-padding
743 This dimension is the minimum amount of white space that will always
744 be present between the bottom-most symbol of one system, and the
745 top-most of the next system.
747 Increasing this will put systems whose bounding boxes almost touch
751 @cindex @code{horizontal-shift}
752 @item horizontal-shift
753 All systems (including titles and system separators) are shifted by
754 this amount to the right. Page markup, such as headers and footers are
755 not affected by this. The purpose of this variable is to make space
756 for instrument names at the left.
758 @cindex @code{after-title-space}
759 @item after-title-space
760 Amount of space between the title and the first system.
762 @cindex @code{after-title-space}
763 @item before-title-space
764 Amount of space between the last system of the previous piece and the
767 @cindex @code{between-title-space}
768 @item between-title-space
769 Amount of space between consecutive titles (e.g., the title of the
770 book and the title of a piece).
772 @cindex @code{printallheaders}
773 @item printallheaders
774 Setting this to #t will print all headers for each \score in a
775 \book. Normally only the piece and opus \headers are printed.
777 @cindex @code{systemSeparatorMarkup}
778 @item systemSeparatorMarkup
779 This contains a markup object, which will be inserted between
780 systems. This is often used for orchestral scores.
782 The markup command @code{\slashSeparator} is provided as a sensible
785 @lilypond[ragged-right]
788 \relative { c1 \break c1 }
791 systemSeparatorMarkup = \slashSeparator
807 ragged-last-bottom = ##t
811 You can also define these values in Scheme. In that case @code{mm},
812 @code{in}, @code{pt}, and @code{cm} are variables defined in
813 @file{paper-defaults.ly} with values in millimeters. That's why the
814 value has to be multiplied in the example
818 #(define bottom-margin (* 2 cm))
825 The default footer is empty, except for the first page, where the
826 @code{copyright} field from @code{\header} is inserted, and the last
827 page, where @code{tagline} from @code{\header} is added. The default
828 tagline is ``Music engraving by LilyPond (@var{version})''.@footnote{Nicely
829 printed parts are good PR for us, so please leave the tagline if you
832 The header and footer are created by the functions @code{make-footer}
833 and @code{make-header}, defined in @code{\paper}. The default
834 implementations are in @file{ly/@/paper@/-defaults@/.ly} and
835 @file{ly/@/titling@/-init@/.ly}.
837 The page layout itself is done by two functions in the
838 @code{\paper} block, @code{page-music-height} and
839 @code{page-make-stencil}. The former tells the line-breaking algorithm
840 how much space can be spent on a page, the latter creates the actual
841 page given the system to put on it.
846 The option right-margin is defined but doesn't set the right margin
847 yet. The value for the right margin has to be defined adjusting the
848 values of @code{left-margin} and @code{line-width}.
850 The default page header puts the page number and the @code{instrument}
851 field from the @code{\header} block on a line.
853 The titles (from the @code{\header@{@}} section) are treated as a
854 system, so @code{ragged-bottom} and @code{ragged-last-bottom} will
855 add space between the titles and the first system of the score.
859 @section Music layout
861 This section deals with the manner in which the music is printed
862 within the boundaries defined by the @code{\paper} block.
864 The global paper layout is determined by three factors: the page layout, the
865 line breaks, and the spacing. These all influence each other. The
866 choice of spacing determines how densely each system of music is set.
867 This influences where line breaks are chosen, and thus ultimately, how
868 many pages a piece of music takes.
870 Globally spoken, this procedure happens in three steps: first,
871 flexible distances (``springs'') are chosen, based on durations. All
872 possible line breaking combinations are tried, and the one with the
873 best results -- a layout that has uniform density and requires as
874 little stretching or cramping as possible -- is chosen.
876 After spacing and linebreaking, the systems are distributed across
877 pages, taking into account the size of the page, and the size of the
881 * Setting global staff size::
882 * Selecting notation font size::
885 * Vertical spacing of piano staves::
886 * Horizontal spacing::
893 @node Setting global staff size
894 @subsection Setting global staff size
896 @cindex font size, setting
897 @cindex staff size, setting
898 @cindex @code{layout} file
900 To set the global staff size, use @code{set-global-staff-size}.
903 #(set-global-staff-size 14)
907 This sets the global default size to 14pt staff height and scales all
910 The Feta font provides musical symbols at eight different
911 sizes. Each font is tuned for a different staff size: at a smaller size
912 the font becomes heavier, to match the relatively heavier staff lines.
913 The recommended font sizes are listed in the following table:
916 @multitable @columnfractions .15 .2 .22 .2
919 @tab @b{staff height (pt)}
920 @tab @b{staff height (mm)}
962 @c modern rental material?
967 These fonts are available in any sizes. The context property
968 @code{fontSize} and the layout property @code{staff-space} (in
969 @internalsref{StaffSymbol}) can be used to tune the size for individual
970 staves. The sizes of individual staves are relative to the global size.
978 This manual: @ref{Selecting notation font size}.
981 @node Selecting notation font size
982 @subsection Selecting notation font size
984 The easiest method of setting the font size of any context, is by
985 setting the @code{fontSize} property.
987 @lilypond[quote,fragment,relative=1,verbatim]
996 It does not change the size of variable symbols, such as beams or
999 Internally, the @code{fontSize} context property will cause the
1000 @code{font-size} property to be set in all layout objects. The value
1001 of @code{font-size} is a number indicating the size relative to the
1002 standard size for the current staff height. Each step up is an
1003 increase of approximately 12% of the font size. Six steps is exactly a
1004 factor two. The Scheme function @code{magstep} converts a
1005 @code{font-size} number to a scaling factor.
1007 @lilypond[quote,fragment,relative=1,verbatim]
1009 \override NoteHead #'font-size = #-4
1011 \override NoteHead #'font-size = #3
1015 LilyPond has fonts in different design sizes. The music fonts for
1016 smaller sizes are chubbier, while the text fonts are relatively wider.
1017 Font size changes are achieved by scaling the design size that is
1018 closest to the desired size. The standard font size (for
1019 @code{font-size} equals 0), depends on the standard staff height. For
1020 a 20pt staff, a 10pt font is selected.
1022 The @code{font-size} property can only be set on layout objects that
1023 use fonts. These are the ones supporting the
1024 @internalsref{font-interface} layout interface.
1028 The following commands set @code{fontSize} for the current voice:
1030 @cindex @code{\tiny}
1032 @cindex @code{\small}
1034 @cindex @code{\normalsize}
1039 @subsection Score layout
1041 @cindex @code{\layout}
1043 While @code{\paper} contains settings that relate to the page formatting
1044 of the whole document, @code{\layout} contains settings for score-specific
1051 \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
1054 \override TextScript #'padding = #1.0
1055 \override Glissando #'thickness = #3
1063 This manual: @ref{Changing context default settings}
1066 @node Vertical spacing
1067 @subsection Vertical spacing
1069 @cindex vertical spacing
1070 @cindex distance between staves
1071 @cindex staff distance
1072 @cindex between staves, distance
1073 @cindex staves per page
1074 @cindex space between staves
1076 The height of each system is determined automatically. To prevent
1077 systems from bumping into each other, some minimum distances are set.
1078 By changing these, you can put staves closer together, and thus put
1079 more systems onto one page.
1081 Normally staves are stacked vertically. To make staves maintain a
1082 distance, their vertical size is padded. This is done with the
1083 property @code{minimum-Y-extent}. When applied to a
1084 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
1085 line, such as a staff or a line of lyrics. @code{minimum-Y-extent}
1086 takes a pair of numbers, so
1087 if you want to make it smaller than its default @code{#'(-4 . 4)}
1091 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
1095 This sets the vertical size of the current staff to 3 staff spaces on
1096 either side of the center staff line. The value @code{(-3 . 3)} is
1097 interpreted as an interval, where the center line is the 0, so the
1098 first number is generally negative. The staff can be made larger at
1099 the bottom by setting it to @code{(-6 . 4)}.
1101 The spacing of staves in a system may also be tuned per system. This is
1102 done with the command
1106 #"Score.NonMusicalPaperColumn"
1107 #'line-break-system-details
1108 #'((alignment-extra-space . 15))
1112 at the line break before the system to be changed. The distance
1113 @code{15} is distributed over all staves that have a fixed distance
1114 alignment. For example,
1116 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
1122 #"Score.NonMusicalPaperColumn"
1123 #'line-break-system-details
1124 #'((fixed-alignment-extra-space . 15))
1132 The distance for @code{alignment-extra-space} may also be negative.
1135 To change the amount of space between systems, use
1136 @code{between-system-space}. A score with only one staff is still
1137 considered to have systems, so setting @code{between-system-space} will
1138 be much more useful than changing @code{minimum-Y-extent} of a Staff
1143 between-system-space = 10\mm
1147 If you simply want to tell LilyPond ``fit as much as possible onto
1148 these pages, then expand to fill any available space on the pages,''
1149 then use the following
1153 between-system-padding = #1
1155 ragged-last-bottom=##f
1160 @c let's wait for a some comments before writing more.
1162 The vertical spacing on a page can also be changed for each system individually.
1163 Some examples are found in the example file
1164 @inputfileref{input/regression/,page-spacing.ly}.
1166 When setting @code{annotate-spacing} in the @code{\paper} block LilyPond
1167 will graphically indicate the dimensions of properties that may be set
1171 #(set-default-paper-size "a7" 'landscape)
1172 \paper { annotate-spacing = ##t }
1177 All units dimensions are measured in staff spaces. The pairs
1178 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
1179 @var{b} the upper edge of the interval.
1183 Internals: Vertical alignment of staves is handled by the
1184 @internalsref{VerticalAlignment} object. The context parameters
1185 specifying the vertical extent are described in connection with
1186 the @internalsref{Axis_group_engraver}.
1188 Example files: @inputfileref{input/regression/,page-spacing.ly},
1189 @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
1194 @node Vertical spacing of piano staves
1195 @subsection Vertical spacing of piano staves
1197 The distance between staves of a @internalsref{PianoStaff} cannot be
1198 computed during formatting. Rather, to make cross-staff beaming work
1199 correctly, that distance has to be fixed beforehand.
1201 The distance of staves in a @code{PianoStaff} is set with the
1202 @code{forced-distance} property of the
1203 @internalsref{VerticalAlignment} object, created in
1204 @internalsref{PianoStaff}.
1206 It can be adjusted as follows
1208 \new PianoStaff \with @{
1209 \override VerticalAlignment #'forced-distance = #7
1216 This would bring the staves together at a distance of 7 staff spaces,
1217 measured from the center line of each staff.
1219 The difference is demonstrated in the following example,
1220 @lilypond[quote,verbatim]
1222 \new PianoStaff \with {
1223 \override VerticalAlignment #'forced-distance = #7
1236 It is also possible to change the distance between for each system
1237 individually. This is done by including the command
1241 #"Score.NonMusicalPaperColumn"
1242 #'line-break-system-details
1243 #'((fixed-alignment-extra-space . 15))
1247 at the line break before the system to be changed. The distance
1248 @code{15} is distributed over all staves that have a fixed distance
1249 alignment. For example,
1251 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
1257 #"Score.NonMusicalPaperColumn"
1258 #'line-break-system-details
1259 #'((fixed-alignment-extra-space . 15))
1267 The distance for @code{fixed-alignment-extra-space} may also be
1272 Example files: @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
1274 @node Horizontal spacing
1275 @subsection Horizontal Spacing
1277 The spacing engine translates differences in durations into stretchable
1278 distances (``springs'') of differring lengths. Longer durations get
1279 more space, shorter durations get less. The shortest durations get a
1280 fixed amount of space (which is controlled by
1281 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
1282 object). The longer the duration, the more space it gets: doubling a
1283 duration adds a fixed amount (this amount is controlled by
1284 @code{spacing-increment}) of space to the note.
1286 For example, the following piece contains lots of half, quarter, and
1287 8th notes; the eighth note is followed by 1 note head width (NHW).
1288 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
1290 @lilypond[quote,fragment,verbatim,relative=1]
1291 c2 c4. c8 c4. c8 c4. c8 c8
1295 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
1296 approximately the width of a note head, and
1297 @code{shortest-duration-space} is set to 2.0, meaning that the
1298 shortest note gets 2.4 staff space (2.0 times the
1299 @code{spacing-increment}) of horizontal space. This space is counted
1300 from the left edge of the symbol, so the shortest notes are generally
1301 followed by one NHW of space.
1303 If one would follow the above procedure exactly, then adding a single
1304 32nd note to a score that uses 8th and 16th notes, would widen up the
1305 entire score a lot. The shortest note is no longer a 16th, but a 32nd,
1306 thus adding 1 NHW to every note. To prevent this, the shortest
1307 duration for spacing is not the shortest note in the score, but rather
1308 the one which occurs most frequently.
1311 The most common shortest duration is determined as follows: in every
1312 measure, the shortest duration is determined. The most common shortest
1313 duration is taken as the basis for the spacing, with the stipulation
1314 that this shortest duration should always be equal to or shorter than
1315 an 8th note. The shortest duration is printed when you run
1316 @code{lilypond} with the @code{--verbose} option.
1318 These durations may also be customized. If you set the
1319 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
1320 this sets the base duration for spacing. The maximum duration for this
1321 base (normally an 8th), is set through @code{base-shortest-duration}.
1323 @cindex @code{common-shortest-duration}
1324 @cindex @code{base-shortest-duration}
1325 @cindex @code{stem-spacing-correction}
1326 @cindex @code{spacing}
1328 Notes that are even shorter than the common shortest note are
1329 followed by a space that is proportional to their duration relative to
1330 the common shortest note. So if we were to add only a few 16th notes
1331 to the example above, they would be followed by half a NHW:
1333 @lilypond[quote,fragment,verbatim,relative=2]
1334 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
1338 In the introduction (see @ref{Engraving}), it was explained that stem
1339 directions influence spacing. This is controlled with the
1340 @code{stem-spacing-correction} property in the
1341 @internalsref{NoteSpacing}, object. These are generated for every
1342 @internalsref{Voice} context. The @code{StaffSpacing} object
1343 (generated in @internalsref{Staff} context) contains the same property
1344 for controlling the stem/bar line spacing. The following example shows
1345 these corrections, once with default settings, and once with
1346 exaggerated corrections:
1348 @lilypond[quote,ragged-right]
1352 \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
1353 \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
1359 Proportional notation is supported; see @ref{Proportional notation}.
1361 By default, spacing in tuplets depends on various non-duration
1362 factors (such as accidentals, clef changes, etc). To disregard
1363 such symbols and force uniform equal-duration spacing, use
1364 @code{Score.SpacingSpanner #'uniform-stretching}. This
1365 property can only be changed at the beginning of a score,
1367 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1369 \override SpacingSpanner #'uniform-stretching = ##t
1387 When @code{strict-note-spacing} is set, notes are spaced without
1388 regard for clefs, bar lines, and grace notes,
1390 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1391 \override Score.SpacingSpanner #'strict-note-spacing = ##t
1392 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c] c32[ c32] }
1398 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
1399 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
1400 @internalsref{SeparatingGroupSpanner}.
1404 Spacing is determined on a score wide basis. If you have a score that
1405 changes its character (measured in durations) halfway during the
1406 score, the part containing the longer durations will be spaced too
1409 There is no convenient mechanism to manually override spacing. The
1410 following work-around may be used to insert extra space into a score.
1412 \once \override Score.SeparationItem #'padding = #1
1415 No work-around exists for decreasing the amount of space.
1419 @subsection Line length
1422 @cindex breaking pages
1424 @cindex @code{indent}
1425 @cindex @code{line-width}
1426 @cindex @code{ragged-right}
1427 @cindex @code{ragged-last}
1429 @c Although line-width can be set in \layout, it should be set in paper
1430 @c block, to get page layout right.
1431 @c Setting indent in \paper block makes not much sense, but it works.
1433 @c Bit verbose and vague, use examples?
1434 The most basic settings influencing the spacing are @code{indent} and
1435 @code{line-width}. They are set in the @code{\layout} block. They
1436 control the indentation of the first line of music, and the lengths of
1439 If @code{ragged-right} is set to true in the @code{\layout} block, then
1440 systems ends at their natural horizontal length, instead of being spread
1441 horizontally to fill the whole line. This is useful for
1442 short fragments, and for checking how tight the natural spacing is.
1445 @cindex vertical spacing
1447 The option @code{ragged-last} is similar to @code{ragged-right}, but
1448 only affects the last line of the piece. No restrictions are put on
1449 that line. The result is similar to formatting text paragraphs. In a
1450 paragraph, the last line simply takes its natural horizontal length.
1451 @c Note that for text there are several options for the last line.
1452 @c While Knuth TeX uses natural length, lead typesetters use the same
1453 @c stretch as the previous line. eTeX uses \lastlinefit to
1454 @c interpolate between both these solutions.
1466 @subsection Line breaking
1469 @cindex breaking lines
1471 Line breaks are normally computed automatically. They are chosen so
1472 that lines look neither cramped nor loose, and that consecutive lines
1473 have similar density.
1475 Occasionally you might want to override the automatic breaks; you can
1476 do this by specifying @code{\break}. This will force a line break at
1477 this point. Line breaks can only occur at places where there are bar
1478 lines. If you want to have a line break where there is no bar line,
1479 you can force an invisible bar line by entering @code{\bar
1480 ""}. Similarly, @code{\noBreak} forbids a line break at a
1484 @cindex regular line breaks
1485 @cindex four bar music.
1487 For line breaks at regular intervals use @code{\break} separated by
1488 skips and repeated with @code{\repeat}:
1490 << \repeat unfold 7 @{
1491 s1 \noBreak s1 \noBreak
1492 s1 \noBreak s1 \break @}
1493 @emph{the real music}
1498 This makes the following 28 measures (assuming 4/4 time) be broken every
1499 4 measures, and only there.
1503 @code{\break}, and @code{\noBreak}.
1504 @cindex @code{\break}
1505 @cindex @code{\noBreak}
1509 Internals: @internalsref{BreakEvent}.
1511 A linebreaking configuration can now be saved as a @code{.ly} file
1512 automatically. This allows vertical alignments to be stretched to
1513 fit pages in a second formatting run. This is fairly new and
1514 complicated; see @inputfileref{input/regression/,page-layout-twopass.ly}
1519 Line breaks can only occur if there is a ``proper'' bar line. A note
1520 which is hanging over a bar line is not proper, such as
1522 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1523 c4 c2 c2 \break % this does nothing
1524 c2 c4 | % a break here would work
1525 c4 c2 c4 ~ \break % as does this break
1531 @subsection Page breaking
1533 The default page breaking may be overriden by inserting
1534 @code{\pageBreak} or @code{\noPageBreak} commands. These commands are
1535 analogous to @code{\break} and @code{\noBreak}. They should be
1536 inserted at a bar line. These commands force and forbid a page-break
1537 from happening. Of course, the @code{\pageBreak} command also forces
1540 Page breaks are computed by the @code{page-breaking} function in the
1541 @code{\paper} block.
1543 To force a new page for a new piece (in a collection of pieces or a
1544 piece in several movements), use @code{breakbefore} in the header.
1555 @cindex @code{\pageBreak}
1557 @cindex @code{\noPageBreak}
1563 The @code{breakbefore=##t} header requires that there is a @code{piece} header as well. It may be used as a normal header, or left blank (@code{=""}) as in the example above, but it must be present.
1567 @node Multiple movements
1568 @section Multiple movements
1570 @cindex bibliographic information
1573 @cindex Music engraving by LilyPond
1575 A document may contain multiple pieces of music and texts. Examples
1576 of these are an etude book, or an orchestral part with multiple
1577 movements. Each movement is entered with a @code{\score} block,
1585 and texts are entered with a @code{\markup} block,
1593 @cindex @code{\book}
1595 The movements and texts are combined together in a @code{\book} block,
1613 The header for each piece of music can be put inside the @code{\score}
1614 block. The @code{piece} name from the header will be printed before
1615 each movement. The title for the entire book can be put inside the
1616 @code{\book}, but if it is not present, the @code{\header} which is at
1617 the top of the file is inserted.
1619 @cindex Engraved by LilyPond
1620 @cindex signature line
1625 title = "Eight miniatures"
1626 composer = "Igor Stravinsky"
1630 \header @{ piece = "Romanze" @}
1633 ..text of second verse..
1636 ..text of third verse..
1640 \header @{ piece = "Menuetto" @}
1648 @section MIDI output
1653 MIDI (Musical Instrument Digital Interface) is a standard for
1654 connecting and controlling digital instruments. A MIDI file is a
1655 series of notes in a number of tracks. It is not an actual
1656 sound file; you need special software to translate between the
1657 series of notes and actual sounds.
1659 Pieces of music can be converted to MIDI files, so you can listen to
1660 what was entered. This is convenient for checking the music; octaves
1661 that are off or accidentals that were mistyped stand out very much
1662 when listening to the MIDI output.
1666 Many musically interesting effects, such as swing, articulation,
1667 slurring, etc., are not translated to midi.
1669 The midi output allocates a channel for each staff, and one for global
1670 settings. Therefore the midi file should not have more than 15 staves
1671 (or 14 if you do not use drums). Other staves will remain silent.
1673 Not all midi players correctly handle tempo changes in the midi
1674 output. Players that are known to work include
1675 @uref{http://@/timidity@/.sourceforge@/.net/,timidity}.
1678 * Creating MIDI files::
1680 * MIDI instrument names::
1683 @node Creating MIDI files
1684 @subsection Creating MIDI files
1686 To create a MIDI from a music piece of music, add a @code{\midi} block
1687 to a score, for example,
1692 \midi @{ \tempo 4=72 @}
1696 The tempo is specified using the @code{\tempo} command. In this
1697 example the tempo of quarter notes is set to 72 beats per minute.
1700 If there is a @code{\midi} command in a @code{\score}, only MIDI will
1701 be produced. When notation is needed too, a @code{\layout} block must
1707 \midi @{ \tempo 4=72 @}
1711 @cindex layout block
1715 Ties, dynamics, and tempo changes are interpreted. Dynamic marks,
1716 crescendi and decrescendi translate into MIDI volume levels. Dynamic
1717 marks translate to a fixed fraction of the available MIDI volume
1718 range, crescendi and decrescendi make the volume vary linearly between
1719 their two extremes. The fractions can be adjusted by
1720 @code{dynamicAbsoluteVolumeFunction} in @internalsref{Voice} context.
1721 For each type of MIDI instrument, a volume range can be defined. This
1722 gives a basic equalizer control, which can enhance the quality of
1723 the MIDI output remarkably. The equalizer can be controlled by
1724 setting @code{instrumentEqualizer}, or by setting
1727 \set Staff.midiMinimumVolume = #0.2
1728 \set Staff.midiMaximumVolume = #0.8
1731 To remove dynamics from the MIDI output, insert the following lines
1732 in the @code{\midi@{@}} section.
1739 \remove "Dynamic_performer"
1740 \remove "Span_dynamic_performer"
1748 Unterminated (de)crescendos will not render properly in the midi file,
1749 resulting in silent passages of music. The workaround is to explicitly
1750 terminate the (de)crescendo. For example,
1757 will not work properly but
1768 @subsection MIDI block
1772 The MIDI block is analogous to the layout block, but it is somewhat
1773 simpler. The @code{\midi} block can contain
1777 @item a @code{\tempo} definition, and
1778 @item context definitions.
1781 A number followed by a period is interpreted as a real number, so
1782 for setting the tempo for dotted notes, an extra space should be
1783 inserted, for example
1786 \midi @{ \tempo 4 . = 120 @}
1790 @cindex context definition
1792 Context definitions follow precisely the same syntax as within the
1793 \layout block. Translation modules for sound are called performers.
1794 The contexts for MIDI output are defined in @file{ly/@/performer@/-init@/.ly}.
1797 @node MIDI instrument names
1798 @subsection MIDI instrument names
1800 @cindex instrument names
1801 @cindex @code{Staff.midiInstrument}
1803 The MIDI instrument name is set by the @code{Staff.midiInstrument}
1804 property. The instrument name should be chosen from the list in
1805 @ref{MIDI instruments}.
1808 \set Staff.midiInstrument = "glockenspiel"
1812 If the selected instrument does not exactly match an instrument from
1813 the list of MIDI instruments, the Grand Piano (@code{"acoustic grand"})