* Soprano and cello::
* Four-part SATB vocal score::
* Building a score from scratch::
+* Saving typing with variables and functions::
* Scores and parts::
@end menu
@end lilypond
+@node Saving typing with variables and functions
+@subsection Saving typing with variables and functions
+
+@cindex variables
+@cindex variables
+
+By this point, you've seen this kind of thing:
+
+@lilypond[quote,verbatim,ragged-right]
+hornNotes = \relative c'' { c4 b dis c }
+\score {
+ {
+ \hornNotes
+ }
+}
+@end lilypond
+
+You may even realize that this could be useful in minimalist music:
+
+@lilypond[quote,verbatim,ragged-right]
+fragmentA = \relative c'' { a4 a8. b16 }
+fragmentB = \relative c'' { a8. gis16 ees4 }
+violin = \new Staff { \fragmentA \fragmentA \fragmentB \fragmentA }
+\score {
+ {
+ \violin
+ }
+}
+@end lilypond
+
+However, you can also use these variables (also known as
+variables, macros, or (user-defined) command) for tweaks:
+
+@c TODO Avoid padtext - not needed with skylining
+@lilypond[quote,verbatim,ragged-right]
+dolce = \markup{ \italic \bold dolce }
+padText = { \once \override TextScript #'padding = #5.0 }
+fthenp=_\markup{ \dynamic f \italic \small { 2nd } \hspace #0.1 \dynamic p }
+violin = \relative c'' {
+ \repeat volta 2 {
+ c4._\dolce b8 a8 g a b |
+ \padText
+ c4.^"hi there!" d8 e' f g d |
+ c,4.\fthenp b8 c4 c-. |
+ }
+}
+\score {
+ {
+ \violin
+ }
+\layout{ragged-right=##t}
+}
+@end lilypond
+
+These variables are obviously useful for saving
+typing. But they're worth considering even if you
+only use them once -- they reduce complexity. Let's
+look at the previous example without any
+variables. It's a lot harder to read, especially
+the last line.
+
+@example
+violin = \relative c'' @{
+ \repeat volta 2 @{
+ c4._\markup@{ \italic \bold dolce @} b8 a8 g a b |
+ \once \override TextScript #'padding = #5.0
+ c4.^"hi there!" d8 e' f g d |
+ c,4.\markup@{ \dynamic f \italic \small @{ 2nd @}
+ \hspace #0.1 \dynamic p @} b8 c4 c-. |
+ @}
+@}
+@end example
+
+@c TODO Replace the following with a better example -td
+@c Skylining handles this correctly without padText
+
+So far we've seen static substitution -- when LilyPond
+sees @code{\padText}, it replaces it with the stuff that
+we've defined it to be (ie the stuff to the right of
+@code{padtext=}).
+
+LilyPond can handle non-static substitution, too (you
+can think of these as functions).
+
+@lilypond[quote,verbatim,ragged-right]
+padText =
+#(define-music-function (parser location padding) (number?)
+ #{
+ \once \override TextScript #'padding = #$padding
+ #})
+
+\relative c''' {
+ c4^"piu mosso" b a b
+ \padText #1.8
+ c4^"piu mosso" d e f
+ \padText #2.6
+ c4^"piu mosso" fis a g
+}
+@end lilypond
+
+Using variables is also a good way to reduce work if the
+LilyPond input syntax changes (see @ref{Updating old input files}). If
+you have a single definition (such as @code{\dolce}) for all your
+input files (see @ref{Style sheets}), then if the syntax changes, you
+only need to update your single @code{\dolce} definition,
+instead of making changes throughout every @code{.ly} file.
+
+
@node Scores and parts
@subsection Scores and parts
@menu
* Other uses for tweaks::
* Using variables for tweaks::
+* Style sheets::
* Other sources of information::
* Avoiding tweaks with slower processing::
* Advanced tweaks with Scheme::
@end lilypond
+@node Style sheets
+@subsection Style sheets
+
+The output that LilyPond produces can be heavily modified; see
+@ref{Tweaking output}, for details. But what if you have many
+input files that you want to apply your tweaks to? Or what if you
+simply want to separate your tweaks from the actual music? This
+is quite easy to do.
+
+Let's look at an example. Don't worry if you don't understand
+the parts with all the @code{#()}. This is explained in
+@ref{Advanced tweaks with Scheme}.
+
+@lilypond[quote,verbatim,ragged-right]
+mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
+ #:line(#:dynamic "mp" #:text #:italic "dolce" )))
+
+inst = #(define-music-function (parser location string) (string?)
+ (make-music
+ 'TextScriptEvent
+ 'direction UP
+ 'text (markup #:bold (#:box string))))
+
+\relative c'' {
+ \tempo 4=50
+ a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
+ \inst "Clarinet"
+ cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
+}
+@end lilypond
+
+There are some problems with overlapping output; we'll fix those using
+the techniques in @ref{Moving objects}. But let's also
+do something about the @code{mpdolce} and @code{inst}
+definitions. They produce the output we desire, but we might want
+to use them in another piece. We could simply copy-and-paste them
+at the top of every file, but that's an annoyance. It also leaves
+those definitions in our input files, and I personally find all
+the @code{#()} somewhat ugly. Let's hide them in another file:
+
+@example
+%%% save this to a file called "definitions.ily"
+mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
+ #:line(#:dynamic "mp" #:text #:italic "dolce" )))
+
+inst = #(define-music-function (parser location string) (string?)
+ (make-music
+ 'TextScriptEvent
+ 'direction UP
+ 'text (markup #:bold (#:box string))))
+@end example
+
+We will refer to this file using the @code{\include} command near
+the top of the music file. (The extension @code{.ily} is used to
+distinguish this included file, which is not meant to be compiled
+on its own, from the main file.)
+Now let's modify our music (let's save this file as @file{"music.ly"}).
+
+@c We have to do this awkward example/lilypond-non-verbatim
+@c because we can't do the \include stuff in the manual.
+
+@example
+\include "definitions.ily"
+
+\relative c'' @{
+ \tempo 4=50
+ a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
+ \inst "Clarinet"
+ cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
+@}
+@end example
+
+@lilypond[quote,ragged-right]
+mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
+ #:line(#:dynamic "mp" #:text #:italic "dolce" )))
+
+inst = #(define-music-function (parser location string) (string?)
+ (make-music
+ 'TextScriptEvent
+ 'direction UP
+ 'text (markup #:bold (#:box string))))
+
+\relative c'' {
+ \tempo 4=50
+ a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
+ \inst "Clarinet"
+ cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
+}
+@end lilypond
+
+That looks better, but let's make a few changes. The glissando is hard
+to see, so let's make it thicker and closer to the note heads. Let's
+put the metronome marking above the clef, instead of over the first
+note. And finally, my composition professor hates @q{C} time signatures,
+so we'd better make that @q{4/4} instead.
+
+Don't change @file{music.ly}, though. Replace our @file{definitions.ily}
+with this:
+
+@example
+%%% definitions.ily
+mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
+ #:line( #:dynamic "mp" #:text #:italic "dolce" )))
+
+inst = #(define-music-function (parser location string) (string?)
+ (make-music
+ 'TextScriptEvent
+ 'direction UP
+ 'text (markup #:bold (#:box string))))
+
+\layout@{
+ \context @{ \Score
+ \override MetronomeMark #'extra-offset = #'(-9 . 0)
+ \override MetronomeMark #'padding = #'3
+ @}
+ \context @{ \Staff
+ \override TimeSignature #'style = #'numbered
+ @}
+ \context @{ \Voice
+ \override Glissando #'thickness = #3
+ \override Glissando #'gap = #0.1
+ @}
+@}
+@end example
+
+@lilypond[quote,ragged-right]
+mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
+ #:line( #:dynamic "mp" #:text #:italic "dolce" )))
+
+inst = #(define-music-function (parser location string) (string?)
+ (make-music
+ 'TextScriptEvent
+ 'direction UP
+ 'text (markup #:bold (#:box string))))
+
+\layout{
+ \context { \Score
+ \override MetronomeMark #'extra-offset = #'(-9 . 0)
+ \override MetronomeMark #'padding = #'3
+ }
+ \context { \Staff
+ \override TimeSignature #'style = #'numbered
+ }
+ \context { \Voice
+ \override Glissando #'thickness = #3
+ \override Glissando #'gap = #0.1
+ }
+}
+
+\relative c'' {
+ \tempo 4=50
+ a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
+ \inst "Clarinet"
+ cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
+}
+@end lilypond
+
+That looks nicer! But now suppose that I want to publish this
+piece. My composition professor doesn't like @q{C} time
+signatures, but I'm somewhat fond of them. Let's copy the
+current @file{definitions.ily} to @file{web-publish.ily} and
+modify that. Since this music is aimed at producing a pdf which
+will be displayed on the screen, we'll also increase the
+overall size of the output.
+
+@example
+%%% definitions.ily
+mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
+ #:line( #:dynamic "mp" #:text #:italic "dolce" )))
+
+inst = #(define-music-function (parser location string) (string?)
+ (make-music
+ 'TextScriptEvent
+ 'direction UP
+ 'text (markup #:bold (#:box string))))
+
+#(set-global-staff-size 23)
+\layout@{
+ \context @{ \Score
+ \override MetronomeMark #'extra-offset = #'(-9 . 0)
+ \override MetronomeMark #'padding = #'3
+ @}
+ \context @{ \Staff
+ @}
+ \context @{ \Voice
+ \override Glissando #'thickness = #3
+ \override Glissando #'gap = #0.1
+ @}
+@}
+@end example
+
+@lilypond[quote,ragged-right]
+mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
+ #:line( #:dynamic "mp" #:text #:italic "dolce" )))
+
+inst = #(define-music-function (parser location string) (string?)
+ (make-music
+ 'TextScriptEvent
+ 'direction UP
+ 'text (markup #:bold (#:box string))))
+
+#(set-global-staff-size 23)
+\layout{
+ \context { \Score
+ \override MetronomeMark #'extra-offset = #'(-9 . 0)
+ \override MetronomeMark #'padding = #'3
+ }
+ \context { \Voice
+ \override Glissando #'thickness = #3
+ \override Glissando #'gap = #0.1
+ }
+}
+
+\relative c'' {
+ \tempo 4=50
+ a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
+ \inst "Clarinet"
+ cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
+}
+@end lilypond
+
+Now in our music, I simply replace
+@code{\include "definitions.ily"} with
+@code{\include "web-publish.ily"}. Of course, we could make this
+even more convenient. We could make a @file{definitions.ily} file which
+contains only the definitions of @code{mpdolce} and @code{inst}, a
+@file{web-publish.ily} file which contains only the @code{\layout}
+section listed above, and a @file{university.ily} file which
+contains only the tweaks to produce the output that my professor
+prefers. The top of @file{music.ly} would then look like this:
+
+@example
+\include "definitions.ily"
+
+%%% Only uncomment one of these two lines!
+\include "web-publish.ily"
+%\include "university.ily"
+@end example
+
+This approach can be useful even if you are only producing
+one set of parts. I use half a dozen different
+@q{style sheet} files for my projects. I begin every music
+file with @code{\include "../global.ily"}, which contains
+
+@example
+%%% global.ily
+\version @w{"@version{}"}
+#(ly:set-option 'point-and-click #f)
+\include "../init/init-defs.ly"
+\include "../init/init-layout.ly"
+\include "../init/init-headers.ly"
+\include "../init/init-paper.ly"
+@end example
+
@node Other sources of information
@subsection Other sources of information
* General suggestions::
* Typesetting existing music::
* Large projects::
-* Saving typing with variables and functions::
-* Style sheets::
@end menu
@end itemize
-@node Saving typing with variables and functions
-@subsection Saving typing with variables and functions
-
-@cindex variables
-@cindex variables
-
-By this point, you've seen this kind of thing:
-
-@lilypond[quote,verbatim,ragged-right]
-hornNotes = \relative c'' { c4 b dis c }
-\score {
- {
- \hornNotes
- }
-}
-@end lilypond
-
-You may even realize that this could be useful in minimalist music:
-
-@lilypond[quote,verbatim,ragged-right]
-fragmentA = \relative c'' { a4 a8. b16 }
-fragmentB = \relative c'' { a8. gis16 ees4 }
-violin = \new Staff { \fragmentA \fragmentA \fragmentB \fragmentA }
-\score {
- {
- \violin
- }
-}
-@end lilypond
-
-However, you can also use these variables (also known as
-variables, macros, or (user-defined) command) for tweaks:
-
-@lilypond[quote,verbatim,ragged-right]
-dolce = \markup{ \italic \bold dolce }
-padText = { \once \override TextScript #'padding = #5.0 }
-fthenp=_\markup{ \dynamic f \italic \small { 2nd } \hspace #0.1 \dynamic p }
-violin = \relative c'' {
- \repeat volta 2 {
- c4._\dolce b8 a8 g a b |
- \padText
- c4.^"hi there!" d8 e' f g d |
- c,4.\fthenp b8 c4 c-. |
- }
-}
-\score {
- {
- \violin
- }
-\layout{ragged-right=##t}
-}
-@end lilypond
-
-These variables are obviously useful for saving
-typing. But they're worth considering even if you
-only use them once -- they reduce complexity. Let's
-look at the previous example without any
-variables. It's a lot harder to read, especially
-the last line.
-
-@example
-violin = \relative c'' @{
- \repeat volta 2 @{
- c4._\markup@{ \italic \bold dolce @} b8 a8 g a b |
- \once \override TextScript #'padding = #5.0
- c4.^"hi there!" d8 e' f g d |
- c,4.\markup@{ \dynamic f \italic \small @{ 2nd @}
- \hspace #0.1 \dynamic p @} b8 c4 c-. |
- @}
-@}
-@end example
-
-@c TODO Replace the following with a better example -td
-@c Skylining handles this correctly without padText
-
-So far we've seen static substitution -- when LilyPond
-sees @code{\padText}, it replaces it with the stuff that
-we've defined it to be (ie the stuff to the right of
-@code{padtext=}).
-
-LilyPond can handle non-static substitution, too (you
-can think of these as functions).
-
-@lilypond[quote,verbatim,ragged-right]
-padText =
-#(define-music-function (parser location padding) (number?)
- #{
- \once \override TextScript #'padding = #$padding
- #})
-
-\relative c''' {
- c4^"piu mosso" b a b
- \padText #1.8
- c4^"piu mosso" d e f
- \padText #2.6
- c4^"piu mosso" fis a g
-}
-@end lilypond
-
-Using variables is also a good way to reduce work if the
-LilyPond input syntax changes (see @ref{Updating old input files}). If
-you have a single definition (such as @code{\dolce}) for all your
-input files (see @ref{Style sheets}), then if the syntax changes, you
-only need to update your single @code{\dolce} definition,
-instead of making changes throughout every @code{.ly} file.
-
-
-@node Style sheets
-@subsection Style sheets
-
-The output that LilyPond produces can be heavily modified; see
-@ref{Tweaking output}, for details. But what if you have many
-input files that you want to apply your tweaks to? Or what if you
-simply want to separate your tweaks from the actual music? This
-is quite easy to do.
-
-Let's look at an example. Don't worry if you don't understand
-the parts with all the @code{#()}. This is explained in
-@ref{Advanced tweaks with Scheme}.
-
-@lilypond[quote,verbatim,ragged-right]
-mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
- #:line(#:dynamic "mp" #:text #:italic "dolce" )))
-
-inst = #(define-music-function (parser location string) (string?)
- (make-music
- 'TextScriptEvent
- 'direction UP
- 'text (markup #:bold (#:box string))))
-
-\relative c'' {
- \tempo 4=50
- a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
- \inst "Clarinet"
- cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
-}
-@end lilypond
-
-There are some problems with overlapping output; we'll fix those using
-the techniques in @ref{Moving objects}. But let's also
-do something about the @code{mpdolce} and @code{inst}
-definitions. They produce the output we desire, but we might want
-to use them in another piece. We could simply copy-and-paste them
-at the top of every file, but that's an annoyance. It also leaves
-those definitions in our input files, and I personally find all
-the @code{#()} somewhat ugly. Let's hide them in another file:
-
-@example
-%%% save this to a file called "definitions.ily"
-mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
- #:line(#:dynamic "mp" #:text #:italic "dolce" )))
-
-inst = #(define-music-function (parser location string) (string?)
- (make-music
- 'TextScriptEvent
- 'direction UP
- 'text (markup #:bold (#:box string))))
-@end example
-
-We will refer to this file using the @code{\include} command near
-the top of the music file. (The extension @code{.ily} is used to
-distinguish this included file, which is not meant to be compiled
-on its own, from the main file.)
-Now let's modify our music (let's save this file as @file{"music.ly"}).
-
-@c We have to do this awkward example/lilypond-non-verbatim
-@c because we can't do the \include stuff in the manual.
-
-@example
-\include "definitions.ily"
-
-\relative c'' @{
- \tempo 4=50
- a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
- \inst "Clarinet"
- cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
-@}
-@end example
-
-@lilypond[quote,ragged-right]
-mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
- #:line(#:dynamic "mp" #:text #:italic "dolce" )))
-
-inst = #(define-music-function (parser location string) (string?)
- (make-music
- 'TextScriptEvent
- 'direction UP
- 'text (markup #:bold (#:box string))))
-
-\relative c'' {
- \tempo 4=50
- a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
- \inst "Clarinet"
- cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
-}
-@end lilypond
-
-That looks better, but let's make a few changes. The glissando is hard
-to see, so let's make it thicker and closer to the note heads. Let's
-put the metronome marking above the clef, instead of over the first
-note. And finally, my composition professor hates @q{C} time signatures,
-so we'd better make that @q{4/4} instead.
-
-Don't change @file{music.ly}, though. Replace our @file{definitions.ily}
-with this:
-
-@example
-%%% definitions.ily
-mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
- #:line( #:dynamic "mp" #:text #:italic "dolce" )))
-
-inst = #(define-music-function (parser location string) (string?)
- (make-music
- 'TextScriptEvent
- 'direction UP
- 'text (markup #:bold (#:box string))))
-
-\layout@{
- \context @{ \Score
- \override MetronomeMark #'extra-offset = #'(-9 . 0)
- \override MetronomeMark #'padding = #'3
- @}
- \context @{ \Staff
- \override TimeSignature #'style = #'numbered
- @}
- \context @{ \Voice
- \override Glissando #'thickness = #3
- \override Glissando #'gap = #0.1
- @}
-@}
-@end example
-
-@lilypond[quote,ragged-right]
-mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
- #:line( #:dynamic "mp" #:text #:italic "dolce" )))
-
-inst = #(define-music-function (parser location string) (string?)
- (make-music
- 'TextScriptEvent
- 'direction UP
- 'text (markup #:bold (#:box string))))
-
-\layout{
- \context { \Score
- \override MetronomeMark #'extra-offset = #'(-9 . 0)
- \override MetronomeMark #'padding = #'3
- }
- \context { \Staff
- \override TimeSignature #'style = #'numbered
- }
- \context { \Voice
- \override Glissando #'thickness = #3
- \override Glissando #'gap = #0.1
- }
-}
-
-\relative c'' {
- \tempo 4=50
- a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
- \inst "Clarinet"
- cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
-}
-@end lilypond
-
-That looks nicer! But now suppose that I want to publish this
-piece. My composition professor doesn't like @q{C} time
-signatures, but I'm somewhat fond of them. Let's copy the
-current @file{definitions.ily} to @file{web-publish.ily} and
-modify that. Since this music is aimed at producing a pdf which
-will be displayed on the screen, we'll also increase the
-overall size of the output.
-
-@example
-%%% definitions.ily
-mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
- #:line( #:dynamic "mp" #:text #:italic "dolce" )))
-
-inst = #(define-music-function (parser location string) (string?)
- (make-music
- 'TextScriptEvent
- 'direction UP
- 'text (markup #:bold (#:box string))))
-
-#(set-global-staff-size 23)
-\layout@{
- \context @{ \Score
- \override MetronomeMark #'extra-offset = #'(-9 . 0)
- \override MetronomeMark #'padding = #'3
- @}
- \context @{ \Staff
- @}
- \context @{ \Voice
- \override Glissando #'thickness = #3
- \override Glissando #'gap = #0.1
- @}
-@}
-@end example
-
-@lilypond[quote,ragged-right]
-mpdolce = #(make-dynamic-script (markup #:hspace 0 #:translate '(5 . 0)
- #:line( #:dynamic "mp" #:text #:italic "dolce" )))
-
-inst = #(define-music-function (parser location string) (string?)
- (make-music
- 'TextScriptEvent
- 'direction UP
- 'text (markup #:bold (#:box string))))
-
-#(set-global-staff-size 23)
-\layout{
- \context { \Score
- \override MetronomeMark #'extra-offset = #'(-9 . 0)
- \override MetronomeMark #'padding = #'3
- }
- \context { \Voice
- \override Glissando #'thickness = #3
- \override Glissando #'gap = #0.1
- }
-}
-
-\relative c'' {
- \tempo 4=50
- a4.\mpdolce d8 cis4--\glissando a | b4 bes a2
- \inst "Clarinet"
- cis4.\< d8 e4 fis | g8(\! fis)-. e( d)-. cis2
-}
-@end lilypond
-
-Now in our music, I simply replace
-@code{\include "definitions.ily"} with
-@code{\include "web-publish.ily"}. Of course, we could make this
-even more convenient. We could make a @file{definitions.ily} file which
-contains only the definitions of @code{mpdolce} and @code{inst}, a
-@file{web-publish.ily} file which contains only the @code{\layout}
-section listed above, and a @file{university.ily} file which
-contains only the tweaks to produce the output that my professor
-prefers. The top of @file{music.ly} would then look like this:
-
-@example
-\include "definitions.ily"
-
-%%% Only uncomment one of these two lines!
-\include "web-publish.ily"
-%\include "university.ily"
-@end example
-
-This approach can be useful even if you are only producing
-one set of parts. I use half a dozen different
-@q{style sheet} files for my projects. I begin every music
-file with @code{\include "../global.ily"}, which contains
-
-@example
-%%% global.ily
-\version @w{"@version{}"}
-#(ly:set-option 'point-and-click #f)
-\include "../init/init-defs.ly"
-\include "../init/init-layout.ly"
-\include "../init/init-headers.ly"
-\include "../init/init-paper.ly"
-@end example
-
-
@node When things don't work
@section When things don't work