1 #LyX 2.1 created this file. For more info see http://www.lyx.org/
6 \use_default_options true
10 \maintain_unincluded_children false
12 \language_package default
19 \font_default_family default
20 \use_non_tex_fonts false
26 \default_output_format default
28 \bibtex_command default
29 \index_command default
30 \paperfontsize default
33 \pdf_title "LilyPond-book and LyX"
34 \pdf_author "The LyX Team"
36 \pdf_bookmarksnumbered true
37 \pdf_bookmarksopen true
38 \pdf_bookmarksopenlevel 1
43 \pdf_pdfusetitle false
44 \pdf_quoted_options "linkcolor=blue,urlcolor=blue,pdfstartview=XYZ"
47 \use_package amsmath 1
48 \use_package amssymb 1
50 \use_package mathdots 1
51 \use_package mathtools 0
53 \use_package stackrel 0
54 \use_package stmaryrd 0
55 \use_package undertilde 0
57 \cite_engine_type numerical
61 \paperorientation portrait
75 \paragraph_separation indent
76 \paragraph_indentation default
77 \quotes_language english
80 \paperpagestyle default
81 \tracking_changes false
102 \begin_layout Abstract
103 This document explains and demonstrates the inclusion of musical snippets
104 in a LyX document, using the LilyPond syntax for music notation and the
105 LilyPond-book utility for processing.
108 \begin_layout Section
112 \begin_layout Standard
113 LilyPond is an open-source project that renders possible the creation of
114 beautiful computer-generated musical scores.
115 The project consists of a text-based music notation language, and a program
116 to process this notation into musical scores.
119 \begin_layout Standard
120 While LilyPond itself supports the display of title, author information,
121 footnotes, endnotes, etc., its primary focus is on music typesetting.
122 For text typesetting, other programs are generally better suited.
123 LilyPond-book is an utility provided by the LilyPond project that helps
124 incorporate musical scores using the LilyPond notation into LaTeX documents,
128 \begin_layout Standard
129 This document describes the use of the LilyPond music notation within LyX
130 documents that use a LaTeX-based layout, thus combining the beauty and
131 quality of the typesetting achieved by both LaTeX and LilyPond.
132 While a basic understanding of the LilyPond syntax for music notation is
133 in order, knowledge of LaTeX is not necessary when using LyX.
136 \begin_layout Standard
138 \begin_inset CommandInset ref
140 reference "sec:Using-LilyPond-code"
144 explains the requirements, usage instructions, and shortcomings of LilyPond
145 music notation within LyX.
147 \begin_inset CommandInset ref
149 reference "sec:LilyPond-examples"
153 demonstrates the beauty and quality of the typesetting with a few examples.
156 \begin_layout Section
157 Using LilyPond code within LyX
158 \begin_inset CommandInset label
160 name "sec:Using-LilyPond-code"
167 \begin_layout Standard
168 Support for LilyPond music notation (LilyPond code) within LyX is enabled
169 by adding the LilyPond module to your document.
170 This is done from the menu
172 Document\SpecialChar \menuseparator
175 , then selecting LilyPond in the list of modules.
176 You can use any LaTeX-based LyX layout and use the regular preview and
177 export mechanism; LyX will take care of processing the mixed LaTeX/LilyPond
178 code through LilyPond-book for you.
179 LilyPond-book can also handle DocBook and HTML documents, but the integration
180 of these document types with LilyPond-book and LyX is missing at the moment.
183 \begin_layout Subsection
187 \begin_layout Standard
188 LilyPond-book version 2.13 or newer.
192 \begin_layout Plain Layout
193 LilyPond-book supports LaTeX output since version 2.1.
194 However, some features used by LyX are available only in recent versions:
195 PDFLaTeX support (version 2.9), the
199 flag (version 2.11) and especially the
211 \begin_layout Subsection
215 \begin_layout Standard
216 The module provides a LilyPond inset which you insert from the menu
218 Insert\SpecialChar \menuseparator
226 This inset is for typing the LilyPond code which will be typeset into your
228 First, let us try a simple scale:
231 \begin_layout Standard
232 \begin_inset Flex LilyPond
235 \begin_layout Plain Layout
237 \begin_inset Argument 1
240 \begin_layout Plain Layout
249 \begin_layout Plain Layout
256 \begin_layout Plain Layout
261 \begin_layout Plain Layout
271 \begin_layout Standard
273 The previous LyX inset produces the following LaTeX-lookalike code:
276 \begin_layout LyX-Code
279 begin{lilypond}[staffsize=28]
282 \begin_layout LyX-Code
286 \begin_layout LyX-Code
292 \begin_layout LyX-Code
296 \begin_layout LyX-Code
300 \begin_layout LyX-Code
306 \begin_layout Standard
307 What appear first inside square brackets are options to pass to LilyPond-book.
308 This is inserted in LyX from the
312 menu, in the same way that the LilyPond inset itself is inserted.
313 Here, we set the dimension of the staff to 28
314 \begin_inset space \thinspace{}
318 Other options can be added by separating them by a comma, for example:
321 [staffsize=28,verbatim]
324 A list of music fragment options is available in the LilyPond documentation.
325 This whole block can be omitted when the default settings are desired.
328 \begin_layout Standard
329 What follows after the options block is the textual representation in LilyPond
330 syntax of a musical fragment.
331 This code is not, in fact, processed by LaTeX, but is preprocessed by LilyPond-
332 book, which creates the graphics files and includes them in the LaTeX document
333 by replacing the above with a
337 includegraphics{\SpecialChar \ldots{}
343 \begin_layout Standard
344 Thus, the conversion process is as follow:
346 LyX\SpecialChar \menuseparator
347 LilyPond-book\SpecialChar \menuseparator
351 LyX creates a .lytex file, LilyPond-book creates a .tex files and the accompanyin
352 g image files, and LaTeX creates the final document.
353 Every step of the tool chain obeys your spacing, so whether you put the
354 musical extract inline, or in its own paragraph, centered, left-aligned,
355 etc., what you see in the LyX window should be respected in the final format.
356 An example of inline use may be to display a chord name, such as
357 \begin_inset Flex LilyPond
360 \begin_layout Plain Layout
362 \begin_inset Argument 1
365 \begin_layout Plain Layout
385 , or perhaps a very short snippet.
388 \begin_layout Subsection
392 \begin_layout Standard
393 It is possible to have a direct feedback of what the music notation looks
394 like from within LyX.
395 To do this, wrap a LilyPond inset inside a Preview inset, which you find
398 Insert\SpecialChar \menuseparator
402 This only affects the display within LyX, not the output:
405 \begin_layout Standard
408 \begin_layout Standard
409 \begin_inset Flex LilyPond
412 \begin_layout Plain Layout
419 \begin_layout Plain Layout
424 \begin_layout Plain Layout
439 \begin_layout Standard
440 Unfortunately, you might find that the preview isn't exactly instantaneous.
441 You need to move the cursor out of the Preview inset to start compilation,
442 and processing time can take a few seconds.
443 Nevertheless, the direct feedback is often worthwhile during editing, and
444 renders the navigation through the document much easier.
447 \begin_layout Subsection
451 \begin_layout Standard
452 A few gotchas that have been experienced with the integration of LilyPond-book
453 and LyX are reported here.
456 \begin_layout Subsubsection
460 \begin_layout Standard
461 A LyX document using the LilyPond module cannot have child documents using
463 \begin_inset Quotes eld
467 \begin_inset Quotes erd
472 \begin_inset Quotes eld
476 \begin_inset Quotes erd
480 \begin_inset Quotes eld
484 \begin_inset Quotes erd
489 Insert\SpecialChar \menuseparator
490 File\SpecialChar \menuseparator
497 , you will get an error when producing output.
498 This is due to the way LilyPond-book automatically processes these input
500 Since there is currently no command-line option to turn off this behavior
501 of LilyPond-book, it is suggested to use the
502 \begin_inset Quotes eld
506 \begin_inset Quotes erd
512 \begin_layout Standard
513 Note that it is possible to insert child documents which make use of the
514 LilyPond module, using either the
515 \begin_inset Quotes eld
519 \begin_inset Quotes erd
523 \begin_inset Quotes eld
527 \begin_inset Quotes erd
530 method, in a master document which does not make use of the LilyPond module.
531 For this to work you might have to add the line
534 \begin_layout LyX-Code
540 \begin_layout Standard
541 to your master document's preamble under
543 Document\SpecialChar \menuseparator
549 \begin_layout Subsubsection
553 \begin_layout Standard
554 LilyPond-book searches for a
566 command when it decides if the code is only a fragment.
567 It is possible to include no LilyPond command at all, but in that case
568 {surrounding braces} are required.
569 Thus, in the following code,
572 \begin_layout LyX-Code
578 \begin_layout LyX-Code
584 \begin_layout LyX-Code
590 \begin_layout Standard
591 LilyPond-book gets confused:
594 \begin_layout LyX-Code
595 error: syntax error, unexpected NOTENAME_PITCH
598 \begin_layout LyX-Code
604 \begin_layout Standard
605 With surrounding braces, all is well:
608 \begin_layout Standard
611 \begin_layout Standard
612 \begin_inset Flex LilyPond
615 \begin_layout Plain Layout
617 {ais' f'' g' e''} % no
632 \begin_layout Standard
633 Writing the notes directly within braces without using any LilyPond command
634 is convenient when writing short snippets.
635 Advanced users will probably want to enter their musical content using
636 LilyPond variables and commands, which is of course supported.
639 \begin_layout Subsubsection
643 \begin_layout Standard
644 Another gotcha is with subsequent LilyPond snippets with
653 \begin_layout LyX-Code
659 \begin_layout LyX-Code
664 fret-diagram-terse #"x;3;2;o;1;o;" }
667 \begin_layout LyX-Code
673 \begin_layout LyX-Code
677 \begin_layout LyX-Code
683 \begin_layout LyX-Code
688 fret-diagram-terse #"x;x;o;2;3;2;" }
691 \begin_layout LyX-Code
697 \begin_layout Standard
698 For some reason LilyPond-book version 2.13 barks on this when run in safe
699 mode (which you always should use, unless you know what you are doing).
700 This has been corrected as of version 2.15 (was LilyPond issue #1900).
703 \begin_layout Subsubsection
713 \begin_layout Standard
714 LilyPond-book supports including LilyPond code that resides in external
722 With this command, the LilyPond code is processed as if it was typed inside
723 the document and the output score follows the typesetting determined by
724 LaTeX with respect to line width, page breaks, and so on.
725 This is in contrast to the long-standing LyX feature to include LilyPond
726 scores as external material, which calls LilyPond on the external file
727 to produce a rigid figure, and includes this figure in the document, leaving
728 the typesetting decisions to LilyPond.
729 Unfortunately, support for the
735 command in LyX is not implemented yet, but it is possible to use it inside
736 a TeX-Code block, provided that one writes the complete, absolute path
740 \begin_layout Section
742 \begin_inset CommandInset label
744 name "sec:LilyPond-examples"
751 \begin_layout Standard
753 \begin_inset CommandInset ref
755 reference "sub:Editorial-headword"
759 shows a complex score using many LilyPond constructs; some scheme code
760 has been removed from the original source of this snippet, to be able to
763 \begin_inset CommandInset ref
765 reference "sub:Tablatures-template"
769 shows another LilyPond output which should be interesting to guitarists.
772 \begin_layout Subsection
774 \begin_inset CommandInset label
776 name "sub:Editorial-headword"
783 \begin_layout Standard
784 NR 1.7 Editorial annotations Beethoven, Op.
786 3 Piano sonata 18, Movt II, Scherzo Measures 9--14.
789 \begin_layout Standard
794 \begin_layout Standard
795 \begin_inset Flex LilyPond
798 \begin_layout Plain Layout
805 \begin_layout Plain Layout
810 \begin_layout Plain Layout
815 \begin_layout Plain Layout
822 \begin_layout Plain Layout
829 \begin_layout Plain Layout
838 \begin_layout Plain Layout
845 \begin_layout Plain Layout
849 set Staff.fingeringOrientations = #'(up)
852 \begin_layout Plain Layout
856 set Score.currentBarNumber = #9
859 \begin_layout Plain Layout
866 \begin_layout Plain Layout
873 \begin_layout Plain Layout
878 \begin_layout Plain Layout
882 set doubleSlurs = ##t
885 \begin_layout Plain Layout
890 \begin_layout Plain Layout
897 \begin_layout Plain Layout
904 \begin_layout Plain Layout
913 \begin_layout Plain Layout
918 \begin_layout Plain Layout
925 \begin_layout Plain Layout
930 \begin_layout Plain Layout
935 \begin_layout Plain Layout
942 \begin_layout Plain Layout
949 \begin_layout Plain Layout
954 \begin_layout Plain Layout
959 \begin_layout Plain Layout
964 \begin_layout Plain Layout
970 override Script #'script-priority = #-100
973 \begin_layout Plain Layout
980 \begin_layout Plain Layout
991 \begin_layout Plain Layout
996 \begin_layout Plain Layout
1001 \begin_layout Plain Layout
1006 \begin_layout Plain Layout
1011 \begin_layout Plain Layout
1018 \begin_layout Plain Layout
1025 \begin_layout Plain Layout
1030 \begin_layout Plain Layout
1035 \begin_layout Plain Layout
1040 \begin_layout Plain Layout
1045 \begin_layout Plain Layout
1050 \begin_layout Plain Layout
1055 \begin_layout Plain Layout
1062 \begin_layout Plain Layout
1071 \begin_layout Plain Layout
1078 \begin_layout Plain Layout
1082 override Fingering #'direction = #down
1085 \begin_layout Plain Layout
1089 set Staff.fingeringOrientations = #'(down)
1092 \begin_layout Plain Layout
1099 \begin_layout Plain Layout
1106 \begin_layout Plain Layout
1110 set doubleSlurs = ##t
1113 \begin_layout Plain Layout
1118 \begin_layout Plain Layout
1125 \begin_layout Plain Layout
1132 \begin_layout Plain Layout
1139 \begin_layout Plain Layout
1146 \begin_layout Plain Layout
1151 \begin_layout Plain Layout
1155 set doubleSlurs = ##f
1158 \begin_layout Plain Layout
1163 \begin_layout Plain Layout
1168 \begin_layout Plain Layout
1175 \begin_layout Plain Layout
1182 \begin_layout Plain Layout
1187 \begin_layout Plain Layout
1192 \begin_layout Plain Layout
1197 \begin_layout Plain Layout
1204 \begin_layout Plain Layout
1215 \begin_layout Plain Layout
1220 \begin_layout Plain Layout
1225 \begin_layout Plain Layout
1230 \begin_layout Plain Layout
1235 \begin_layout Plain Layout
1242 \begin_layout Plain Layout
1249 \begin_layout Plain Layout
1254 \begin_layout Plain Layout
1259 \begin_layout Plain Layout
1264 \begin_layout Plain Layout
1269 \begin_layout Plain Layout
1274 \begin_layout Plain Layout
1288 \begin_layout Standard
1291 \begin_inset Flex URL
1294 \begin_layout Plain Layout
1296 http://lsr.dsi.unimi.it/LSR/Item?id=627
1301 ; scheme code removed, centering applied through the paragraph settings]
1304 \begin_layout Subsection
1306 \begin_inset CommandInset label
1308 name "sub:Tablatures-template"
1315 \begin_layout Standard
1316 \begin_inset Preview
1318 \begin_layout Standard
1319 \begin_inset Flex LilyPond
1322 \begin_layout Plain Layout
1329 \begin_layout Plain Layout
1335 \begin_layout Plain Layout
1340 \begin_layout Plain Layout
1347 \begin_layout Plain Layout
1352 \begin_layout Plain Layout
1357 \begin_layout Plain Layout
1364 \begin_layout Plain Layout
1371 \begin_layout Plain Layout
1375 new Staff = "guitar" <<
1378 \begin_layout Plain Layout
1382 context Voice = "upper guitar" {
1391 \begin_layout Plain Layout
1395 context Voice = "lower guitar" {
1404 \begin_layout Plain Layout
1409 \begin_layout Plain Layout
1413 new TabStaff = "tab" <<
1416 \begin_layout Plain Layout
1420 context TabVoice = "upper tab" {
1429 \begin_layout Plain Layout
1433 context TabVoice = "lower tab" {
1442 \begin_layout Plain Layout
1447 \begin_layout Plain Layout
1452 \begin_layout Plain Layout
1467 \begin_layout Standard
1470 \begin_inset Flex URL
1473 \begin_layout Plain Layout
1475 http://lsr.dsi.unimi.it/LSR/Item?id=634