Debian Codegraph @

texmf-dist/doc/latex/latex4musicians/latex4musicians.tex

raw
1 % latex4musicians.tex -*- LaTeX -*-
2 %
3 % By Guido Gonzato, PhD <guido.gonzato (at) gmail.com>
4 %
5 % Last updated: January 19, 2019
6
7 % \RequirePackage[l2tabu,orthodox]{nag} % LaTeX syntax check
8
9 \documentclass[a4paper,12pt]{article}
10 \usepackage{etoolbox} % fix alltt
11 \usepackage{fancyhdr} % fancy headers
12 \usepackage{metalogo} % LaTeX logos
13 \usepackage{wasysym} % for \twonotes
14 \usepackage{graphicx} % include PDF files
15 \usepackage[colorlinks,%
16 linkcolor=red,%
17 urlcolor=blue,%
18 filecolor=blue,%
19 breaklinks=true]%
20 {hyperref} % URLs and links
21 \urlstyle{same} % use the same font for links
22 \usepackage{setspace} % for sources
23 \usepackage{fancyvrb} % fancy verbatim
24 \usepackage{color} % for included pages
25 \pagecolor{white} % don't disrupt pdfpages
26 \usepackage{pdfpages} % include external pages
27 \usepackage[breakable]%
28 {tcolorbox} % shaded boxes
29 \usepackage{alltt} % for sources
30 \usepackage{textcomp} % for upquote
31 \usepackage{upquote} % fix ' in PDF output
32 \usepackage{boxedminipage} % for LaTeX examples
33
34 \include{params} % low-level formatting stuff
35 \pagestyle{fancy} % fancy headers
36
37 % -----
38
39 \begin{document}
40
41 \title{\LaTeX{} for {\huge\twonotes{}}usicians}
42
43 \author{Guido Gonzato, PhD}
44
45 \date{Version \version\\
46 \today}
47
48 \maketitle
49
50 \begin{center}
51 \includegraphics[width=\textwidth]{jingle.pdf}
52 \end{center}
53
54 \begin{abstract}
55
56 This guide shows how to create \LaTeX{} documents that include
57 several kinds of music elements, from very simple to quite complex.
58 Music features may consist of music symbols, song lyrics, guitar
59 chords diagrams, lead sheets, music excerpts, guitar tablatures,
60 multi-page scores.
61
62 Music can be produced directly by \TeX{} and \LaTeX{} using
63 packages, and also by external scorewriters. Major packages and
64 programs are listed and briefly described, providing ready-to-use
65 examples.
66
67 \end{abstract}
68
69 \tableofcontents
70 % \listoftables
71 % \listoffigures
72
73 \noteseparator
74
75 % -----
76
77 \section{Introduction}
78
79 ~ \hfill%
80 \begin{minipage}{0.7\linewidth}
81 \begin{quote}
82 [And] there is no such hobby that it cannot be combined with \LaTeX.
83
84 ~ \hfill --- \href{http://www.mychemistry.eu/2013/04/guitar-tablatures/}
85 {Clemens Niederberger}
86 \end{quote}
87 \end{minipage}
88
89 \bigskip
90
91 I'm a long-time and enthusiastic \LaTeX{} user, and I'm also an
92 amateur musician; I play folk music on wind instruments. Years ago, I
93 used \LaTeX{} to typeset my
94 \href{http://abcplus.sourceforge.net/#ABCGuide}{ABC notation tutorial}
95 that I'm still maintaining. Writing that tutorial, I included many PDF
96 music snippets along with the corresponding ABC sources, and I was
97 very satisfied with the result. (Hopefully, other people were
98 satisfied, too.)
99
100 Since then, I have become interested in other music notation
101 languages. I have come across many excellent programs and many great
102 packages I wasn't aware of; I have collected many music snippets and I
103 have taken notes. I must say that I'm impressed; there are plenty of
104 options for the musician who is also a \LaTeX{} user. In fact, \TeX{}
105 can typeset music by itself using extensions, such as the MusiX\TeX{}
106 family. Besides, \LaTeX{} can easily include music produced by other
107 scorewriters.
108
109 So, to write \LaTeX{} documents that include music we have to solve
110 two problems: how do we make the music in a suitable format? And how
111 do we combine the music with \LaTeX?
112
113 For my own self-training, and in the hope of doing something useful
114 for other musicians, I have decided to write this guide that explains
115 how to solve these problems in many ways. In particular, it shows how
116 to create documents that include many types of music information, from
117 very simple to quite complex:
118
119 \begin{itemize}
120
121 \item \hyperref[sec:musicsymbols]{music symbols}:
122 \begin{minipage}[c]{\linewidth}
123 \includegraphics{glyphs}
124 \end{minipage}
125
126 \item \hyperref[sec:songbooks]{song lyrics}:
127 \begin{minipage}[c]{\linewidth}
128 \includegraphics[width=2cm]{guitar}
129 \end{minipage}
130
131 \item \hyperref[sec:guitar]{guitar chord diagrams}:
132 \begin{minipage}[c]{\linewidth}
133 \includegraphics{gdiagram}
134 \end{minipage}
135
136 \item \hyperref[sec:sheetmusic]{sheet music}:
137 \begin{minipage}[c]{\linewidth}
138 \includegraphics{sheet}
139 \end{minipage}
140
141 \item \hyperref[sec:tablatures]{guitar tablatures}:
142 \begin{minipage}[c]{\linewidth}
143 \includegraphics{gtablature}
144 \end{minipage}
145
146 \item \hyperref[sec:multimedia]{multimedia files}:
147 \begin{minipage}[c]{\linewidth}
148 \href{run:jingle.midi}{\fbox{play me!}}
149 \end{minipage}
150
151 \item \hyperref[sec:sources]{notation sources}:
152 \hspace{1em}
153 \begin{boxedminipage}[c]{0.4\linewidth}
154 \begin{alltt}
155 \footnotesize
156 X: 1
157 L: 1/4
158 K: C
159 c G/G/ _AG|z !>!B!>!c z|]
160 \end{alltt}
161 \end{boxedminipage}
162
163 \end{itemize}
164
165 This guide aims to provide a roundup of available options, along with
166 ready-to-use examples. We will examine a few \TeX/\LaTeX{} packages
167 and several programs that produce high-quality music output; then we
168 will learn how to include the music (as PDF files, sound files, or
169 notation sources) in \LaTeX{} documents.
170
171 % -----
172
173 \subsection{Conventions}
174
175 This document is meant to be consulted in its PDF version (online, if
176 possible), rather than printed on paper. Hence, it uses many external
177 links.
178
179 Links are written in short form whenever possible; for instance, the
180 \pkgname{abc} package will be referred to as
181 \href{https://www.ctan.org/pkg/abc}{abc} instead of
182 \url{https://www.ctan.org/pkg/abc}.
183
184 Sources (\LaTeX{} or notation languages) are shown in a frame with a
185 light green background; the resulting PDF output, when applicable, has
186 a light gray background. Command line sessions are shown in a frame;
187 user commands are emphasised in boldface.
188
189 All software described in this guide is
190 \href{https://en.wikipedia.org/wiki/Free_and_open-source_software}%
191 {free and open source}.
192
193 % -----
194
195 \subsection{Preliminaries}
196
197 To begin with, we need a working \LaTeX{} system. I strongly recommend
198 that you install the latest release of
199 \href{https://www.tug.org/texlive/}{TeX Live}, which I used to typeset
200 this manual and all included examples on a GNU/Linux system (TeX Live
201 2018). Please note that on Debian-based GNU/Linux systems, and maybe
202 other distributions, the default TeX Live packages may be older. I
203 suppose that other \TeX{} distributions like
204 \href{https://miktex.org/}{MiKTeX} or
205 \href{http://www.tug.org/mactex/}{MacTeX} are just as good, but I have
206 no first-hand experience with them.
207
208 Secondly, we need a Bash-based command line environment; this is
209 provided by default in GNU/Linux and macOS systems. Windows users
210 should install the excellent \href{http://www.msys2.org/}{MSYS2}
211 platform.
212
213 In most cases, typesetting is done with the common \cmd{pdflatex}
214 command. Some packages, though, require the \XeLaTeX{} or \LuaLaTeX{}
215 engines. In this manual, \cmd{pdflatex} is the default command, unless
216 otherwise specified.
217
218 This manual is not meant to replace the documentation of the packages
219 and programs that it briefly describes. A few examples are provided to
220 get you started and to whet your appetite, but in most cases they
221 don't cover all available features. The package or program
222 documentation is the primary source of information you should refer
223 to.
224
225 % Good luck. Some programmers write awsome programs, but clearly
226 % don't know how to write good, useful, concise documentation.
227
228 Finally, I assume that you are reasonably familiar with \LaTeX. Should
229 you need some information, fine manuals and tutorials are available at
230 the \href{https://ctan.org/tex-archive/info/}{\LaTeX{} info page}.
231
232 % -----
233
234 \subsection{Adding Packages}
235
236 TeX Live provides a large number of packages, but in the following
237 sections we will deal with packages that may not be included in less
238 recent releases. Also, some features may be available in package
239 releases that are newer than those included in TeX Live. In these
240 cases, you will have to install the missing (or newer) package
241 manually. The procedure is simple:
242
243 \begin{enumerate}
244
245 \item create this directory structure:
246
247 \verb|$ mkdir -p $HOME/texmf/tex/latex|
248
249 new packages will be installed in this directory tree.
250
251 \item get the package (typically as a zip-compressed directory) from
252 your favourite CTAN mirror; let's call it \file{foo.zip}
253
254 \item unpack it in the right place:
255
256 \verb|$ mkdir $HOME/texmf/tex/latex/foo|
257
258 \verb|$ mv foo.zip $HOME/texmf/tex/latex/foo|
259
260 \verb|$ cd $HOME/texmf/tex/latex/foo ; unzip foo.zip|
261
262 \item if no \file{.sty} file exists, run the command
263 \cmd{latex foo.ins} or \cmd{latex foo.dtx} to create it;
264
265 \item run the command \cmd{texhash \$HOME/texmf}
266
267 \end{enumerate}
268
269 Package \pkgname{foo} is now accessible.
270
271 If you are installing a package that is newer than that in TeX Live
272 and want \LaTeX{} to use it, add this line to your \file{.bashrc}:
273
274 \begin{verbatim}
275 export TEXINPUTS=$HOME/texmf/tex//:
276 \end{verbatim}
277 % $
278
279 Please note the double \cmd{/} at the end. This line makes \TeX{}
280 search recursively in \file{\$HOME/texmf/tex/}, then it adds the
281 current value of \cmd{TEXINPUTS} (if any) to the search path.
282
283 % -----
284
285 \subsection{Including PDF files}
286
287 It's reasonable to assume that PDF is the most sensible format for
288 final output. PostScript, SVG, PNG and other formats will not be
289 considered, but it's easy to convert PDF files to these formats using
290 applications like \href{https://inkscape.org}{Inkscape} or
291 \href{https://www.imagemagick.org}{ImageMagick}.
292
293 Unless you create music directly using \pkgname{MusiXTeX} and related
294 packages (Section~\ref{sec:musixtex}), your \LaTeX{} document will
295 include music as PDF files. Such files can be short excerpts, i.e.\
296 smaller than a page, or span several pages. These files will be
297 included with the \ltx{includegraphics} command (package
298 \pkg{graphicx}) or with the \ltx{include\-pdf} command (package
299 \pkg{pdfpages}), respectively:
300
301 \begin{source}
302 \begin{verbatim}
303 \documentclass[oneside]{article}
304 \usepackage{graphicx}
305 \usepackage{pdfpages}
306 \usepackage[a4paper,margin=1.5cm]{geometry}
307
308 \begin{document}
309
310 This is a short excerpt:
311
312 \includegraphics[width=0.8\textwidth]{sample.pdf}
313
314 Let's now include several pages:
315
316 % pages=- means "all pages"
317 \includepdf[pages=-,pagecommand={},width=\textwidth]{music.pdf}
318
319 \end{document}
320 \end{verbatim}
321 \end{source}
322
323 I suggest that you read the excellent \pkg{epslatex} guide that
324 explains many details on alignment, size, rotation etc.\ of included
325 graphics files.
326
327 In the case of short excerpts, we need some means of cropping the PDF
328 to its actual contents (bounding box); PDF files, in fact, are usually
329 created as whole pages. Cropping the PDF is accomplished with the free
330 program \href{http://pdfcrop.sourceforge.net}{pdfcrop}, a very useful
331 Perl script that depends on
332 \href{https://www.ghostscript.com}{Ghostscript} and
333 \href{http://pdfedit.cz/en/index.html}{PDFedit}.
334
335 Given a file called \file{music.pdf}, we crop it with these commands:
336
337 \begin{screen}
338 $ \textbf{pdfcrop music.pdf}
339 PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
340 ==> 1 page written on \verb|`|music-crop.pdf'.
341 $ \textbf{mv -f music-crop.pdf music.pdf}
342 $ _
343 \end{screen}
344 % $
345
346 Pdfcrop doesn't work on MSYS2; moreover, MSYS2's Ghostscript package
347 lacks the \cmd{bbox} device. However, if you install the official
348 release of Ghostscript for Windows, you can use the following shell
349 script, \cmd{pdfcrop.sh}. It only works with single-page PDF files:
350
351 \begin{source}
352 \begin{verbatim}
353 #!/bin/sh
354
355 # pdfcrop.sh - for MSYS2 and GhostScript
356 # Guido Gonzato, PhD. GPL 2 or later.
357
358 MYSELF=$(basename $0)
359
360 if [ $# -eq 0 ] ; then
361 printf "Usage: ${MYSELF} <file.pdf>\n"
362 printf "This script uses 'gs' to crop a one-page pdf file.\n\n"
363 exit 1
364 fi
365
366 # GhostScript for Windows is installed in C:\Gs
367 GS=/c/gs/gs9.26/bin/gswin64c.exe
368 # GNU/Linux and others:
369 # GS=/usr/bin/gs
370 INPUT=$1
371 PDF=$(basename $1 .pdf)
372 OUTPUT=$PDF-crop.pdf
373 GSOPTS="-q -sDEVICE=bbox -dBATCH -dNOPAUSE"
374
375 # find out the bounding box
376 $GS $GSOPTS $INPUT 2>&1 | grep "%%B" > $PDF.bbox
377
378 # read bbox coordinates in variables
379 read tmp X1 Y1 X2 Y2 < $PDF.bbox
380
381 # write the output, cropped to bbox
382 $GS -q -o $OUTPUT \
383 -sDEVICE=pdfwrite \
384 -c "[ /CropBox [$X1 $Y1 $X2 $Y2] /PAGES pdfmark" \
385 -f $INPUT
386
387 /bin/rm -f $PDF.bbox
388
389 echo "$INPUT cropped to $OUTPUT"
390 \end{verbatim}
391 \end{source}
392
393 % $
394
395 % -----
396
397 \noteseparator
398
399 % -----
400
401 \section{Music Symbols}
402 \label{sec:musicsymbols}
403
404 The simplest music elements we may want to include in our documents
405 are music symbols (\emph{glyphs}). Standard \LaTeX{} only provides the
406 math mode commands \ltx{sharp}, \ltx{flat}, and \ltx{natural}:
407 $\sharp$ $\flat$ $\natural$. Additional glyphs are provided by several
408 packages; moreover, glyphs provided by music fonts are accessible via
409 \XeLaTeX{} and Lua\LaTeX.
410
411 % -----
412
413 \subsection{Using Packages}
414
415 The impressive
416 \href{http://tug.ctan.org/info/symbols/%
417 comprehensive/symbols-a4.pdf}%
418 {Comprehensive LaTeX Symbol List}, Section 7, lists packages that
419 provide a handful of music symbols: \pkg{textcomp}, \pkg{mnsymbol},
420 \pkg{fdsymbol}, \pkg{boisik}, \pkg{wasysym}, \pkg{stix}, and
421 \pkg{arev}.
422
423 More symbols are provided by \pkg{musicography}, \pkg{leadsheets}, and
424 \pkg{harmony}. These packages work with \cmd{pdflatex}, but still
425 provide a fairly limited number of glyphs. Besides, there could be
426 incompatibility between packages because of commands defined using the
427 same name.
428
429 % TODO: figure out what harmony glyphs are for...
430
431 % -----
432
433 \subsubsection{Package \pkg{musicography}}
434
435 This package may be missing in less recent releases of TeX Live, so
436 you might have to install it manually. If you only need a limited
437 number of glyphs, then \pkg{musicography} may do the job:
438
439 \begin{source}
440 \begin{verbatim}
441 \documentclass{article}
442 \usepackage{musicography}
443 \thispagestyle{empty} % no page number
444
445 \begin{document}
446
447 Musicography makes the music symbol font provided by MusiX\TeX\
448 available as text font and then uses it to define a number
449 of symbols:
450
451 \musFlat\ \musSharp\ \musNatural\ \musDoubleFlat\ \musDoubleSharp\
452 \musWhole\ \musHalf\ \musQuarter\ \musEighth\ \musSixteenth\
453 \musWholeDotted\ \musHalfDotted\ \musQuarterDotted\
454 \musEighthDotted\ \musSixteenthDotted\
455 \meterC\ \meterCutC\ \meterCThree\ \meterCThreeTwo\ \meterCZ\
456 \musMeter{7}{8}
457
458 \end{document}\end{verbatim}
459 \end{source}
460
461 \score{musicography}
462
463 % -----
464
465 \subsubsection{Package \pkg{leadsheets}}
466
467 If you only need a limited number of glyphs, then also
468 \pkg{leadsheets} may do the job:
469
470 \begin{source}
471 \begin{verbatim}
472 \documentclass{article}
473 \usepackage[minimal]{leadsheets}
474 \useleadsheetslibraries{musicsymbols}
475 \thispagestyle{empty}
476
477 \begin{document}
478
479 Leadsheets makes the music symbol font provided by MusiX\TeX\
480 available as text font and then uses it to define a number
481 of symbols:
482
483 \sharp\ \doublesharp\ \flat\ \doubleflat\ \natural\
484 \trebleclef\ \altoclef\ \bassclef\ \meterC\ \allabreve\
485 \meter{12}{8}\ \wholerest\ \halfrest\ \quarterrest\
486 \eighthrest\ \sixteenthrest\ \Break\ \normalbar\
487 \leftrepeat\ \rightrepeat\ \leftrightrepeat\ \doublebar\
488 \stopbar
489
490 \end{document}
491 \end{verbatim}
492 \end{source}
493
494 \score{glyphs_ls}
495
496 This package also provides the \ltx{writechord} command to typeset
497 chords:
498
499 \begin{source}
500 \begin{verbatim}
501 \documentclass[12pt]{article}
502 \usepackage[minimal]{leadsheets}
503 \useleadsheetslibraries{chords}
504 \thispagestyle{empty}
505
506 \begin{document}
507
508 Let's typeset some chords: \writechord{Bb7(#9)} \writechord{Bbb6}
509 \writechord{C#7(b9)} \writechord{C##13}
510
511 \end{document}
512 \end{verbatim}
513 \end{source}
514
515 \scoreshort{chords}
516
517 % -----
518
519 \subsubsection{Package \pkg{lilyglyphs}}
520
521 One of the most complete sources of music glyphs is the
522 \pkg{lilyglyphs} package. It provides all the symbols available in the
523 \href{http://lilypond.org/doc/v2.18/%
524 Documentation/notation/the-feta-font} {Emmentaler} music font, which
525 is used by the \href{http://lilypond.org}{LilyPond} scorewriter
526 (Section~\ref{sec:lilypond}). \pkgname{Lilyglyphs} only works with
527 \XeLaTeX{} and \LuaLaTeX, and is incompatible with
528 \pkgname{leadsheets} and \pkgname{MusiXTeX}. Available glyphs and
529 corresponding commands are listed in Section 3 of the package
530 \href{http://mirrors.ctan.org/macros/luatex/latex/lilyglyphs/%
531 documentation/lilyglyphs.pdf}{documentation}.
532
533 This is a very small example of what \pkgname{Lilyglyphs} provides:
534
535 \begin{source}
536 \begin{verbatim}
537 \documentclass{article}
538 \usepackage{fontspec}
539 \usepackage{lilyglyphs}
540 \thispagestyle{empty}
541
542 \begin{document}
543
544 Lilyglyphs makes the music symbol font provided by LilyPond available
545 as text font and then uses it to define a number of symbols, some
546 \clefGInline\ of which \clefCInline\ can be used \clefFInline\ inline:
547
548 clefs:~ \clefG\ \clefC\ \clefF\ ~time signatures:~
549 \lilyTimeC\ \lilyTimeCHalf\ \lilyTimeSignature{7}{8}\
550 ~accidentals:~ \sharp\ \flat\ \natural\ \doublesharp\ \flatflat\
551 ~rests:~ \wholeNoteRest\ \halfNoteRest\ \crotchetRest\
552 ~notes:~ \wholeNote\ \halfNote\ \halfNoteDown\ \quarterNote\
553 \quarterNoteDotted\
554 ~and much, much more.
555
556 \end{document}
557 \end{verbatim}
558 \end{source}
559
560 \score{lilyglyphs}
561
562 % -----
563
564 \subsection{Using Music Fonts}
565
566 The \XeLaTeX{} and Lua\LaTeX{} engines use Unicode input by default
567 and support OTF/TTF fonts. We can use these engines to print any
568 character provided by locally installed fonts; these can be listed
569 with the \cmd{fc-list} command, provided by the
570 \href{https://www.fontconfig.org/}{Fontconfig} software.
571
572 Some fonts are especially useful for music. Unicode-encoded fonts
573 provide \href{https://www.unicode.org/charts/PDF/U1D100.pdf}{music
574 symbols}, which we can find for instance in
575 \href{https://www.gnu.org/software/freefont/}{GNU FreeFont}. However,
576 a font standard for music applications called
577 \href{https://www.smufl.org}{SMuFL} has been developed.
578
579 Specifically, \href{https://www.smufl.org/fonts}{Bravura} is a free,
580 SMuFL-compliant music font that provides thousands of high-quality
581 music glyphs. Bravura is available in OpenType format as
582 \file{Bravura.otf} and \file{BravuraText.otf}; the first is used for
583 drawing music symbols in scores, the second for inserting music
584 symbols in text. Each glyph is mapped to a numerical code called
585 \emph{code point}; a comprehensive list of glyphs and the
586 corresponding code points is available at
587 \url{https://www.smufl.org/version}.
588
589 The following source shows how to use the glyphs provided by Bravura.
590 We can define new commands for commonly used glyphs, or directly use
591 the \ltx{char"XXXX} syntax to print Unicode characters specifying
592 their code point. The fonts are expected to be installed in
593 \path{/usr/share/fonts/}; if you install the fonts in a different
594 directory, you'll also have change the following source accordingly:
595
596 \begin{source}
597 \begin{verbatim}
598 \documentclass{article}
599 \usepackage{fontspec}
600 \thispagestyle{empty}
601 \newfontfamily\brtxt{BravuraText.otf}[Path=/usr/share/fonts/]
602 \newfontfamily\brv{Bravura.otf}[Path=/usr/share/fonts/]
603
604 \newcommand{\clefGi} {{\brtxt \char"E050}}
605 \newcommand{\clefCi} {{\brtxt \char"E05C}}
606 \newcommand{\clefFi} {{\brtxt \char"E062}}
607
608 \newcommand{\clefG} {{\brv \char"E050}}
609 \newcommand{\clefC} {{\brv \char"E05C}}
610 \newcommand{\clefF} {{\brv \char"E062}}
611 \newcommand{\timeC} {{\brv \char"E08A}}
612 \newcommand{\timeCHalf} {{\brv \char"E08B}}
613 \renewcommand{\flat} {{\brv \char"E260}}
614 \renewcommand{\natural} {{\brv \char"E261}}
615 \renewcommand{\sharp} {{\brv \char"E262}}
616 \newcommand{\wholeNote} {{\brv \char"E1D2}}
617 \newcommand{\halfNote} {{\brv \char"E1D3}}
618 \newcommand{\halfNoteDown}{{\brv \char"E1D4}}
619 \newcommand{\quarterNote} {{\brv \char"E1D5}}
620
621 \begin{document}
622
623 The Bravura and BravuraText Music fonts provide thousands of music
624 symbols. BravuraText glyphs are specifically \clefGi\ designed
625 \clefFi\ to be used \clefCi\ inline:
626
627 clefs:~ \clefG\ \clefC\ \clefF\ ~time signatures:~
628 \timeC\ \timeCHalf\ ~accidentals:~ \sharp\ \flat\ \natural\
629 ~notes:~ \wholeNote\ \halfNote\ \halfNoteDown\ \quarterNote\
630 ~and much, much more.
631
632 \end{document}
633 \end{verbatim}
634 \end{source}
635
636 \score{bravura}
637
638 % -----
639
640 \noteseparator
641
642 % -----
643
644 \section{Song Lyrics}
645 \label{sec:songbooks}
646
647 Several packages make it possible to typeset song lyrics, with varying
648 degrees of complexity. For instance, we may want to write lyrics only;
649 other useful features include chords above lyrics, guitar chords
650 diagrams, transposition, index generation, etc.
651
652 % -----
653
654 \subsection{Package \pkg{guitar}}
655 \label{sec:pkgguitar}
656
657 This is a very basic and simple to use package that provides a
658 \env{guitar} environment to add chords above lyrics. Customisation
659 options include alignment, spacing, font, and other low-level
660 details.
661
662 A minimal
663 example:
664
665 \begin{source}
666 \begin{verbatim}
667 \documentclass{article}
668 \thispagestyle{empty}
669 \usepackage{guitar}
670
671 \begin{document}
672
673 \begin{guitar}
674 \textbf{Imagine (John Lennon)}
675
676 \emph{Intro, $\times$ 2}
677 % use tilde to add some space
678 [C] ~ [Cmaj7] ~ [F] ~
679 % if chords overlap, add | at the end of the chord, like:
680 [C]Imagine there's [Cmaj7|]{no} [F]heaven
681 [C]It's easy if [Cmaj7|]{you} [F]try
682 [C]No hell [Cmaj7|]{below} [F]us
683 [C]Above us [Cmaj7|]{only} [F]sky
684 \end{guitar}
685
686 \end{document}
687 \end{verbatim}
688 \end{source}
689
690 \scoreshort{guitar}
691
692 % -----
693
694 \subsection{Package \pkg{gtrcrd}}
695
696 This is another basic and simple to use package. Customisation options
697 include chord location and name (Do-Re-Mi instead of C-D-E), font,
698 transposition, and spacing. Chords overlaps need manual adjustment.
699
700 \begin{source}
701 \begin{verbatim}
702 \documentclass{article}
703 \thispagestyle{empty}
704 \usepackage{gtrcrd}
705
706 \setlength{\crdheight}{2ex} % reduce spacing
707 \def\crdfont{\footnotesize \itshape \sffamily} % setchord font
708 \setlength{\parindent}{0pt} % no indentation
709
710 \begin{document}
711
712 \textbf{Imagine (John Lennon)}
713
714 \emph{Intro, $\times$ 2}
715
716 % if chords overlap, use \hspace:
717 \C {\hspace{3mm}} \C[maj7] {\hspace{10mm}} \F ~
718
719 \C Imagine there's \C[maj7] no {\hspace{5mm}} \F heaven
720
721 \C It's easy if \C[maj7] you {\hspace{2mm}} \F try
722
723 \C No hell \C[maj7] below \F us
724
725 \C Above us \C[maj7] only {\hspace{2mm}} \F sky
726 \end{document}
727 \end{verbatim}
728 \end{source}
729
730 \scoreshort{gtrcrd}
731
732 % -----
733
734 \subsection{Package \pkg{songs}}
735 \label{sec:pkgsongs}
736
737 This is a very powerful package that provides many features: chords
738 above lyrics, guitar chords diagrams (Section~\ref{sec:songs_cd}),
739 transposition, index generation, multiple columns, and more. Overall,
740 it allows for the creation of complete songbooks.
741
742 % \enlargethispage{\baselineskip}
743
744 \begin{source}
745 \begin{verbatim}
746 \documentclass{article}
747 \thispagestyle{empty}
748 \usepackage[chorded]{songs}
749
750 \begin{document}
751
752 \renewcommand{\lyricfont}{\small}
753 \renewcommand{\printchord}{\it\small}
754 \afterpreludeskip=-18pt
755 \beforepostludeskip=-8pt
756
757 \begin{songs}{}
758 \beginsong{Imagine}[by={John Lennon}]
759 \beginverse
760 \emph{Intro, $\times$ 2}
761 \[C] \[Cmaj7] \[F]
762 \[C]Imagine there's \[Cmaj7]no \[F]heaven
763 \[C]It's easy if \[Cmaj7]you \[F]try
764 \[C]No hell \[Cmaj7]below \[F]us
765 \[C]Above us \[Cmaj7]only \[F]sky
766 \endverse
767 \endsong
768 \end{songs}
769
770 \end{document}
771 \end{verbatim}
772 \end{source}
773
774 \scoreshort{songs}
775
776 % -----
777
778 \subsection{Package \pkg{musixguit}}
779
780 This package is integrated with \pkg{musixtex}
781 (Section~\ref{sec:musixtex}), and is also capable of producing sheet
782 music and guitar chord diagrams. Its documentation is written in
783 German; if you can't read it don't worry, the provided examples are
784 easy to understand. Chords overlaps need manual adjustment.
785
786 \begin{source}
787 \begin{verbatim}
788 \documentclass{article}
789 \usepackage{musixguit}
790 \thispagestyle{empty}
791
792 \begin{document}
793
794 \textbf{Imagine (John Lennon)}
795
796 \begin{song}
797
798 \emph{Intro, $\times$ 2}
799
800 \chord{C} ~ \chord{Cmaj7} {\hspace{8mm}} \chord{F}
801
802 \chord{C}Imagine there's \chord{Cmaj7}no~~~ \chord{F}heaven
803
804 \chord{C}It's easy if \chord{Cmaj7}you~~ \chord{F}try
805
806 \chord{C}No hell \chord{Cmaj7}below \chord{F}us
807
808 \chord{C}Above us \chord{Cmaj7}only~ \chord{F}sky
809
810 \end{song}
811
812 \end{document}
813 \end{verbatim}
814 \end{source}
815
816 \scoreshort{musixguit}
817
818 % -----
819
820 \subsection{Package \pkg{leadsheets}}
821 \label{sec:leadsheets}
822
823 This package provides many features: music and symbols, chords,
824 MuseJazz style, a \env{song} and a \env{verse} environment,
825 transposition, a \cmd{leadsheet} class, and templates. Overall, this
826 package allows for the creation of complete songbooks.
827
828 \begin{source}
829 \begin{verbatim}
830 \documentclass{article}
831 \usepackage[full]{leadsheets}
832 \thispagestyle{empty}
833
834 \begin{document}
835
836 \begin{song}{title={Imagine}, music={John Lennon}}
837 \begin{verse}
838
839 Intro, $\times$ 2\\
840 \chord{C}~ \chord{Cmaj7}~ \chord{F}~
841
842 % The ^ character is a shortcut for \chord
843 \chord{C}Imagine there's ^{Cmaj7}no ^{F}heaven \\
844 ^{C}It's easy if ^{Cmaj7}you ^{F}try \\
845 ^{C}No hell ^{Cmaj7}below ^{F}us \\
846 ^{C}Above us ^{Cmaj7}only ^{F}sky \\
847
848 \end{verse}
849 \end{song}
850
851 \end{document}
852 \end{verbatim}
853 \end{source}
854
855 \scoreshort{leadsheets}
856
857 % -----
858
859 \subsection{Package \pkg{songbook}}
860
861 This is another powerful package that provides support for chords,
862 songs, overhead transparencies, and index generation.
863
864 \begin{source}
865 \begin{verbatim}
866 \documentclass{article}
867 \usepackage[chordbk]{songbook}
868 \thispagestyle{empty}
869
870 \begin{document}
871
872 \textbf{Imagine (John Lennon)}
873
874 % \medskip
875
876 \emph{Intro, $\times$ 2}
877
878 \Ch{C}~ \Ch{Cmaj7}~ \Ch{F}~
879
880 \Ch{C}{Imagine} there's \Ch{Cmaj7}{no} \Ch{F}heaven
881
882 \Ch{C}{It's} easy if \Ch{Cmaj7}{you} \Ch{F}{try}
883
884 \Ch{C}No hell \Ch{Cmaj7}{below} \Ch{F}us
885
886 \Ch{C}{Above} us \Ch{Cmaj7}{only} \Ch{F}{sky}
887
888 \end{document}
889 \end{verbatim}
890 \end{source}
891
892 \scoreshort{songbook}
893
894 % -----
895
896 \subsection{Program: \href{https://www.vromans.org/projects/Chordii/}
897 {chordii}}
898
899 Chordii is a free command-line program, released under the
900 \href{https://www.gnu.org/licenses/licenses.en.html}{GNU GPL}. It uses
901 a simple text notation to typeset songs in PostScript format, complete
902 with chords and guitar chord grid.
903
904 This is the source of a song written in Chordii format:
905
906 \begin{source}
907 \begin{verbatim}
908 {titles:left}
909 {title:Imagine}
910 {st:John Lennon}
911
912 (Intro, x 2)
913 [C] [Cmaj7] [F]
914 [C]Imagine there's [Cmaj7]no [F]heaven
915 [C]It's easy if [Cmaj7]you [F]try
916 [C]No hell [Cmaj7]below [F]us
917 [C]Above us [Cmaj7]only [F]sky
918 \end{verbatim}
919 \end{source}
920
921 % \medskip
922
923 We typeset the score with these commands:
924
925 \begin{screen}
926 $ \textbf{chordii -a imagine.cho > imagine.ps}
927 $ \textbf{ps2pdf imagine.ps}
928 $ _
929 \end{screen}
930 % $
931
932 The \cmd{-a} switch means ``Automatic single space lines without
933 chords''. The resulting song is:
934
935 \bigskip
936
937 \scoreshort{chordii}
938
939 % -----
940
941 \noteseparator
942
943 % -----
944
945 \section{Guitar Chord Diagrams}
946 \label{sec:guitar}
947
948 Guitar players may need to print \emph{guitar chords diagrams} and
949 \emph{guitar tablatures}; both can be made with \LaTeX{} packages and
950 external programs. As a matter of fact, these music features are not
951 limited to the guitar; chord diagrams and tablatures apply to other
952 stringed instruments as well.
953
954 Tablatures are a form of music notation that is usually employed to
955 show how a \emph{melody} should be fingered on the fretboard. Since
956 tablatures are just a special form of music notation, we will deal
957 with them after the section about sheet music. For the moment, let's
958 see how to do guitar chord diagrams.
959
960 For an authoritative list of standard guitar chords diagrams, I
961 suggest that you visit \href{http://lilypond.org/doc/v2.18/%
962 Documentation/notation/predefined-fretboard-diagrams}{this useful
963 page}.
964
965 % -----
966
967 \subsection{Package \pkg{gchords}}
968 \label{sec:gchords}
969
970 This package makes it possible to print guitar chord diagrams using
971 the \ltx{chord} command that employs a simple syntax:
972
973 \medskip
974
975 \ltx{chord}{\emph{\{fret
976 number\}}}{\emph{\{fingering\}}}{\emph{\{chord name\}}}
977
978 \begin{itemize}
979
980 \item \emph{fret number} can be \texttt{\{t\}}, which means top
981 fret, or \texttt{\{t\}} followed by a digit that denotes the fret;
982
983 \item \emph{fingering} is explained in the example below;
984
985 \item \emph{chord name} is the given chord name.
986
987 \end{itemize}
988
989 The \ltx{chords} command prints a row of chords, each defined by a
990 \ltx{chord} command:
991
992 \begin{source}
993 \begin{verbatim}
994 \documentclass{article}
995 \usepackage{gchords}
996 \thispagestyle{empty}
997
998 \begin{document}
999
1000 \def\numfrets{4}
1001
1002 \chords{ % print a row of chords
1003 % fingers: n, x, o, p{n}, f{n}
1004 % C chord: finger 3 pos. 3, finger 2 pos. 2, finger 1 pos. 1
1005 \chord{t}{n,f3p3,f2p2,n,f1p1,n}{C}
1006 \chord{t}{n,n,p2,p2,p1,n}{Am}
1007 \chord{t}{x,n,n,p2,p3,p1}{Dm}
1008 \chord{t3}{n,p2,n,p1,n,n}{G7 (ugly)}
1009 {\tiny % font size for string labels, t{X}
1010 \chord{t}{t{E}n,t{A}n,t{D}n,t{G}n,t{B}n,t{e}n}
1011 {std. tuning} }
1012 }
1013
1014 \end{document}
1015 \end{verbatim}
1016 \end{source}
1017
1018 \scoreshort{gchords}
1019
1020 % -----
1021
1022 \subsection{Package \pkg{songs}}
1023 \label{sec:songs_cd}
1024
1025 We met this package in Section~\ref{sec:pkgsongs}. It provides an
1026 easy way to print guitar chord diagrams (referred to as ``guitar
1027 tablatures'' in the package). The \ltx{gtab} command defines chord
1028 diagrams using a very simple syntax:
1029
1030 \medskip
1031
1032 \ltx{gtab}{\emph{\{chord name\}}}
1033 {\emph{\{fret:strings:fingering\}}}
1034
1035 \begin{itemize}
1036
1037 \item \emph{chord name} is the given chord name;
1038
1039 \item \emph{fret} is an optional fret number;
1040
1041 \item \emph{strings} is a string of digits denoting the strings that
1042 compose the chord;
1043
1044 \item \emph{fingering} is an optional string of digits denoting the
1045 fingers to use.
1046
1047 \end{itemize}
1048
1049 \begin{source}
1050 \begin{verbatim}
1051 \documentclass{article}
1052 \thispagestyle{empty}
1053 \usepackage[chorded]{songs}
1054
1055 \begin{document}
1056
1057 % \gtab{chord name}{fret:strings:fingering}
1058 \gtab{C}{032010:032010} \gtab{Cmaj7}{032000:032000}
1059 \gtab{F}{1:022100}
1060
1061 \end{document}
1062 \end{verbatim}
1063 \end{source}
1064
1065 \scoreshort{songs_g}
1066
1067 % -----
1068
1069 \subsection{Package \pkg{guitarchordschemes}}
1070
1071 This package enables the creation of fully customisable guitar chord
1072 diagrams and scales. The main command is \ltx{chordscheme}, and is
1073 quite self-explanatory:
1074
1075 \begin{source}
1076 \begin{verbatim}
1077 \documentclass{article}
1078 \usepackage{guitarchordschemes}
1079 \thispagestyle{empty}
1080
1081 \begin{document}
1082
1083 % general parameters
1084 \setchordscheme{
1085 rotate=-90,
1086 x-unit=2.5mm, % chord size, x
1087 y-unit=3mm, % chord size, y
1088 name-format=\bfseries, % chord name font
1089 finger-format=\bfseries%
1090 \footnotesize % fingering font
1091 }
1092
1093 \newsavebox{\Gstd}
1094 \savebox{\Gstd}{
1095 \chordscheme[ % define the chord
1096 name = G (Sol), % chord name
1097 position = 1, % first fret position
1098 finger = {2/5:2} , % fret, string, finger
1099 finger = {3/6:3} , % fret, string, finger
1100 finger = {3/1:4} , % fret, string, finger
1101 ring = {2,3,4} % open strings
1102 ]}
1103
1104 \newsavebox{\Gbarre}
1105 \savebox{\Gbarre}{
1106 \chordscheme[
1107 name = G (Sol) barre,
1108 position = 3,
1109 barre = 1/1-6, % fret, string range
1110 finger = {2/3:2},
1111 finger = {3/5:3},
1112 finger = {3/4:4}
1113 ]}
1114
1115 \usebox{\Gstd}\usebox{\Gbarre}
1116
1117 \end{document}
1118 \end{verbatim}
1119 \end{source}
1120
1121 \scoreshort{gcschemes}
1122
1123 % -----
1124
1125 \noteseparator
1126
1127 % -----
1128
1129 \section{Sheet Music}
1130 \label{sec:sheetmusic}
1131
1132 In this section, we will learn how to produce sheet music in PDF
1133 format for inclusion in \LaTeX{} documents. Sheet music can be typeset
1134 by \TeX{} itself, but we can also use the output produced by one of
1135 the several free and open source scorewriters.
1136
1137 In the next few sections, we will briefly examine each option. Music
1138 notation languages will not be explained, for obvious space reasons.
1139 Minimal sources will be listed to give minimal working examples and to
1140 get acquainted with the notation complexity.
1141
1142 % -----
1143
1144 \subsection{Which Notation Software?}
1145
1146 I'm not going to suggest any particular music notation software. I do
1147 have my personal preferences; I find some notations easier than
1148 others; some programs have more features than others; and so on.
1149 Nevertheless, I think that all packages and programs described in the
1150 following sections have their advantages, and all of them can typeset
1151 beautiful scores. Unless you need specific features, choosing a
1152 typesetting software is mostly a matter of personal preference. Let's
1153 put it this way: the best program is the one that lets you obtain the
1154 results you need, with the least effort, in the least amount of time,
1155 and the most fun.
1156
1157 All software described below is capable of typesetting complex Western
1158 music: multiple voices and staves, symbols, dynamics, lyrics, text
1159 annotations; sone of them can also do tablatures and more.
1160
1161 % -----
1162
1163 \subsection{Packages \pkg{musixtex}, \pkg{m-tx}}
1164 \label{sec:musixtex}
1165
1166 In the beginning, \TeX{} could not typeset music, and everyone was
1167 unhappy. Then the \pkg{mtex} (aka \pkgname{MuTeX}) package was
1168 created, but it was limited and not very easy to use. Then
1169 \pkgname{MuTeX} begat \pkgname{MusicTeX}, which begat \pkg{pmtex};
1170 then \pkgname{MusicTeX} begat \pkg{musixtex}, which begat \pkg{pmx},
1171 which begat \pkg{m-tx}. I hope I got the storyline right. Each package
1172 was a simpler interface to its predecessors.
1173
1174 In reverse order: \pkgname{M-Tx} is a preprocessor to \pkgname{PMX},
1175 which in turn is a preprocessor for \pkgname{MusiXTeX}, which does the
1176 actual music typesetting via \TeX. It goes without saying that
1177 \pkgname{M-Tx} is the simplest to use, while \pkgname{MusiXTeX} is the
1178 most difficult to use but also the most powerful. Other packages
1179 related to \pkgname{MusiXTeX} are the following:
1180
1181 \begin{itemize}
1182
1183 \item \pkg{autosp} generates note-spacing commands for
1184 \pkgname{MusiXTeX} scores;
1185
1186 \item \pkg{bagpipe} provides support for typesetting bagpipe music;
1187
1188 \item \pkg{bizantinemusic} facilitates the writing of Byzantine
1189 music;
1190
1191 \item \pkg{figbas} provides mini fonts for figured bass notation in
1192 \pkgname{MusiXTeX};
1193
1194 \item \pkg{gregoriotex} provides engraving of Gregorian Chant
1195 (Section~\ref{sec:gregoriotex});
1196
1197 \item \pkg{lyluatex} provides commands to include LilyPond scores in
1198 Lua\LaTeX{} documents (Section~\ref{sec:lyluatex});
1199
1200 \item \pkg{musixtnt} is an extension library that enables
1201 transformations of the effect of notes commands;
1202
1203 \item \pkg{pmxchords} produces chord information to go with pmx
1204 output;
1205
1206 \item \pkg{snote} provides shape notes for \pkgname{MusixTeX};
1207
1208 \item \pkg{texmuse} is a music typesetting system using \TeX{}
1209 and Metafont.
1210
1211 \end{itemize}
1212
1213 From \pkg{musixtex} home page:
1214
1215 \begin{quote}
1216
1217 MusiXTEX provides a set of macros, based on the earlier MusicTEX,
1218 for typesetting music with \TeX.
1219
1220 \end{quote}
1221
1222 \pkgname{MusiXTeX} is quite low-level, and the user must take care of
1223 such details as beam slope and note spacing; several examples are
1224 available \href{https://ctan.org/tex-archive/macros/%
1225 musixtex/doc/examples}{here}. Notably, it works with plain \TeX. (Ever
1226 tried plain \TeX?) A minimal example (\file{sample-mtex.tex}):
1227
1228 \begin{source}
1229 \begin{verbatim}
1230 % bare MusiXTeX example
1231
1232 \input musixtex
1233 \nopagenumbers
1234
1235 \setstaffs1{1} % a single stave
1236 \setclef1{\treble} % with a treble clef
1237 \generalmeter{\meterC} % common time
1238 \nobarnumbers % what it says
1239 \startextract % a short music piece
1240 % \qu = quarter note, stem up;
1241 % \ql = quarter note, stem down;
1242 % \Notes, \en = start and end of note line
1243 \Notes \qu c \qu d \qu e \qu f \en
1244 \bar
1245 \Notes \qu g \qu{'a} \ql b \ql c \en
1246 \endextract
1247
1248 \end
1249 \end{verbatim}
1250 \end{source}
1251
1252 We typeset the score with these commands:
1253
1254 \begin{screen}
1255 $ \textbf{tex sample-mtex.tex}
1256 $ \textbf{dvips sample-mtex.dvi}
1257 $ \textbf{ps2pdf sample-mtex.ps}
1258 $ _
1259 \end{screen}
1260
1261 \scoreshort{sample-mtex}
1262
1263 \pkgname{MusiXTeX} input can also be embedded in \LaTeX{} documents
1264 (\file{sam\-ple-m\-la\-tex.tex}):
1265
1266 \begin{source}
1267 \begin{verbatim}
1268 \documentclass{article}
1269 \usepackage{musixtex}
1270 \thispagestyle{empty}
1271
1272 \begin{document}
1273
1274 A short music excerpt in MusiX\TeX:
1275
1276 \medskip
1277
1278 \begin{music}
1279 \smallmusicsize
1280 \instrumentnumber{1}
1281 \setstaffs1{1}
1282 \generalmeter{\meterC}
1283 \nobarnumbers
1284 \startextract
1285 % bar 1
1286 \Notes \qu c \en % C
1287 \notes \ibu1d2\qb1d\tbu1\qb1e \en % beamed DE
1288 \notes \ibu1g2\qb1f\qb1g%
1289 \qb1{'a}\tbu1\qb1b \en % beamed FGAB
1290 \bar % bar 2
1291 \Notes \ql{'c} \en % c
1292 \notes \ibu1{'b}{-3}%
1293 \qb1b\tbu1\qb1a \en % beamed BA
1294 \notes \ibu1{g}{-3}%
1295 \qb1g\qb1f\qb1e\tbu1\qb1d \en % beamed GFED
1296 \bar % bar 3
1297 \notes \ibu1f0\qb1c\qb1g\qb1e\tbu1\qb1g% % beamed CGEG
1298 \ibu1f0\qb1c\qb1g\qb1e\tbu1\qb1g \en % beamed CGEG
1299 \bar % bar 4
1300 \Notes \qu c\qu e\qu c\qp \en % CEC
1301 \endextract
1302
1303 \end{music}
1304
1305 \end{document}
1306 \end{verbatim}
1307 \end{source}
1308
1309 \score{sample-mlatex}
1310
1311 \bigskip
1312
1313 Admittedly it looks a bit arcane, and I'll point you to the
1314 \href{http://mirrors.ctan.org/macros/musixtex/doc/musixdoc.pdf}
1315 {documentation} for explanations. I suggest that you learn at least
1316 the basics of it; several useful packages are based on this syntax.
1317
1318 \pkgname{M-Tx} employs a much simpler notation than
1319 \pkgname{MusiXTeX}. This is a standalone music sample
1320 (\file{sample-mtx.mtx}) that produces the same music as the above
1321 \pkgname{MusiXTeX} score:
1322
1323 \begin{source}
1324 \begin{verbatim}
1325 % music sample in M-Tx notation
1326
1327 Title: \bigtype Music sample in M-tx
1328 Style: Solo
1329 Meter: C
1330 Width: 140mm
1331
1332 c4 d8 e f g a b | c4 b8 a g f e d | c8 g+ e g c- g+ e g | c4- e c r |
1333 \end{verbatim}
1334 \end{source}
1335
1336 We typeset the score with this command:
1337
1338 \begin{screen}
1339 $ \textbf{musixtex sample-mtx.mtx}
1340 This is musixtex.lua version 0.21.
1341 ==> This is M-Tx 0.63a (Music from TeXt) <8 April 2018>
1342 ==>> Input from file sample-mtx.mtx
1343 ...
1344 sample-mtx.pdf generated by ps2pdf.
1345 $ _
1346 \end{screen}
1347 % $
1348
1349 \noindent which produces \file{sample-mtx.pdf}. In older versions of
1350 \pkgname{M-Tx}, the command was \cmd{m-tx}; it has now been retired
1351 and replaced by \cmd{musixtex}. This is the resulting score:
1352
1353 \bigskip
1354
1355 \score{sample-mtx}
1356
1357 \bigskip
1358
1359 Music in \pkgname{M-Tx} format can be easily included in \LaTeX{}
1360 documents. \pkgname{M-Tx} provides the \env{Score}, \env{excerpts},
1361 and \env{mus} environments to include complete pieces, short excerpts,
1362 and inline short excerpts respectively. Let's see how to use
1363 \cmd{excerpts} and \cmd{mus}; a few steps are required.
1364
1365 First of all, the \LaTeX{} source that includes the \pkgname{M-Tx}
1366 music files must not have a \file{.tex} extension; \file{.ltx} or
1367 \file{.latex} are ok. Let's call our sample file
1368 \file{sample-latexmtx.ltx}.
1369
1370 Secondly, we need the \file{mtxlatex.sty} style file, which is not
1371 installed by default but is found in the \pkgname{M-Tx} documentation
1372 directory. In TeX Live, \file{mtxlatex.sty} is located in directory
1373 \path{/usr/share/doc/texlive-doc/generic/m-tx}. This file must be
1374 copied to the same directory as the source file; all included
1375 \pkgname{M-Tx} files must be copied there too.
1376
1377 We already met \file{sample-mtx.mtx}; the following is another short
1378 excerpt, \file{scale.mtx}. It produces a 30mm wide scale:
1379
1380 \begin{source}
1381 \begin{verbatim}
1382 Style: Solo
1383 Meter: C
1384 Size: 13pt
1385 Width: 30mm
1386
1387 c8 d e f g2 |
1388 \end{verbatim}
1389 \end{source}
1390
1391 Finally, this is the main file \file{sample-latexmtx.ltx}:
1392
1393 \begin{source}
1394 \begin{verbatim}
1395 \documentclass[12pt]{article}
1396 \usepackage{mtxlatex} % usually not installed
1397 \thispagestyle{empty}
1398
1399 \mtxlatex
1400
1401 \begin{document}
1402
1403 This \LaTeX{} document includes music written in M-Tx. The
1404 \texttt{mus} environment includes music inline:
1405 \begin{mus} \input{scale.tex} \end{mus} , while the
1406 \texttt{excerpts} environment is used for longer excerpts:
1407
1408 \medskip
1409
1410 \begin{excerpts}
1411 \input{sample-mtx.tex}
1412 \end{excerpts}
1413
1414 \end{document}
1415 \end{verbatim}
1416 \end{source}
1417
1418 We typeset the document with this command:
1419
1420 \begin{screen}
1421 $ \textbf{musixtex sample-mtx scale sample-latexmtx.ltx}
1422 ...
1423 sample-latexmtx.pdf generated by ps2pdf.
1424 $ _
1425 \end{screen}
1426 % $
1427
1428 Please note that we omitted the \pkgname{M-Tx} file extensions, and
1429 that the main file is the last in the command line. We obtain this
1430 output:
1431
1432 \bigskip
1433
1434 \score{sample-latexmtx}
1435
1436 \bigskip
1437
1438 Please also note that the \pkgname{M-Tx} excerpts cannot be resized as
1439 if they were included PDF files: their geometry, in fact, is set in
1440 the \pkgname{M-Tx} source.
1441
1442 % -----
1443
1444 \subsection{Package \pkg{gregoriotex}}
1445 \label{sec:gregoriotex}
1446
1447 This package typesets Gregorian chant. Input is in GABC format, a
1448 simple text notation inspired by the
1449 \href{http://abcnotation.com/}{ABC notation} that we'll examine later
1450 on. Conversion requires Lua\LaTeX.
1451
1452 This is a sample GABC source, \file{kyrie.gabc}, taken from the
1453 package documentation:
1454
1455 \begin{source}
1456 \begin{alltt}
1457 name:Kyrie XVII;
1458 %%
1459 (c4)KY(f)ri(gfg)e(h.) *()
1460 e(ixjvIH'GhvF'E)l\'e(ghg')i(g)son.(f.)
1461 <i>bis</i>(::)
1462 \end{alltt}
1463 \end{source}
1464
1465 We also need an auxiliary \LaTeX{} source, \file{kyrie.tex}:
1466
1467 \begin{source}
1468 \begin{verbatim}
1469 \documentclass{article}
1470 \thispagestyle{empty}
1471 \usepackage[autocompile]{gregoriotex}
1472
1473 \begin{document}
1474
1475 \gregorioscore{kyrie}
1476
1477 \end{document}
1478 \end{verbatim}
1479 \end{source}
1480
1481 We typeset the score with this command:
1482
1483 \begin{screen}
1484 $ \textbf{lualatex kyrie.tex}
1485 ...
1486 Output written on kyrie.pdf (1 page, 11290 bytes).
1487 Transcript written on kyrie.log.
1488 $ _
1489 \end{screen}
1490 % $
1491
1492 \scoreshort{kyrie}
1493
1494 % -----
1495
1496 \subsection{Program: \href{http://lilypond.org/}{LilyPond}}
1497 \label{sec:lilypond}
1498
1499 LilyPond is a free and multiplatform scorewriter, released under the
1500 GNU GPL. From the LilyPond home page:
1501
1502 \begin{quote}
1503
1504 LilyPond is a music engraving program, devoted to producing the
1505 highest-quality sheet music possible. It brings the aesthetics of
1506 traditionally engraved music to computer printouts. LilyPond is free
1507 software and part of the \href{http://gnu.org/}{GNU Project}.
1508
1509 \end{quote}
1510
1511 LilyPond uses a simple text notation for music input; output is PDF by
1512 default. This is our usual music sample in LilyPond format,
1513 \file{sample-lily\-pond.ly}:
1514
1515 \begin{source}
1516 \begin{verbatim}
1517 % music sample in LilyPond notation
1518
1519 \version "2.18.2"
1520
1521 \paper{
1522 indent = 0 \mm
1523 }
1524
1525 \header {
1526 title = "Music sample in LilyPond"
1527 tagline = "" % no footer
1528 }
1529
1530 \relative c' {
1531 \time 4/4
1532 \clef treble
1533 c4 d8 e f8 g a b | c4 b8 a g8 f e d |
1534 c8 g' e g c,8 g' e g | c,4 e c r \bar "|."
1535 }
1536 \end{verbatim}
1537 \end{source}
1538
1539 We typeset the document with this command:
1540
1541 \begin{screen}
1542 $ \textbf{lilypond sample-lilypond.ly}
1543 GNU LilyPond 2.18.2
1544 Processing `sample-lilypond.ly'
1545 Parsing...
1546 Interpreting music...
1547 Preprocessing graphical objects...
1548 Finding the ideal number of pages...
1549 Fitting music on 1 page...
1550 Drawing systems...
1551 Layout output to `sample-lilypond.ps'...
1552 Converting to `./sample-lilypond.pdf'...
1553 Success: compilation successfully completed
1554 $ _
1555 \end{screen}
1556 % $
1557
1558 \bigskip
1559
1560 LilyPond is capable of typesetting many different kinds of music, and
1561 it is among the most complete and powerful scorewriters available. If
1562 you want to find out more, the documentation page is
1563 \href{http://lilypond.org/manuals.html}{here}.
1564
1565 % -----
1566
1567 \subsubsection{\cmd{lilypond-book}}
1568
1569 LilyPond also provides the \cmd{lilypond-book} command that can be
1570 used to easily embed LilyPond sources in special \LaTeX{} documents.
1571 These should have a \cmd{.lytex} extension, like the following source
1572 (\cmd{sample-lilybook.lytex}):
1573
1574 \begin{source}
1575 \begin{verbatim}
1576 \documentclass{article}
1577 \thispagestyle{empty}
1578
1579 \begin{document}
1580
1581 This is a LilyPond snippet \begin{lilypond} {c' e' g'}
1582 \end{lilypond} embedded in the \LaTeX{} source.
1583
1584 This is another LilyPond excerpt that uses the \texttt{lilypond}
1585 environment:
1586
1587 \medskip
1588
1589 \begin{lilypond}
1590 \score {
1591 \relative c' {
1592 \time 4/4
1593 \clef treble
1594 c4 d8 e f8 g a b | c4 b8 a g8 f e d |
1595 c8 g' e g c,8 g' e g | c,4 e c r \bar "|."
1596 }
1597 } % end of score
1598 \end{lilypond}
1599
1600 \medskip
1601
1602 End of document.
1603
1604 \end{document}
1605
1606 \end{verbatim}
1607 \end{source}
1608
1609 We typeset the score with these commands:
1610
1611 \begin{screen}
1612 $ \textbf{lilypond-book -f latex -o /tmp \textbackslash
1613 --lily-output-dir=/tmp sample-lilybook.lytex}
1614 lilypond-book (GNU LilyPond) 2.18.2
1615 ...
1616 Writing `/tmp/sample-lilybook.tex'...
1617 $ \textbf{cd /tmp}
1618 $ \textbf{pdflatex sample-lilybook.tex}
1619 ...
1620 Output written on sample-lilybook.pdf (1 page, 60934 bytes).
1621 Transcript written on sample-lilybook.log.
1622 $ _
1623 \end{screen}
1624 % $
1625
1626 \bigskip
1627
1628 \score{sample-lilybook}
1629
1630 % -----
1631
1632 \subsubsection{Package \pkg{lyluatex}}
1633 \label{sec:lyluatex}
1634
1635 This package may be missing in less recent releases of TeX Live, so
1636 you might have to install it manually. \pkgname{Lyluatex} provides a
1637 native Lua\LaTeX{} environment that offers the same functionality as
1638 \cmd{lilypond-book}, even though the output is different. This source
1639 is \file{sample-lyluatex.tex}:
1640
1641 \begin{source}
1642 \begin{verbatim}
1643 \documentclass{article}
1644 \usepackage{lyluatex}
1645 \thispagestyle{empty}
1646
1647 \begin{document}
1648
1649 This is a LilyPond snippet \lilypond{c' e' g'} embedded in the text
1650 using the \verb|\lilypond| command.
1651
1652 This is another LilyPond excerpt that uses the \texttt{lilypond}
1653 environment:
1654
1655 \medskip
1656
1657 \begin{lilypond}
1658 \score {
1659 \relative c' {
1660 \time 4/4
1661 \clef treble
1662 c4 d8 e f8 g a b | c4 b8 a g8 f e d |
1663 c8 g' e g c,8 g' e g | c,4 e c r \bar "|."
1664 }
1665 } % end of score
1666 \end{lilypond}
1667
1668 \medskip
1669
1670 End of document.
1671
1672 \end{document}
1673 \end{verbatim}
1674 \end{source}
1675
1676 We typeset the score with this command:
1677
1678 \begin{screen}
1679 $ \textbf{lualatex --shell-escape sample-lyluatex.tex}
1680 ...
1681 Output written on sample-lyluatex.pdf (1 page, 22334 bytes).
1682 Transcript written on sample-lyluatex.log.
1683 $ _
1684 \end{screen}
1685 % $
1686
1687 \score{sample-lyluatex}
1688
1689 % -----
1690
1691 \subsection{Program: \href{http://moinejf.free.fr}{abcm2ps}}
1692
1693 \cmd{abcm2ps} is a free and multiplatform scorewriter, released under
1694 the GNU GPL.
1695
1696 This program is currently one of the best implementations of the
1697 \href{http://abcnotation.com/}{ABC notation}, which describes itself
1698 as:
1699
1700 \begin{quote}
1701
1702 \emph{the} text-based music notation system and the \emph{de
1703 facto} standard for folk and traditional music.
1704
1705 \end{quote}
1706
1707 In fact, this notation is specifically designed to meet the needs of
1708 traditional musicians; hundred of thousands (really!) of tunes in ABC
1709 formats are available. ABC is a simple text notation, originally
1710 designed for single-voice music but currently capable of producing
1711 complex polyphonic scores.
1712
1713 This is our usual music sample in ABC notation (\file{sample-abc.abc}):
1714
1715 \begin{source}
1716 \begin{verbatim}
1717 % music sample in ABC notation
1718
1719 X: 1
1720 T: Music sample in ABC
1721 M: C
1722 L: 1/4
1723 K: C
1724 %
1725 C D/E/ F/G/A/B/|c B/A/ G/F/E/D/|C/G/E/G/ C/G/E/G/|CECz|]
1726 \end{verbatim}
1727 \end{source}
1728
1729 We typeset the score with these commands:
1730
1731 \begin{screen}
1732 $ \textbf{abcm2ps -c -O= sample-abc.abc}
1733 abcm2ps-8.14.1 (2018-11-15)
1734 File sample-abc.abc
1735 Output written on sample-abc.ps (1 page, 1 title, 20503 bytes)
1736 $ \textbf{ps2pdf sample-abc.ps}
1737 $ _
1738 \end{screen}
1739 % $
1740
1741 % -----
1742
1743 \subsection{Program: \href{http://moinejf.free.fr}{abc2svg}}
1744
1745 \cmd{abc2svg} is a free and multiplatform scorewriter, released under
1746 the GNU GPL. It's basically \cmd{abcm2ps} rewritten in JavaScript.
1747
1748 Although \cmd{abc2svg} can be integrated in a
1749 \href{http://moinejf.free.fr/js/edit-1.xhtml}{web-based editor}, it's
1750 a command-line program. It reads an ABC source file and turns it to
1751 \file{xhtml}:
1752
1753 \begin{screen}
1754 $ \textbf{abc2svg file.abc > file.xhtml}
1755 $ _
1756 \end{screen}
1757
1758 The resulting \file{.xhtml} can then be loaded into any web browser
1759 and printed to PDF. \href{https://www.google.com/chrome}{Google
1760 Chrome} or \href{https://www.chromium.org/Home}{Chromium} are the
1761 recommended browsers.
1762
1763 We can run the whole procedure non-interactively, entirely in the
1764 command line. This only works in GNU/Linux and macOS:
1765
1766 \begin{screen}
1767 $ \textbf{abc2svg tunes.abc > tunes.xhtml}
1768 $ \textbf{chromium-browser --headless --print-to-pdf=tunes.pdf tunes.xhtml}
1769 ... many log messages ...
1770 ... Written to file tunes.pdf.
1771 $ _
1772 \end{screen}
1773
1774 % $
1775 However, in this case Chromium will add headers and footers to every
1776 page. To remove them and obtain a clean PDF file, run the command:
1777
1778 \begin{screen}
1779 $ \textbf{pdfcrop --margins "0 -9 0 -9" --clip tunes.pdf}
1780 PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
1781 ==> 79 pages written on `tunes-crop.pdf'.
1782 $ _
1783 \end{screen}
1784
1785 The same result can be obtained using \pkg{pdfpages} directly:
1786
1787 \begin{source}
1788 \begin{verbatim}
1789 \documentclass{article}
1790 \usepackage{pdfpages}
1791
1792 \def\tunes{tunes.pdf} % PDF file to trim
1793
1794 \begin{document}
1795
1796 \includepdf[pages=-,pagecommand={},%
1797 width=\paperwidth,trim={0 0.9cm 0 0.9cm},clip]{\tunes}
1798
1799 \end{document}
1800 \end{verbatim}
1801 \end{source}
1802
1803 % -----
1804
1805 \subsection{Program: \href{http://people.ds.cam.ac.uk/ph10/pmw.html}{PMW}}
1806
1807 Philip's Music Writer (PMW) is a free and multiplatform scorewriter,
1808 released under the GNU GPL. From the PMW home page:
1809
1810 \begin{quote}
1811
1812 \emph{Philip's Music Writer} (PMW) is a computer program for high
1813 quality music typesetting.
1814
1815 \end{quote}
1816
1817 PMW uses a simple text notation for music input and produces output in
1818 PostScript.
1819
1820 This is our usual music sample in PMW format (\file{sample-pmw.pmw}):
1821
1822 \begin{source}
1823 \begin{verbatim}
1824 @ music sample in PMW
1825
1826 Heading "|Music sample in PMW"
1827 Key C
1828 Time 4/4
1829
1830 [stave 1 treble 1]
1831 c d- e-; f-g-a-b-; | c' b- a-; g-f-e-d-; |
1832 c-g-e-g-; c-g-e-g-; |c e c r |
1833 [endstave]
1834 \end{verbatim}
1835 \end{source}
1836
1837 We typeset the score with these commands:
1838
1839 \begin{screen}
1840 $ \textbf{pmw -includefonts sample-pmw.pmw}
1841 $ \textbf{ps2pdf sample-pmw.ps}
1842 $ _
1843 \end{screen}
1844 % $
1845
1846 % -----
1847
1848 \subsection{Program: \href{http://www.arkkra.com/}{MUP}}
1849
1850 MUP is a free and multiplatform scorewriter, released under a free
1851 license. From the MUP home page:
1852
1853 \begin{quote}
1854
1855 Mup takes a text file as input and produces very high quality
1856 PostScript output for printed music. It can handle both regular
1857 notation and tablature notation. It can also produce MIDI output.
1858
1859 \end{quote}
1860
1861 This is our usual music sample in MUP format (\file{sample-mup.mup}):
1862
1863 \begin{source}
1864 \begin{verbatim}
1865 // music sample in MUP notation
1866
1867 header
1868 title "Music sample in MUP"
1869
1870 score
1871 time=4/4
1872
1873 music
1874 1: 4c; 8d bm; e ebm; f bm; g; a; b ebm;
1875 bar
1876 1: 4c+; 8b bm; a ebm; g bm; f; e; d ebm;
1877 bar
1878 1: 8c bm; g; e; g ebm; c bm; g; e; g ebm;
1879 bar
1880 1: 4c; e; c; r;
1881 endbar
1882 \end{verbatim}
1883 \end{source}
1884
1885 We typeset the score with these commands:
1886
1887 \begin{screen}
1888 $ \textbf{mup -F sample-mup.mup}
1889 Mup - Music Publisher Version 6.6
1890 Copyright (c) 1995-2017 by Arkkra Enterprises.
1891 Mup is free software. Use -l option to see license terms.
1892 $ \textbf{ps2pdf sample-mup.ps}
1893 $ _
1894 \end{screen}
1895 % $
1896
1897 % -----
1898
1899 \subsection{Program: \href{http://musescore.org}{MuseScore}}
1900 \label{sec:musescore}
1901
1902 MuseScore is a free and multiplatform scorewriter, released under the
1903 GNU GPL. Unlike the previous programs, it's a desktop application;
1904 however, it can be conveniently used from the command line.
1905
1906 MuseScore uses its own file formats (\file{.mscz}, \file{.mscx}) but
1907 it can also import several other file formats;
1908 \href{https://www.musicxml.com/}{MusicXML} is probably the most
1909 important.
1910
1911 We convert any supported file to PDF with this command:
1912
1913 \begin{screen}
1914 $ \textbf{musescore file.xml -o file.pdf}
1915 initScoreFonts 0x30d33c0
1916 convert <file.xml> to <file.pdf>
1917 setFirstInstrument: no instrument found for part 'P1'
1918 $ _
1919 \end{screen}
1920 % $
1921
1922 % -----
1923
1924 \subsection{Package \pkg{abc}}
1925 \label{sec:pkgabc}
1926
1927 This package enables the inclusion of music in ABC notation in
1928 \LaTeX{} sources; it's similar to \cmd{lilypond-book} or
1929 \pkg{lyluatex}, but targeting ABC.
1930
1931 \pkgname{Abc} provides the \env{abc} environment and the
1932 \ltx{abcinput} commands. The first embeds ABC music in the source,
1933 while the second includes an external ABC file. This is
1934 (\file{sample-abc.tex}):
1935
1936 \begin{source}
1937 \begin{verbatim}
1938 \documentclass{article}
1939 \usepackage[generate,ps2eps]{abc}
1940 \thispagestyle{empty}
1941
1942 \begin{document}
1943
1944 This is an Irish reel:
1945
1946 \begin{abc}[name=julia,program={abcm2ps -O=}]
1947 X:63
1948 T: Julia Delaney's
1949 M: C|
1950 L: 1/8
1951 R: reel
1952 K: Ddor
1953 |: dcAG ~F2EF|~E2 DE FD D2|dcAG FGAA|Addc d2 fe :|
1954 f2fe fagf |ecgc acgc |f2fe fagf|edcG Add2 :|
1955 \end{abc}
1956
1957 This is an Irish polka, slighly smaller:
1958
1959 \abcinput[program={abcm2ps -O=},width=0.9\abcwidth]
1960 {breeches}
1961
1962 End of document.
1963
1964 \end{document}
1965 \end{verbatim}
1966 \end{source}
1967
1968 The \cmd{generate} option (default) indicates that the ABC music
1969 should be generated by the external ABC typesetter. If the ABC music
1970 is not modified and it has already been generated, we could specify
1971 the \cmd{nogenerate} option. This is what we want to do when only the
1972 text is changed.
1973
1974 We typeset the source with this command:
1975
1976 \begin{screen}
1977 $ \textbf{pdflatex --shell-escape sample-abc.tex}
1978 ...
1979 Output written on sample-abc.pdf (1 page, 30937 bytes).
1980 Transcript written on sample-abc.log.
1981 $ _
1982 \end{screen}
1983
1984 \score{sample-abc}
1985
1986 % -----
1987
1988 \noteseparator
1989
1990 % -----
1991
1992 \section{Guitar Tablatures}
1993 \label{sec:tablatures}
1994
1995 Let's go back to guitar stuff. Tablature, as already explained, is a
1996 form of music notation for stringed instruments; making tablatures is
1997 basically the same process as making sheet music.
1998
1999 We can distinguish between \emph{automatic tablatures}, where fret
2000 positions are generated by the program, and \emph{manual tablatures},
2001 where fret positions are specified by the user.
2002
2003 % -----
2004
2005 \subsection{Program: \href{http://lilypond.org/}{LilyPond}}
2006 \label{sec:lilytab}
2007
2008 In addition to sheet music, LilyPond can also easily typeset automatic
2009 guitar tablatures. A minimal example (\file{lilytab.ly}):
2010
2011 \begin{source}
2012 \begin{verbatim}
2013 \version "2.18.2"
2014 \header { tagline = "" } % no footer
2015 \paper { left-margin = 0\cm }
2016
2017 music = {
2018 \time 3/4
2019 c4 d e f g a b a b c'2 r4 \bar "|."
2020 }
2021
2022 \score {
2023 <<
2024 \new Staff { \clef "G_8" \music } % sheet music
2025 \new TabStaff { \tabFullNotation \music } % tablature
2026 >>
2027 }
2028 \end{verbatim}
2029 \end{source}
2030
2031 We typeset the score with this command:
2032
2033 \begin{screen}
2034 $ \textbf{lilypond lilytab.ly}
2035 ...
2036 Converting to `./lilytab.pdf'...
2037 Success: compilation successfully completed
2038 $ _
2039 \end{screen}
2040 % $
2041
2042 \scoreshort{lilytab}
2043
2044 \bigskip
2045
2046 As we can see, the very same music line can be typeset as sheet music
2047 and as guitar tablature. Fretboard positions are automatically
2048 generated by LilyPond.
2049
2050 % -----
2051
2052 \subsection{Program: \href{https://wim.vree.org/svgParse/abc2xml.html}
2053 {abc2xml.py}}
2054 \label{sec:abc2xml}
2055
2056 This Python program converts an ABC file to a
2057 \href{https://www.musicxml.com/}{MusicXML} file containing automatic
2058 tablature information; this file can then be typeset with any
2059 MusicXML-enabled application, like MuseScore.
2060
2061 A minimal tablature example (\file{abctab.abc}):
2062
2063 \begin{source}
2064 \begin{verbatim}
2065 X: 1
2066 M: 3/4
2067 L: 1/4
2068 K: C
2069 %
2070 V:1
2071 CDE | FGA | BBB | c2z |]
2072 V:2 clef=tab octave=-1
2073 CDE | FGA | BBB | c2z |]
2074 \end{verbatim}
2075 \end{source}
2076
2077 We typeset the score with these commands (error messages can be safely
2078 ignored):
2079
2080 \begin{screen}
2081 $ \textbf{abc2xml.py -f abctab.abc > abctab.xml}
2082 -- decoded from utf-8
2083 -- skipped header: (field X,1)
2084 -- done in 0.02 secs
2085 $ \textbf{musescore abctab.xml -o abctab.pdf}
2086 Jack appears to be installed on this system, so we'll use it.
2087 initScoreFonts 0x25ba100
2088 libpng warning: iCCP: known incorrect sRGB profile
2089 convert <abctab.xml> to <abctab.pdf>
2090 Error at line 18 col 16: no instrument found for part 'P1'
2091 Error at line 138 col 16: no instrument found for part 'P2'
2092 $ _
2093 \end{screen}
2094 % $
2095
2096 \score{abctab}
2097
2098 \bigskip
2099
2100 As we can see, the very same music line can be typeset as sheet music
2101 and as guitar tablature. Fretboard positions are automatically
2102 generated by \cmd{abc2xml.py}.
2103
2104 We can also use \cmd{lilypond} to typeset the ABC tablature. The
2105 ancillary program \cmd{musicxml2ly} converts MusicXML files to
2106 LilyPond format:
2107
2108 \begin{screen}
2109 $ \textbf{abc2xml.py -f abctab.abc > abctab.xml}
2110 -- decoded from utf-8
2111 -- skipped header: (field X,1)
2112 -- done in 0.02 secs
2113 $ \textbf{musicxml2ly abctab.xml}
2114 $ musicxml2ly: Reading MusicXML from abctab.xml ...
2115 musicxml2ly: Converting to LilyPond expressions...
2116 musicxml2ly: Converting to LilyPond expressions...
2117 musicxml2ly: Output to `abctab.ly'
2118 $ \textbf{lilypond abctab.ly}
2119 GNU LilyPond 2.18.2
2120 Processing `abctab.ly'
2121 ...
2122 Converting to `./abctab.pdf'...
2123 Success: compilation successfully completed
2124 $ _
2125 \end{screen}
2126 % $
2127
2128 Regrettably, \cmd{musicxml2ly} is not as robust as MuseScore's
2129 MusicXML import filter, and it may fail on complex music.
2130
2131 % -----
2132
2133 \subsection{Package \pkg{musixtex}}
2134
2135 Starting from version 1.29, \pkgname{MusiXTeX} can also make manual
2136 tablatures for several stringed instruments. A minimal example, to be
2137 typeset with \cmd{musixtex} (\file{sample-musixtex-tab.tex}):
2138
2139 \begin{source}
2140 \begin{verbatim}
2141 % bare MusiXTeX example
2142
2143 \input musixtex
2144 \nopagenumbers
2145
2146 This is a MusiXTeX tablature example:
2147
2148 \setlines16 % six lines
2149 \setstaffs1{1}
2150 \setclefsymbol1{\tabclef} % and a TAB clef
2151 \nobarnumbers
2152 \let\extractline\leftline % left aligned
2153
2154 \startextract
2155 \Notes \tab{5}{3} \tab{4}{0} \tab{4}{2} \en
2156 \bar
2157 \Notes \tab{4}{3} \tab{3}{0} \tab{3}{2} \en
2158 \bar
2159 \Notes \tab{2}{0} \tab{3}{2} \tab{2}{0} \en
2160 \bar
2161 \Notes \tab{2}{1} \qp \qp \en
2162 \endextract
2163
2164 \end
2165 \end{verbatim}
2166 \end{source}
2167
2168 \scoreshort{sample-musixtex-tab}
2169
2170 % -----
2171
2172 \subsection{Package \pkg{guitartabs}}
2173
2174 This package may be missing in less recent releases of TeX Live, so
2175 you might have to install it manually. It provides a \cmd{guitartabs}
2176 document class and a very simple syntax to manually specify strings,
2177 fret positions, and note length:
2178
2179 \begin{source}
2180 \begin{verbatim}
2181 \documentclass{guitartabs}
2182 \thispagestyle{empty}
2183
2184 \begin{document}
2185
2186 \Large
2187
2188 \begin{tabline}{4}{4}{4}{E,A,D,G,B,e}
2189 % bar 1
2190 % note 1 of 3, string 5, fret 4, note length 1/4
2191 \notel{1}{3}{5}{3}{4}
2192 % note 2 of 3, string 4, fret 0, note length 1/4
2193 \notel{2}{3}{4}{0}{4}
2194 \notel{3}{3}{4}{2}{4}
2195 % bar 2
2196 \nextbar
2197 \notel{1}{3}{4}{3}{4}
2198 \notel{2}{3}{3}{0}{4}
2199 \notel{3}{3}{3}{2}{4}
2200 % bar 3
2201 \nextbar
2202 \notel{1}{3}{2}{0}{4}
2203 \notel{2}{3}{3}{2}{4}
2204 \notel{3}{3}{2}{0}{4}
2205 % bar 4
2206 \nextbar
2207 \notel{1}{3}{5}{3}{2}
2208 % rests
2209 \restquarter{2}{3}
2210 \restquarter{3}{3}
2211 \end{tabline}
2212
2213 \end{document}
2214 \end{verbatim}
2215 \end{source}
2216
2217 \score{guitartabs}
2218
2219 If you don't need the note length indications at the bottom of the
2220 tablature, use \ltx{note} instead of \ltx{notel}.
2221
2222 % -----
2223
2224 \subsection{Using Guitar Pro Tablatures}
2225
2226 A \emph{de facto} standard for guitar tablatures is the
2227 \href{https://www.guitar-pro.com}{Guitar Pro} format, or more
2228 precisely a set file formats: \file{.gpX} (where X is 3, 4, 5, 6),
2229 \file{.gpx}, \file{.gtp}. Many sites offer free tablatures in one of
2230 these formats.
2231
2232 To print them, we can use
2233 \href{http://www.tuxguitar.com.ar/}{TuxGuitar} or MuseScore. TuxGuitar
2234 is a free and multiplatform tablature editor; it's a desktop
2235 application that can export tablatures in PDF format. Regrettably, it
2236 cannot work as a command-line program.
2237
2238 To import GuitarPro tablatures into MuseScore and export them as PDF,
2239 we can use the \cmd{-P} command line switch. It exports all parts to
2240 the PDF file; then it's up to the user to find out the pages that
2241 contain the tablature.
2242
2243 % -----
2244
2245 \noteseparator
2246
2247 % -----
2248
2249 \section{Bits and Pieces}
2250
2251 \subsection{Multimedia Files}
2252 \label{sec:multimedia}
2253
2254 In addition to sheet music, our documents can also include sound
2255 files. To be more precise, we can click on a link to an external sound
2256 file that is referred to in the PDF document; the default player will
2257 be run.
2258
2259 This feature is made possible by the \pkg{hyperref} package, which
2260 provides the \ltx{href} command:
2261
2262 \begin{source}
2263 \begin{verbatim}
2264 \href{run:jingle.midi}{this midi file}
2265 \end{verbatim}
2266 \end{source}
2267
2268 The first parameter opens the specified file with the default
2269 multimedia player; the second parameter creates a link to click on.
2270 For example, the above line lets the reader click on
2271 \href{run:jingle.midi}{this midi file} and listen to it. The operating
2272 system must know how to play the specified sound file.
2273
2274 The link need not be just text; we may as well apply the link to
2275 included graphics.
2276
2277 % -----
2278
2279 \subsection{Notation Source Files}
2280 \label{sec:sources}
2281
2282 If we need to include notation source files, we could use a simple
2283 \cmd{verbatim} environment, or \cmd{alltt} (package \pkg{alltt}) if we
2284 also want to include \LaTeX{} commands in the source:
2285
2286 \bigskip
2287
2288 \noindent
2289 { \small
2290 \begin{boxedminipage}[c]{0.52\linewidth}
2291 \begin{verbatim}
2292 \textit{\% This is a comment!}
2293 \textbf{X:} 1
2294 \textbf{L:} 1/4
2295 \textbf{K:} C
2296 \textit{\% These are notes:}
2297 c G/G/ _AG|z !>!B!>!c z|]
2298 \end{verbatim}
2299 \end{boxedminipage}
2300 \hspace{2em}
2301 \begin{boxedminipage}[c]{0.4\linewidth}
2302 \begin{alltt}
2303 \textit{\% This is a comment!}
2304 \textbf{X:} 1
2305 \textbf{L:} 1/4
2306 \textbf{K:} C
2307 \textit{\% These are notes:}
2308 c G/G/ _AG|z !>!B!>!c z|]
2309 \end{alltt}
2310 \end{boxedminipage}
2311 } % \small
2312
2313 \bigskip
2314
2315 But if you want something fancier, like the sources included in this
2316 document, you could also use the \pkg{tcolorbox} and define a new
2317 environment like the following:
2318
2319 \bigskip
2320
2321 \begin{tcolorbox}[breakable,boxrule=0.2pt,%
2322 left=0pt,right=0pt,colback=green!7!white,arc=2pt]
2323 \begin{verbatim}
2324 \newenvironment{source}
2325 { % beg def
2326 \medskip
2327 \small
2328 \begin{margins}{-0.3cm}{-0.3cm}
2329 \begin{spacing}{0.9}
2330 \begin{tcolorbox}[breakable,boxrule=0.2pt,%
2331 left=0pt,right=0pt,colback=green!7!white,arc=2pt]
2332 \begin{alltt}
2333 }
2334 { % end def
2335 \end{alltt}
2336 \end{tcolorbox}
2337 \end{spacing}
2338 \end{margins}
2339 }
2340 \end{verbatim}
2341 \end{tcolorbox}
2342
2343 % -----
2344
2345 \noteseparator
2346
2347 % -----
2348
2349 \section{Putting It All Together}
2350
2351 We have solved the first problem; now we know how to make music files
2352 in several different ways. Now it's time to solve the second problem:
2353 how to combine music files and \LaTeX.
2354
2355 We have two possible approaches: keeping all music in the \LaTeX{}
2356 source, or keeping the music in external files. Both approaches have
2357 advantages and disadvantages. Basically, the first method is slower,
2358 because any change in the source may require recompilation of music
2359 excerpts. The second method requires a little more work, because we
2360 need to maintain an additional file that takes care of music
2361 conversion.
2362
2363 % -----
2364
2365 \subsection{Package \pkg{abc}, Revisited}
2366
2367 We met this package in Section~\ref{sec:pkgabc}, where it was used to
2368 include ABC music in a \LaTeX{} source. This package, however, is not
2369 limited to ABC. User-defined environments can provide support for
2370 virtually any external scorewriter; LilyPond support, however, is
2371 slightly bugged.
2372
2373 The following source defines the \env{mtx} and \env{pmw} environments.
2374 For each, the definition specifies the external program to run, its
2375 command line switches, and the file extension:
2376
2377 \begin{source}
2378 \begin{verbatim}
2379 \documentclass{article}
2380 \thispagestyle{empty}
2381 \usepackage[generate,ps2eps]{abc}
2382
2383 % --- M-Tx support
2384 \newenvironment{mtx}[1][]
2385 {\renewcommand{\normalabcoutputfile}{out-mtx}%
2386 \abc[program=musixtex,options={-g},extension=mtx,#1]}
2387 {\endabc}
2388 \newcommand{\mtxinput}[2][]{%
2389 \abcinput[program=musixtex,options={-g},extension=mtx,#1]{#2}}
2390
2391 % --- PMW support
2392 \newenvironment{pmw}[1][]
2393 {\renewcommand{\normalabcoutputfile}{out-pmw}%
2394 \abc[program=pmw,options={-includefont},extension=pmw,#1]}
2395 {\endabc}
2396 \newcommand{\pmwinput}[2][]{%
2397 \abcinput[program=pmw,options={-includefont},extension=pmw,#1]{#2}}
2398
2399 \begin{document}
2400
2401 This document includes music excerpts written in different formats. It
2402 uses \texttt{abc.sty} and defines new environments.
2403
2404 This is a short piece, typeset by M-Tx:
2405
2406 \mtxinput{sample-mtx}
2407
2408 The same piece, typeset by PMW:
2409
2410 \pmwinput{sample-pmw}
2411
2412 End of document.
2413
2414 \end{document}
2415 \end{verbatim}
2416 \end{source}
2417
2418 \score{sample-all}
2419
2420 \bigskip
2421
2422 A complete template that implements all environments is presented in
2423 Section~\ref{sec:abcall}.
2424
2425 % -----
2426
2427 \subsection{Using \cmd{make}}
2428
2429 Another way to make a \LaTeX{} document that includes music in
2430 different formats is by using a developer's tool called \cmd{make}.
2431 It's a program that takes care of what needs what, what needs to be
2432 converted first, what should be done if you modify something, and so
2433 on. \cmd{make} is normally used to compile programs.
2434
2435 Let's make a practical example. We have a \LaTeX{} document,
2436 \file{main.tex}, which includes three PDF files, \file{music1.pdf},
2437 \file{music2.pdf}, and \file{music3.pdf}:
2438
2439 \begin{source}
2440 \begin{verbatim}
2441 \documentclass{article}
2442 \usepackage{graphicx}
2443 \thispagestyle{empty}
2444
2445 \begin{document}
2446
2447 This document includes three music excerpts:
2448
2449 \includegraphics{music1}
2450
2451 \includegraphics{music2}
2452
2453 \includegraphics{music3}
2454
2455 End of document.
2456
2457 \end{document}
2458 \end{verbatim}
2459 \end{source}
2460
2461 Let's suppose that the three PDF files are obtained from an
2462 \pkgname{M-Tx} file, a LilyPond file, and an ABC file. We should
2463 convert the PDF files manually, then typeset \file{main.tex}. It's not
2464 a big deal, but what if you have dozens of music files, each of which
2465 must be converted with different commands? This task would soon grow
2466 tedious and difficult to manage.
2467
2468 Here \cmd{make} comes to the rescue. It uses a text file, called
2469 \file{Makefile}, which contains rules for building the document and
2470 the PDF files that it includes. This is a simple \file{Makefile} that
2471 can be used to compose (make!) \file{main.pdf}:
2472
2473 \begin{source}
2474 \begin{verbatim}
2475 # Makefile for main.tex
2476
2477 FIGURES = music1.pdf music2.pdf music3.pdf
2478
2479 # The final document depends on main.tex and the figures
2480 main.pdf: main.tex $(FIGURES)
2481 pdflatex main.tex
2482
2483 # music1.pdf depends on music1.mtx
2484 # conversion commands follow
2485 music1.pdf: music1.mtx
2486 musixtex music1.mtx ; pdfcrop musix1.pdf ; \
2487 /bin/mv musix1-crop.pdf music1.pdf
2488
2489 # music2.pdf depends on music2.ly
2490 music2.pdf: music2.ly
2491 lilypond music2.ly; pdfcrop musix2.pdf ; \
2492 /bin/mv musix2-crop.pdf music2.pdf
2493
2494 # music3.pdf depends on music3.abc
2495 music3.pdf: music3.abc
2496 abcm2ps -c -O= music3.abc; ps2pdf music3.ps; \
2497 pdfcrop musix3.pdf ; \
2498 /bin/mv musix3-crop.pdf music3.pdf
2499
2500 # end of Makefile
2501 \end{verbatim}
2502 \end{source}
2503
2504 % $
2505
2506 Let's see what it does. First of all, as you might have guessed the
2507 \cmd{\#} character starts a comment; the rest of the line is ignored.
2508
2509 This line:
2510
2511 \begin{source}
2512 \begin{verbatim}
2513 FIGURES = music1.pdf music2.pdf music3.pdf
2514 \end{verbatim}
2515 \end{source}
2516
2517 \noindent
2518 creates a \emph{variable}, that is a ``name'' (\cmd{FIGURES}) that
2519 ``contains'' the three file names \cmd{music1.pdf music2.pdf
2520 music3.pdf}. This variable will be referred to later on.
2521
2522 These lines:
2523
2524 \begin{source}
2525 \begin{verbatim}
2526 main.pdf: main.tex $(FIGURES)
2527 pdflatex main.tex
2528 \end{verbatim}
2529 \end{source}
2530 % $
2531
2532 \noindent
2533 declare that \cmd{main.pdf} is a \emph{target} that depends on
2534 \file{main.tex} and on the three files denoted by the \cmd{FIGURES}
2535 variable. The second line specifies the command that must be run to
2536 make \file{main.pdf}. This line starts with a TAB character, not with
2537 spaces: this is important!
2538
2539 Then we have three sections, one for each music file. Each section
2540 tells \cmd{make} what to do to compose the PDF figure. For instance,
2541 the section:
2542
2543 \begin{source}
2544 \begin{verbatim}
2545 music1.pdf: music1.mtx
2546 musixtex music1.mtx ; pdfcrop musix1.pdf ; \
2547 /bin/mv musix1-crop.pdf music1.pdf
2548 \end{verbatim}
2549 \end{source}
2550
2551 \noindent
2552 states that \file{music1.pdf} is a target that depends on
2553 \file{music1.mtx}; the following lines specify the commands to create
2554 \file{music1.pdf}. Commands are separated by the \cmd{;} character,
2555 while \cmd{\textbackslash} indicates that the command continues to the
2556 next line.
2557
2558 To make \file{main.pdf}, we simply run the command:
2559
2560 \begin{screen}
2561 $ \textbf{make}
2562 ...
2563 $ _
2564 \end{screen}
2565
2566 \noindent
2567 in the same directory where we saved \file{Makefile}. \cmd{make} will
2568 make the three figures first, then \file{main.pdf} that depends on
2569 them.
2570
2571 If we modify one of the files, \cmd{make} will take care of
2572 dependencies and rebuild the final target. For example, if we modify
2573 \file{music2.ly}, \cmd{make} will rebuild \file{music2.pdf} first, then
2574 \file{main.pdf} that depends on \file{music2.pdf}.
2575
2576 In my opinion, this approach is the most flexible. This guide was
2577 compiled using \cmd{make} and a pretty long \file{Makefile}.
2578
2579 % -----
2580
2581 \noteseparator
2582
2583 % -----
2584
2585 \newpage
2586 \section{The End}
2587
2588 That's it, dear fellow musicians: I really hope that this guide will
2589 be useful to you. Please help me improve this document: for any
2590 suggestions, comments, or contributions, please feel free to contact
2591 me by \href{mailto:[email protected]}{email}. I'd like to
2592 receive feedback, especially if you use this document in education.
2593
2594 I would like to thank all the geniuses who wrote the packages and
2595 programs cited in this guide. Kudos and hats off, folks!
2596
2597 This document is copyleft \copyleft{} Guido Gonzato, PhD, and released
2598 under the \href{https://www.gnu.org/licenses/fdl.html}{GNU Free
2599 Documentation Licence}.
2600
2601 \medskip
2602
2603 \begin{center}
2604 \includegraphics{guidopiper.jpeg}
2605 \end{center}
2606
2607 Ciao! \texttt{=8-)}
2608
2609 % -----
2610
2611 \noteseparator
2612
2613 % -----
2614
2615 \newpage
2616
2617 \appendix
2618
2619 \section{List of Packages and Programs}
2620
2621 This manual uses many \LaTeX{} packages and includes PDF output
2622 produced by several programs, all of which are free and open source.
2623 Commercial programs were intentionally left out.
2624
2625 The page \url{https://www.ctan.org/topic/music} is an important
2626 starting po\-int for those interested in combining \LaTeX{} and music.
2627 It's a list of \LaTeX{} packages for typesetting music and related
2628 stuff. The following is the complete list of packages and programs I
2629 used to make this manual, in order of appearance.
2630
2631 \begin{itemize}
2632
2633 \item CTAN Music page. ``This topic contains packages for
2634 typesetting music and related stuff.''\\
2635 \url{https://www.ctan.org/topic/music}.
2636
2637 \item Package: musicography, v. 2018-05.21.\\
2638 \url{https://ctan.org/pkg/musicography}
2639
2640 \item Package: leadsheets, v. 0.5b\\
2641 \url{https://ctan.org/pkg/leadsheets}
2642
2643 \item Package: lilyglyphs, v. 0.2.3\\
2644 \url{https://ctan.org/pkg/lilyglyphs}
2645
2646 \item Font: Bravura, v.1.272\\
2647 \url{https://www.smufl.org/fonts}
2648
2649 \item Package: guitar, v. 1.6\\
2650 \url{https://ctan.org/pkg/guitar}
2651
2652 \item Package: gtrcrd, v. 1.1\\
2653 \url{https://ctan.org/pkg/gtrcrd}
2654
2655 \item Package: songs, v. 3.0\\
2656 \url{https://ctan.org/pkg/songs}
2657
2658 \item Package: musixguit, v. 1.2.2\\
2659 \url{https://ctan.org/pkg/musixguit}
2660
2661 \item Package: songbook, v. 4.5\\
2662 \url{https://ctan.org/pkg/songbook}
2663
2664 \item Program: Chordii, v. 4.3\\
2665 \url{https://www.vromans.org/projects/Chordii}
2666
2667 \item Package: gchords, v. 1.20\\
2668 \url{https://ctan.org/pkg/gchords}
2669
2670 \item Package: guitarchordschemes, v. 0.7\\
2671 \url{https://ctan.org/pkg/guitarchordschemes}
2672
2673 \item Package: guitartabs, v. 2018-05-01\\
2674 \url{https://ctan.org/pkg/guitartabs}
2675
2676 \item Page: MusiXTeX and Related Software. \\
2677 \url{https://icking-music-archive.org/software/htdocs/htdocs.html}
2678
2679 \item Package: MusiXTeX, v. 1.29\\
2680 \url{https://ctan.org/pkg/musixtex}
2681
2682 \item Package: M-Tx, v. 0.63a\\
2683 \url{https://ctan.org/pkg/m-tx}
2684
2685 \item Package: Gregoriotex, v. 5.1.1\\
2686 \url{https://ctan.org/pkg/gregoriotex}\\
2687 \url{http://gregorio-project.github.io/gregoriotex}\\
2688 \url{http://gregorio-project.github.io}
2689
2690 \item Program: LilyPond, v. 1.18.2\\
2691 \url{http://lilypond.org}
2692
2693 \item Package: Lyluatex, v. 1.0b\\
2694 \url{https://ctan.org/pkg/lyluatex}
2695
2696 \item Programs: \cmd{abcm2ps} v. 8.14.2, \cmd{and2svg} v. 1.19.0\\
2697 \url{http://moinejf.free.fr}
2698
2699 \item Program: PMW, Philip's Music Writer, v. 4.30\\
2700 \url{http://people.ds.cam.ac.uk/ph10/pmw.html}
2701
2702 \item Program: MUP v. 6.6\\
2703 \url{http://www.arkkra.com}
2704
2705 \item Program: MuseScore v. 3.0\\
2706 \url{http://musescore.org}
2707
2708 \item Package: Abc v. 2.0b\\
2709 \url{https://ctan.org/pkg/abc}
2710
2711 \item Program: abc2xml.ly v. 218\\
2712 \url{https://wim.vree.org/svgParse/abc2xml.html}
2713
2714 \end{itemize}
2715
2716 % -----
2717
2718 \newpage
2719
2720 \section{Examples}
2721
2722 \subsection{A Complete \pkg{abc} Example}
2723 \label{sec:abcall}
2724
2725 This source defines environments for M-Tx, PMW, LilyPond, and MUP; it
2726 also redefines the \cmd{abc} environment as \cmd{ABC}. This is
2727 necessary for technical reasons. Lilypond sources must begin with a
2728 double line \ltx{version "2.18.2"}; this is required to avoid a bug.
2729
2730 \begin{source}
2731 \begin{verbatim}
2732 % typeset with:
2733 % pdflatex -shell-escape sample-abc-all.tex
2734
2735 \documentclass{article}
2736 \thispagestyle{empty}
2737 \usepackage[generate,ps2eps]{abc}
2738
2739 % --- M-Tx support
2740 \newenvironment{mtx}[1][]
2741 {\renewcommand{\normalabcoutputfile}{out-mtx}%
2742 \abc[program=musixtex,options={-g},extension=mtx,#1]}
2743 {\endabc}
2744 \newcommand{\mtxinput}[2][]{%
2745 \abcinput[program=musixtex,options={-g},extension=mtx,#1]{#2}}
2746
2747 % --- PMW support
2748 \newenvironment{pmw}[1][]
2749 {\renewcommand{\normalabcoutputfile}{out-pmw}%
2750 \abc[program=pmw,options={-includefont},extension=pmw,#1]}
2751 {\endabc}
2752 \newcommand{\pmwinput}[2][]{%
2753 \abcinput[program=pmw,options={-includefont},extension=pmw,#1]{#2}}
2754
2755 % --- LilyPond support
2756 % !!! BUG: the LilyPond source must begin with a \null command
2757 \newenvironment{lily}[1][]
2758 {\renewcommand{\normalabcoutputfile}{out-lily}%
2759 \abc[program=lilypond,options={-d backend=eps},extension=ly,#1]}
2760 {\endabc}
2761 \newcommand{\lilyinput}[2][]{%
2762 \abcinput[program=lilypond,options={--ps},extension=ly,#1]{#2}}
2763
2764 % --- MUP support
2765 \newenvironment{mup}[1][]
2766 {\renewcommand{\normalabcoutputfile}{out-mup}%
2767 \abc[program=mup,options={-F},extension=mup,#1]}
2768 {\endabc}
2769 \newcommand{\mupinput}[2][]{%
2770 \abcinput[program=mup,options={-F},extension=mup,#1]{#2}}
2771
2772 % --- ABC must be redefined
2773 \newenvironment{ABC}[1][]
2774 {\renewcommand{\normalabcoutputfile}{out-ABC}%
2775 \abc[program=abcm2ps,options={-O=},extension=abc,#1]}
2776 {\endabc}
2777 \newcommand{\ABCinput}[2][]{%
2778 \abcinput[program=abcm2ps,options={-O=},extension=abc,#1]{#2}}
2779
2780 \begin{document}
2781
2782 This document includes music excerpts written in several formats. It
2783 uses \texttt{abc.sty} and defines new environments.
2784
2785 This is a short piece, typeset by M-Tx:
2786
2787 \begin{mtx}
2788 Title: \bigtype Music sample in M-Tx
2789 Style: Solo
2790 Meter: C
2791 Width: 160mm
2792
2793 c4 d8 e f g a b | c4 b8 a g f e d | c8 g+ e g c- g+ e g | c4- e c r |
2794 \end{mtx}
2795
2796 The same piece, typeset by LilyPond:
2797
2798 \begin{lily}
2799 % twice - it's required to avoid a bug
2800 \version "2.18.2"
2801 \version "2.18.2"
2802
2803 \header {
2804 title = "Music sample in LilyPond"
2805 tagline = "" % no footer
2806 }
2807
2808 \relative c' {
2809 \time 4/4
2810 \clef treble
2811 c4 d8 e f8 g a b | c4 b8 a g8 f e d |
2812 c8 g' e g c,8 g' e g | c,4 e c r \bar "|."
2813 }
2814 \end{lily}
2815
2816 The same piece, typeset by PMW:
2817
2818 \begin{pmw}
2819 Heading "|Music sample in PMW"
2820 Key C
2821 Time 4/4
2822
2823 [stave 1 treble 1]
2824 c d- e-; f-g-a-b-; | c' b- a-; g-f-e-d-; |
2825 c-g-e-g-; c-g-e-g-; |c e c r |
2826 [endstave]
2827 \end{pmw}
2828
2829 The same piece, typeset by MUP:
2830
2831 \begin{mup}
2832 // music sample in MUP notation
2833
2834 header
2835 title "Music sample in MUP"
2836
2837 score
2838 time=4/4
2839
2840 music
2841 1: 4c; 8d bm; e ebm; f bm; g; a; b ebm;
2842 bar
2843 1: 4c+; 8b bm; a ebm; g bm; f; e; d ebm;
2844 bar
2845 1: 8c bm; g; e; g ebm; c bm; g; e; g ebm;
2846 bar
2847 1: 4c; e; c; r;
2848 endbar
2849 \end{mup}
2850
2851 The same piece, typeset by abcm2ps:
2852
2853 \begin{ABC}
2854 X: 1
2855 T: Music sample in ABC
2856 M: 4/4
2857 L: 1/4
2858 K: C
2859 %
2860 C D/E/ F/G/A/B/|c B/A/ G/F/E/D/|C/G/E/G/ C/G/E/G/|CECz|]
2861 \end{ABC}
2862
2863 \end{document}
2864
2865 \end{verbatim}
2866 \end{source}
2867
2868 \score{sample-abc-all}
2869
2870 % -----
2871
2872 \subsection{A Complete Songbook Example}
2873 \label{sec:songbook}
2874
2875 The following source is a minimal template for songbooks. It uses the
2876 \pkg{gchords} and \pkg{guitar} packages (Sections~\ref{sec:gchords}
2877 and \ref{sec:pkgguitar}). The resulting PDF has its own page numbers
2878 (don't get confused!) and is included in this document with
2879 \ltx{includepdf}.
2880
2881 \begin{source}
2882 \begin{verbatim}
2883 \documentclass[11pt]{article}
2884 \usepackage{graphicx}
2885 \usepackage{gchords}
2886 \usepackage{guitar}
2887
2888 \begin{document}
2889
2890 \title{A Minimal Songbook}
2891 \author{Guido Gonzato}
2892 \date{\today}
2893
2894 \maketitle
2895 \tableofcontents
2896
2897 % -----
2898
2899 \section{For He's a Jolly Good Fellow}
2900
2901 % Typically sung to congratulate somebody.
2902
2903 \smallchords
2904
2905 \def\numfrets{4}
2906 \begin{minipage}[c]{\linewidth} % use less space
2907 \chords{
2908 \chord{t}{n,p3,p2,n,p1,n}{C}
2909 \chord{t}{p3,p2,n,n,n,p3}{G}
2910 \chord{t}{n,p3,p2,p3,p1,n}{C7}
2911 \chord{t1}{n,p2,p2,p1,n,n}{F}
2912 }
2913 \end{minipage}
2914
2915 \medskip
2916
2917 \includegraphics[width=\textwidth]{fellow}
2918
2919 \bigskip
2920
2921 \begin{guitar}
2922
2923 For [C]he's a jolly good fellow,
2924 For [G]he's a jolly good [C]fellow,
2925 For [C7]he's a jolly good [F]fellow,
2926 Which [C]nobody [G]can [C]deny.
2927
2928 \end{guitar}
2929
2930 % -----
2931
2932 \section{Happy Birthday To You}
2933
2934 % Sung to remind somebody they're growing old.
2935
2936 \def\numfrets{4}
2937 \begin{minipage}[c]{\linewidth}
2938 \chords{
2939 \chord{t1}{n,p2,p2,p1,n,n}{F}
2940 \chord{t}{n,p3,p2,n,p1,n}{C}
2941 \chord{t}{n,p3,p2,p3,p1,n}{C7}
2942 \chord{t1}{n,n,p2,p2,p2,n}{Bb}
2943 }
2944 \end{minipage}
2945
2946 \medskip
2947
2948 \includegraphics[width=\textwidth]{happyb}
2949
2950 \bigskip
2951
2952 \begin{guitar}
2953 Happy [F]birthday to [C]you,
2954 Happy [C7]birthday to [F]you,
2955 Happy birthday dear [Bb]Guido,
2956 Happy [F]birthday [C]to [F]you!
2957 \end{guitar}
2958
2959 % -----
2960
2961 \section{Warm Kitty}
2962
2963 % No need to introduce this lullaby!
2964
2965 \def\numfrets{4}
2966 \begin{minipage}[c]{\linewidth}
2967 \chords{
2968 \chord{t}{n,n,p2,p2,p2,n}{A}
2969 \chord{t}{n,p2,p2,p1,n,n}{E}
2970 \chord{t}{n,p2,p2,p1,p3,n}{E7}
2971 }
2972 \end{minipage}
2973
2974 \medskip
2975
2976 \includegraphics[width=\textwidth]{warm}
2977
2978 \bigskip
2979
2980 \begin{guitar}
2981
2982 [A]Soft kitty, [E]warm kitty
2983 [A]Little ball of [E]fur [E7]~
2984 [A]Happy kitty, [E]sleepy kitty
2985 [A]Purr, [E]purr, [A]purr
2986
2987 \end{guitar}
2988
2989 \end{document}
2990 \end{verbatim}
2991 \end{source}
2992
2993 \newpage
2994
2995 \pagecolor{pdfbg}
2996 \includepdf[pages=-,pagecommand={}]{sample-songbook.pdf}
2997 \pagecolor{white}
2998
2999 % -----
3000
3001 \subsection{A sample \file{Makefile}}
3002
3003 This is the \file{Makefile} that was used to typeset the previous
3004 example. The \cmd{clean} target is used to clean up all temporary
3005 files.
3006
3007 \begin{source}
3008 \begin{verbatim}
3009 # Makefile for sample-songbook
3010
3011 FIGURES = fellow.pdf happyb.pdf warm.pdf
3012
3013 sample-songbook: sample-songbook.tex $(FIGURES)
3014 pdflatex sample-songbook.tex; \
3015 pdflatex sample-songbook.tex; \
3016 pdflatex sample-songbook.tex
3017
3018 fellow.pdf: fellow.abc
3019 abcm2ps -c -O= fellow.abc; \
3020 ps2pdf fellow.ps; pdfcrop fellow.pdf; \
3021 /bin/mv -f fellow-crop.pdf fellow.pdf
3022
3023 happyb.pdf: happyb.abc
3024 abcm2ps -O= happyb.abc; \
3025 ps2pdf happyb.ps; pdfcrop happyb.pdf; \
3026 /bin/mv -f happyb-crop.pdf happyb.pdf
3027
3028 warm.pdf: warm.abc
3029 abcm2ps -O= warm.abc; \
3030 ps2pdf warm.ps; pdfcrop warm.pdf; \
3031 /bin/mv -f warm-crop.pdf warm.pdf
3032
3033 clean:
3034 /bin/rm -f .*~ *~ *aux *bak *lo? *to? *out *tmp *bbl *ps
3035 \end{verbatim}
3036 \end{source}
3037 % $
3038
3039 % -----
3040
3041 \subsection{Verses and Guitar Chords Diagrams}
3042
3043 Combining verses and guitar chord diagrams can be done in several
3044 ways. I think that the following example shows two of the easiest
3045 methods. Please refer to Section~\ref{sec:pkgguitar} and
3046 Section~\ref{sec:gchords} for further details.
3047
3048 \begin{source}
3049 \begin{verbatim}
3050 \documentclass{article}
3051 \usepackage{guitar}
3052 \usepackage{gchords}
3053 \thispagestyle{empty}
3054
3055 \newcommand{\C}{\hspace{-0.8em}\chord{t}{n,p3,p2,n,p1,n}{C}}
3056 \newcommand{\CmajVII}{\hspace{-0.8em}\chord{t}{n,p3,p2,n,n,n}{Cmaj7}}
3057 \newcommand{\F}{\hspace{-0.8em}\chord{t1}{n,p2,p2,p1,n,n}{F}}
3058
3059 \def\chordsize{1.5mm}
3060 \def\numfrets{3}
3061 \def\namefont{\it}
3062
3063 \begin{document}
3064
3065 \noindent
3066 We can typeset verses and guitar chord grids in a \texttt{guitar}
3067 environment:
3068
3069 \bigskip
3070
3071 \begin{minipage}[c]{\linewidth} % to avoid indentation
3072 \begin{guitar}
3073
3074 \textbf{Imagine (John Lennon)}
3075 \emph{Intro, $\times$ 2}
3076 [\C] \hspace{2em} [\CmajVII] \hspace{2em} [\F] \hspace{2em}
3077 [\C]Imagine there's [\CmajVII|]{no} ~ [\F]heaven
3078 [\C]It's easy if [\CmajVII|]{you} ~ [\F]try
3079
3080 \end{guitar}
3081 \end{minipage}
3082
3083 \noindent
3084 {\ldots}and so on. But we could just use the \verb|\upchord| command,
3085 provided by \texttt{gchords}:
3086
3087 \begin{verse}
3088
3089 \upchord{\C}Imagine there's \upchord{\CmajVII}no \qquad
3090 \upchord{\F}heaven
3091
3092 \upchord{\C}It's easy if \upchord{\CmajVII}you \qquad
3093 \upchord{\F}try
3094
3095 \end{verse}
3096
3097 \end{document}
3098 \end{verbatim}
3099 \end{source}
3100
3101 \score{verses-chords}
3102
3103 % -----
3104
3105 \end{document}
3106
3107 %% --- end of file latex4musicians.tex