Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I’ll give a tutorial, “LaTeX for musicians”, in the next year and certainly I want the to show how to include music in their texts. I’m a musician myself but I never used LaTeX to typeset music.

I found two ways to include music in a LaTeX document (plus: integrate music as image) and I want to share my thoughts and ask for some help (see below). First, let's take a more detailed look at both ways:

ABC

Code

% file abc.tex
\documentclass{scrartcl}
\usepackage{abc}

\begin{document}
Text
\begin{abc}[name=c-dur]
X: 1 % start of header
K: C % scale: C major
"Text"C4 G4 | (3FED c4 G2 |
\end{abc}
\end{document}

Compile

pdflatex --shell-escape abc.tex

Output

ABC output

LilyPond

Code

% file lp.lytex
\documentclass{scrartcl}

\begin{document}
Text
\begin[staffsize=12]{lilypond}
\relative c' {
  c2^"Text" g'2 \times 2/3 { f8 e d } c'2 g4
}
\end{lilypond}
\end{document}

Compile

lilypond-book --output=out-dir --pdf lp.lytex
cd out-dir
pdflatex lp.tex

Output

LilyPond output

Comparison

Now let’s talk about the pros and cons.

  • The ABC workflow is much easier than the one of LilyPond and it simply needs a call of pdflatex. For this it’s preferable for the students of the tutorial since most of them aren't computer geeks.
  • The ABC syntax seems to bee easier at a first glance.
  • LilyPond uses the right font i.e. the font of the LaTeX document.
  • abc.sty always produces a display style image, i.e., it starts a new line and centers it’s content. Furthermore there seems to be now option to shorten the line that they fit just the typed notes and not span the whole \linewidth (workaround: set width=0.5\abcwidth).
  • As far as I can see LilyPond is more flexible in the number of ways to typeset music (inline, display style, …) and the possibilities of typesetting in general.
  • The LilyPond music font looks better except the fat bar lines.

Questions

The numbers are not to give an order. I numbered the questions to make it easy to answer the …

  1. Which way would you prefer to use? Which one do you suggest for students how a not very good in using computers?
  2. I wonder if it will be possible to create a package that integrates LilyPond in the same way that abc.sty does width ABC notation
  3. Can one change the font of the ABC output so that it matches the LaTeX main font?
  4. Is there a way to make ABC find a good line length for the given number of notes?
  5. Can one change the width of LilyPonds bar lines?

Conclusion

I’d prefer to use (and teach) the LilyPond way but I fear the compilation workflow would scare the students. So if question 2 could be solved it would be great :-)

I hope you understand what I want since my english may be not the best. Please ask if something is not clear …

share|improve this question
6  
@PauloCereda recently blogged about this. You can read it here –  percusse Dec 6 '11 at 21:13
    
@percusse: Thank you for this info but this bolg doesn’t say anithing abut a LaTeX integration :-( –  Tobi Dec 9 '11 at 14:50
    
For ABC you did include the package with \usepackage{abc}. How come you don't include any package for the lilypond? I am asking, because i couldn't find the lilypond package myself. –  71GA Apr 14 '12 at 10:22
    
@71GA: (As far as I remeber …) You don’t need a package but you must precompile the document with lilypond-book before you can process it with pdflatex. The precompiling looks for the {lilypond} environment. Crates the score as an image and replaces the environment in the precomiled tex file with commands to include the image. Just process the above example to see how it works. –  Tobi Apr 14 '12 at 14:00
    
Both ways are very valid. But have you also considered musixtex? –  dorien Oct 15 '12 at 8:57
show 4 more comments

2 Answers

up vote 12 down vote accepted

It's not possible to use the same font as the document with ABC, for inherent limitations of the abcm2ps program. However, it's quite a long time since I don't update it and things might have changed (I'll take a look).

It should be easy to add "inline" versions of the music snippet inclusion, which is not there because the package was intended for inclusion of complete tunes.

Integration with LilyPond in the same way is not as easy. I have some "kind-of-working" code. A major hindrance is the difficulty of passing LilyPond parameters and directives from the TeX side (with lilypond-book it's the other way around).

Since there seems to be interest in this topic, I'll try and develop the code. For now, the following code

\begin{filecontents*}{testlily.ly}
\version "2.13.38" 

\include "config.ly" 

\relative c'' { 
c d e c 
}
\end{filecontents*}
\begin{filecontents*}{testlily3.ly}
\version "2.13.38" 

\include "config.ly" 

\relative c' {
  c2^"Text" g'2 \times 2/3 { f8 e d } c'2 g4
}

\end{filecontents*}
\documentclass[draft]{article} 
\usepackage[final]{graphicx} 
\usepackage[MacOSX,between-system-space=3]{lilypond} 
\usepackage{lipsum} 
\pagestyle{empty}
\begin{document}

Test: integrating \LaTeX{} and LilyPond. 

\lilypondfile{testlily} 

Not too bad, isn't it? 

\lipsum[2] 

\lilypondfile{testlily3} 

\end{document}

will produce the following output:

enter image description here

share|improve this answer
1  
Thanks for this and sory for the delayed answer. Could you tell me where I can find lilypond.sty? I found onw at github but that needs a pythonscript … –  Tobi Dec 9 '11 at 14:43
    
@Tobi That's a private package I'm experimenting with. –  egreg Dec 9 '11 at 14:49
    
Could show me your code? I thought about building an onw package but I guess it’s not nessescary that we both do the same jobe … (You may send an e-mail to the address given in my profile) –  Tobi Dec 9 '11 at 14:58
    
@Tobi Sorry, but there isn't any address there. –  egreg Dec 9 '11 at 15:16
    
Thas strange. I can see it if I open my profile. Here ist is: tobias_weh{at}arcor{dot}de –  Tobi Dec 9 '11 at 15:20
show 6 more comments

LyX may be an good for this purpose and the audience you mention. From the LyX Wiki:

Support for LilyPond-Book
LyX now supports LilyPond music notation with the lilypond-book module, by direct entry of LilyPond markup in LyX's window and processing through lilypond-book→(pdf)latex. In combination with the new preview inset, you can view the score directly in the LyX window. For more information see LyX's example file lilypond.lyx.

share|improve this answer
1  
Thank you but I’m not a friend of LyX since it shows some kind of WSIWYG but not the real output (If I understood the programm right) … –  Tobi Dec 9 '11 at 14:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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