+Formatting rules are also preset variables: each object has variables
+containing procedures. These procedures perform the actual
+formatting, and by substituting different ones, we can change the
+appearance of objects. In the following example, the rule which note
+head objects use to produce their symbol is changed during the music
+fragment.
+
+@c FIXME: this example has errors:
+@c programming error: Grob `NoteHead' has no interface for property `text'
+@c Continuing; crossing fingers
+@lilypond[quote,raggedright]
+#(define (mc-squared grob orig current)
+ (let ((interfaces (ly:grob-property grob 'interfaces))
+ (pos (ly:grob-property grob 'staff-position)))
+ (if (and (memq 'note-head-interface interfaces)
+ (memq pos '(-2 -3 -5)))
+ (begin
+ (ly:grob-set-property! grob 'print-function brew-new-markup-stencil)
+ (ly:grob-set-property! grob 'font-family 'roman)
+ (ly:grob-set-property!
+ grob 'text
+ (make-raise-markup
+ -0.5
+ (case pos
+ ((-5) (make-simple-markup "m"))
+ ((-3) (make-simple-markup "c "))
+ ((-2) (make-smaller-markup (make-bold-markup "2")))
+ (else (make-simple-markup "bla")))))))))
+
+\new Voice \relative c' {
+ \stemUp
+ \set autoBeaming = ##f
+ \time 2/4
+ <d f g>4
+ \once \override NoteHead #'print-function = #Note_head::brew_ez_stencil
+ <d f g>
+ \once \override NoteHead #'style = #'cross
+ <d f g>
+ \applyoutput #mc-squared
+ <d f g>
+ <<
+ { d8[ es-( fis^^ g] fis2-) }
+ \repeat unfold 5 { \applyoutput #mc-squared s8 }
+ >>
+}
+@end lilypond
+
+
+
+@node What symbols to engrave?
+@section What symbols to engrave?
+
+@cindex engraving
+@cindex typography
+
+The formatting process decides where to place
+symbols. However, this can only be done once it is decided @emph{what}
+symbols should be printed, in other words what notation to use.
+
+Common music notation is a system of recording music that has evolved
+over the past 1000 years. The form that is now in common use dates
+from the early renaissance. Although the basic form (i.e., note heads on a
+5-line staff) has not changed, the details still change to express the
+innovations of contemporary notation. Hence, it encompasses some 500
+years of music. Its applications range from monophonic melodies to
+monstrous counterpoint for large orchestras.
+
+How can we get a grip on such a many-headed beast, and force it into
+the confines of a computer program? Our solution is break up the
+problem of notation (as opposed to engraving, i.e., typography) into
+digestible and programmable chunks: every type of symbol is handled by
+a separate module, a so-called plug-in. Each plug-in is completely
+modular and independent, so each can be developed and improved
+separately. Such plug-ins are called @code{engraver}, by analogy with
+craftsmen who translate musical ideas to graphic symbols.
+
+In the following example, we see how we start out with a plug-in for
+note heads, the @code{Note_heads_engraver}.
+
+@lilypond[quote,raggedright]
+\include "engraver-example.ily"
+
+\score {
+ \topVoice
+ \layout {
+ \context {
+ \Voice
+ \remove "Stem_engraver"
+ \remove "Phrasing_slur_engraver"
+ \remove "Slur_engraver"
+ \remove "Script_engraver"
+ \remove "Beam_engraver"
+ \remove "Auto_beam_engraver"
+ }
+ \context {
+ \Staff
+ \remove "Accidental_engraver"
+ \remove "Key_engraver"
+ \remove "Clef_engraver"
+ \remove "Bar_engraver"
+ \remove "Time_signature_engraver"
+ \remove "Staff_symbol_engraver"
+ \consists "Pitch_squash_engraver"
+ }
+}
+}
+@end lilypond
+
+@noindent
+Then a @code{Staff_symbol_engraver} adds the staff
+
+@lilypond[quote,raggedright]
+\include "engraver-example.ily"
+
+\score {
+ \topVoice
+ \layout {
+ \context {
+ \Voice
+ \remove "Stem_engraver"
+ \remove "Phrasing_slur_engraver"
+ \remove "Slur_engraver"
+ \remove "Script_engraver"
+ \remove "Beam_engraver"
+ \remove "Auto_beam_engraver"
+ }
+ \context {
+ \Staff
+ \remove "Accidental_engraver"
+ \remove "Key_engraver"
+ \remove "Clef_engraver"
+ \remove "Bar_engraver"
+ \consists "Pitch_squash_engraver"
+ \remove "Time_signature_engraver"
+ }
+ }
+}
+@end lilypond
+
+@noindent
+the @code{Clef_engraver} defines a reference point for the staff
+
+@lilypond[quote,raggedright]
+\include "engraver-example.ily"
+
+\score {
+ \topVoice
+ \layout {
+ \context {
+ \Voice
+ \remove "Stem_engraver"
+ \remove "Phrasing_slur_engraver"
+ \remove "Slur_engraver"
+ \remove "Script_engraver"
+ \remove "Beam_engraver"
+ \remove "Auto_beam_engraver"
+ }
+ \context {
+ \Staff
+ \remove "Accidental_engraver"
+ \remove "Key_engraver"
+ \remove "Bar_engraver"
+ \remove "Time_signature_engraver"
+ }
+ }
+}
+@end lilypond
+
+@noindent
+and the @code{Stem_engraver} adds stems.
+
+@lilypond[quote,raggedright]
+\include "engraver-example.ily"
+
+\score {
+ \topVoice
+ \layout {
+ \context {
+ \Voice
+ \remove "Phrasing_slur_engraver"
+ \remove "Slur_engraver"
+ \remove "Script_engraver"
+ \remove "Beam_engraver"
+ \remove "Auto_beam_engraver"
+ }
+ \context {
+ \Staff
+ \remove "Accidental_engraver"
+ \remove "Key_engraver"
+ \remove "Bar_engraver"
+ \remove "Time_signature_engraver"
+ }
+ }
+}
+@end lilypond
+
+The @code{Stem_engraver} is notified of any note head coming along.
+Every time one (or more, for a chord) note head is seen, a stem
+object is created and connected to the note head. By adding
+engravers for beams, slurs, accents, accidentals, bar lines,
+time signature, and key signature, we get a complete piece of
+notation.
+
+@lilypond[quote,raggedright]
+\include "engraver-example.ily"
+\score { \topVoice }
+@end lilypond
+
+This system works well for monophonic music, but what about
+polyphony? In polyphonic notation, many voices can share a staff.
+
+@lilypond[quote,raggedright]
+\include "engraver-example.ily"
+\new Staff << \topVoice \\ \botVoice >>
+@end lilypond
+
+In this situation, the accidentals and staff are shared, but the stems,
+slurs, beams, etc., are private to each voice. Hence, engravers should
+be grouped. The engravers for note heads, stems, slurs, etc., go into a
+group called `Voice context,' while the engravers for key, accidental,
+bar, etc., go into a group called `Staff context.' In the case of
+polyphony, a single Staff context contains more than one Voice context.
+Similarly, more Staff contexts can be put into a single Score
+context. The Score context is the top level notation context.
+
+@seealso
+
+Program reference: @internalsref{Contexts}.
+
+@lilypond[quote,raggedright]
+\include "engraver-example.ily"
+\score {
+ <<
+ \new Staff << \topVoice \\ \botVoice >>
+ \new Staff << \pah \\ \hoom >>
+ >>
+}
+@end lilypond
+
+@node Music representation
+@section Music representation
+
+Ideally, the input format for any high-level formatting system is an
+abstract description of the content. In this case, that would be the
+music itself. This poses a formidable problem: how can we define what
+music really is? Instead of trying to find an answer, we have reversed
+the question. We write a program capable of producing sheet music,
+and adjust the format to be as lean as possible. When the format can
+no longer be trimmed down, by definition we are left with content
+itself. Our program serves as a formal definition of a music
+document.
+
+The syntax is also the user-interface for LilyPond, hence it is easy
+to type
+