A Newbie's Experiences with Lilypond, Lilypond-Book, LATEX
Total Page:16
File Type:pdf, Size:1020Kb
A newbie's experiences with Lilypond, Lilypond-book, LATEX and Perl Joe McCool Southern Regional College, Ireland mccoolj (at) src dot ac dot uk http://benburb.demon.co.uk/apache2-default/joe.html Abstract The author is an active Irish traditional musician. He is also a keen inland boater. He is having a lot of fun composing a book on \Traditional Music for Boaters". In this paper he describes his successes and frustrations using Lilypond, Lilypond-book, LATEX and ABC musical notation. Lilypond and LATEX have a lot in common. Neither are WYSIWYG, neither demand GUI's. Both compile simple flat files to produce beautiful graphical output. Lilypond's original manifestations produced output directly for LATEX, but of late users writing books have been encouraged to use Lilypond-book. This looks for Lilypond code within LATEX source files and produces graphics and associated instructions which can then be processed by LATEX. Most joy has come from automating these processes via GNU/Linux and Perl. 1 What's out there C:Franz Schubert By definition classical music has an inherent connec- O:Austria M:C| tion with books and text. Traditional music does not. L:1/8 Classical music is written down in scores. Histori- Q:1/4=160 cally, traditional music is not. It is largely an aural K:C medium and tunes are learnt by ear. Having said G2|"C"c2c2e2e2|"C"c4G2G2|"G"G3G dcBA|"G" that, musical scores do now have an important role G4 z2G2|"C"c2c2 e2e2|"C"c4G2c2|"G"B2AB to play. More and more young traditonal musicians .... are learning how to read scores. Printed material The K: field represents the tune's key. All lines allows us to store pieces that would otherwise be lost below this contain the music. Lines above are header and pencil and paper is a useful aid to composition. fields, with X: representing an index for this partic- Musicians like to share pieces and the arrival ular tune in a file of other ABC's. Notes in quotes of the personal computer has made this easier than represent accompaniment chords. ever. But, where years ago we popped manuscripts in At first sight ABC seems ideal for what I wish the post, we now need to share scores electronically. to do. It has a simple input format. It can output This has brought about a plethora of programs and PostScript files that I can incorporate into LATEX systems that enable us to do so. documents. ABC programs are open source and, ABC 1.1 ABC notation most importantly, there are huge collections of source files available on the internet. In the 1980's Chris Walshaw, then at the Univer- But, I have a few issues with ABC: sity of Cambridge, began writing out fragments of • there is a gross lack of standardisation. What folk/traditional tunes using letters to represent the standardisation exists is often ignored by the notes. This became gradually formalised into what authors of ABC files. is known as the ABC \standard".1 Numerous small programs have appeared to convert ASCII files of • I need a system comparable to LATEX in terms ABC to printed scores.2 There are also programs to of typesetting quality. ABC does not have the convert ABC code to midi. fine grained control of LATEX. Here's an example of an ABC file: • It is difficult to avoid clashing problems: note X: 1 heads clashing with bar numbers, or grace notes T:The trout clashing with accidentals. • At the time I started my project, the ABC mail- 1 www.walshaw.plus.com/abc 2 for example, moinejf.free.fr ing list seemed to vanish! 376 TUGboat, Volume 29 (2008), No. 3 | Proceedings of the 2008 Annual Meeting A newbie's experiences with Lilypond, Lilypond-book, LATEX and Perl 1.2 Commercially available software 1.5 Example Lilypond file Under Microsoft Windows, several commercial pro- \version "2.11.33" grams are available for typesetting music. Finale,3 \header { Sibelius,4 and Cakewalk5 are well known. Notewor- composer = "Joe Mc Cool" thy Composer is available as shareware.6 title = "The Eight Lock" dedication = "" 1.3 MusicTEX and MusiXTEX } voicedefault = { Both of these, based on what I could find out about \relative c' 7 them, appeared too complex for me. They did \clef treble not seem to have an active development or support \key g \major community. \time 4/4 \repeat volta 2 { 1.4 Lilypond \time 4/4 I rejected the commercial products and Notewor- \clef treble thy because they use proprietary file formats and d'4 d8 e d c b4 they rely on GUI interfaces. I am a traditional- .... ist in more ways than one. Long ago I realised the } \repeat volta 2 { power, elegance and beauty of plain ASCII files under 89 a'4 a8 a b c4. GNU/Linux. Hence my final choice of Lilypond. .... • Lilypond's originators have objectives very simi- } lar to those of LATEX: \to print music in the best } traditions of classical engraving with minimum \include "../new.score.ly" fuss". Notice the indentation of code, similar to pro- • Lilypond uses plain ASCII, not dissimilar to ABC. gramming languages. voicedefault is a musical object • Lilypond enjoys ongoing development. that will subsequently process as a score (see below), • Its documentation is excellent. or a midi file.10 • Very active user support via mailing lists. As my project gathered weight I got tired of • Very fast keying of source files: having to edit individual Lilypond files in order to { Note durations need stating once only. In change the overall look of my book, hence my use of the input a4 b, the notes a and b have the the include statement. new.score.ly consists of: same duration. \score{ { Notes can be raised an octave using a fol- << lowing ' or lowered by a following ,. Lily- { \voicedefault pond also provides a relative mode in } which it will position notes on the scale in >> a common sense, reasonable fashion. \layout{ \relative c'' { #(layout-set-staff-size 20) b c d c b c bes a } } } These notes will all be placed within the In order to change the overall look of all my scale, rather than climbing higher upward. pieces, for example to change the staff size, all I have • key transposition is easy: \transpose d e ... to do is edit the above. • The excitement and delight I found putting to- gether my first Lilypond scripts was matched 2 My approach only by that of my first LATEX scripts. Lilypond My approach is constrained by the following goals: and LATEX really are first cousins! • Each page should contain an integer number of 3 www.finalemusic.com tunes. Classical musicians are happy (or at least 4 www.sibelius.com willing) to turn a page in the middle of a piece, 5 www.cakewalk.com traditional musicians are not. 6 www.noteworthysoftware.com 7 www.tex.ac.uk/cgi-bin/texfaq2html?label=music • Traditional music is often played in sets. Two 8 www.lilypond.org or three jigs will be played one after the other, 9 In rural Ireland we have a saying: \If you think a donkey will do the job, use a horse!" 10 though midi support is regrettably not good in Lilypond. TUGboat, Volume 29 (2008), No. 3 | Proceedings of the 2008 Annual Meeting 377 Joe McCool or a group of hornpipes. When new tunes are Some text before a musical snippet. added to the collection, they must be kept as à j ¹ close together as possible to other members of ¹ ¹ ¹ their set, ideally on the same page, or on the Another snippet: same spread. à j ¹ ¹ ¹ ¹ • Brief texts and footnotes must appear on the Some more text. page of the tune to which they refer. Figure 1: small.pdf • Index entries must have the form `name : type : page number'. This reveals the page number Here the file small.tex constitutes the final and the tune type for each entry. output. This is then processsed by LATEX in the • The build process should produce midi files. normal way, with the result shown in Fig. 1. Lilypond-book creates a graphic for each line of 3 Combining Lilypond and LATEX music. It also creates a graphic for the whole snip- pet | in our small example, 2b589ef505-1.eps and Here is a simple example of a LATEX file (small.ly) containing Lilypond code: 2b589ef505.eps. My project has currently gath- ered about 200 tunes and the number of small files \documentclass{article} in OUTPUT hovers around 3500! \begin{document} Contents of OUTPUT/small.tex: \noindent Some text before a musical snippet.\\ \documentclass{article} \begin[quote,fragment]{lilypond} \usepackage{graphics} { \begin{document} c' e' g' e' \noindent } Some text before a musical snippet.\\ \end{lilypond} {% Another snippet:\\ \parindent 0pt% \begin[quote,fragment]{lilypond} \ifx\preLilyPondExample \undefined% { \relax% f' g' a' b' \else% } \preLilyPondExample% \end{lilypond} \fi% Some more text.\\ \def\lilypondbook{}% \end{document} \input lily-2b589ef505-systems.tex% This is processed by the command line: \ifx\postLilyPondExample \undefined% \relax% lilypond-book -f latex --psfonts \else% --output OUTPUT small.tex \postLilyPondExample% \fi% And in the OUTPUT directory Lilypond creates } the following files: Another snippet:\\ lily-2b589ef505-1.eps {% lily-2b589ef505.eps \parindent 0pt% lily-2b589ef505.ly \ifx\preLilyPondExample \undefined% lily-2b589ef505-systems.tex \relax% lily-2b589ef505-systems.texi \else% lily-2b589ef505.txt \preLilyPondExample% lily-eb070afcf7-1.eps \fi% lily-eb070afcf7.eps \def\lilypondbook{}% lily-eb070afcf7.ly \input lily-eb070afcf7-systems.tex% lily-eb070afcf7-systems.tex \ifx\postLilyPondExample \undefined% lily-eb070afcf7-systems.texi \relax% lily-eb070afcf7.txt \else% small.dep \postLilyPondExample% small.tex \fi% snippet-map.ly } snippet-names Some more text.\\ tmpMQ9ShM.aux \end{document} 378 TUGboat, Volume 29 (2008), No.