I am preparing a booklet using lilypond-book and have some snippets formatted with \begin{lilypond}[fragment]. These generally do what I want, but I would like to use some custom macros that I defined for chant formatting:

recitingNote = {
  \once \override NoteHead  #'stencil = #ly:text-interface::print
  \once \hide Stem
  \once \override NoteHead.text = \markup { \lower #0.5 \filled-box #'(0 . 6) #'(0 . 1) #0 }
  \once \override Dots.dot-count = #0

recitedText = {
  \once \override LyricText.self-alignment-X = #LEFT

I have these in a file named chant.lyinc, and in my usual full Lilypond documents I just \include "chant.lyinc" and am set. However, when I try it in fragment mode:

  \include "chant.lyinc"
  c'2 d'2 e'2 f'2

I get the errors

../chant.lyinc:1:1: error: not a note name: recitingNote

recitingNote = {
../chant.lyinc:1:14: error: syntax error, unexpected '='
             = {
../chant.lyinc:8:1: error: not a note name: recitedText

recitedText = {
../chant.lyinc:8:13: error: syntax error, unexpected '='
            = {

Clearly the fragment wrapper is preventing the usual definitions from taking place. How can I use my custom includes with fragment snippets?

1 Answer 1


The lilypond-book processor works by extracting fragments and wrapping them in a boilerplate .ly file. After the "cut-&-pastable-section", it opens a new music expression with {, uses \sourcefileline 123 to provide debugging tracing, blindly pastes the contents of the fragment, and closes the expression with }.

A hacky workaround to use custom functions is to close the provided music expression with no contents, include the custom definitions, and open a new music expression. This generates warnings and probably screws up debug reporting and who knows what else, but it sort-of works:

  } \include "chant.lyinc" {
  \recitingNote e'2 d'2 e'2 f'2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.