Tuesday, April 22, 2008

LilyPond text spanner text with \halign

Text spanner text can align directly in markup. Use \halign



\new Staff {
c'4
\override TextSpanner #'bound-details #'left #'stencil-align-dir-y =
#center
\override TextSpanner #'bound-details #'left #'text =
\markup { \halign #-1 \italic "vif" \hspace #2 }
c'4 \startTextSpan
c'4
c'4 \stopTextSpan
}


\new Staff {
c'4
\override TextSpanner #'bound-details #'left #'stencil-align-dir-y =
#center
\override TextSpanner #'bound-details #'left #'text =
\markup { \halign #0 \italic "vif" \hspace #2 }
c'4 \startTextSpan
c'4
c'4 \stopTextSpan
}


\new Staff {
c'4
\override TextSpanner #'bound-details #'left #'stencil-align-dir-y =
#center
\override TextSpanner #'bound-details #'left #'text =
\markup { \halign #1 \italic "vif" \hspace #2 }
c'4 \startTextSpan
c'4
c'4 \stopTextSpan
}

The reference point is, in each case, the left edge of the attachment note.

TextSpanner #'right #'attach-dir

Text spanners attach to the left edge of parent noteheads at both the start and stop of the spanner. This makes sense at the start of the spanner but stops the spanner too early.



\new Staff {
\set Score.proportionalNotationDuration = #(ly:make-moment 1 24)
\override TextSpanner #'style = #'dashed-line
\override TextSpanner #'dash-period = #0.5
\override TextSpanner #'bound-details #'left #'text = \markup { \italic "coperta " }
\override TextSpanner #'bound-details #'left #'stencil-align-dir-y = #0
\override TextSpanner #'bound-details #'right #'text = \markup { \draw-line #'(0 . -1) }
c'4 \startTextSpan
c'4
c'4
c'4 \stopTextSpan
}

Overriding #'right #'attach-dir to #1 fixes this.



\new Staff {
\set Score.proportionalNotationDuration = #(ly:make-moment 1 24)
\override TextSpanner #'style = #'dashed-line
\override TextSpanner #'dash-period = #0.5
\override TextSpanner #'bound-details #'left #'text = \markup { \italic "coperta " }
\override TextSpanner #'bound-details #'left #'stencil-align-dir-y = #0
\override TextSpanner #'bound-details #'right #'attach-dir = #1
\override TextSpanner #'bound-details #'right #'text = \markup { \draw-line #'(0 . -1) }
c'4 \startTextSpan
c'4
c'4
c'4 \stopTextSpan
}

The righthand nib now ends correctly.

Saturday, April 19, 2008

Externalizing preamble material and using lilypond-book

lilypond-book processes this minimal LaTeX file just fine.

\documentclass[10pt]{article}
\begin{document}
Hello!
\end{document}

But when we externalize the one-line preamble to a separate file, lilypond-book grumbles.

\include{test-preamble}
\begin{document}
Hello!
\end{document}

With the contents of test-preamble.tex as \documentclass[10pt]{article}.

$ lilypond-book --pdf --output=out test.tex
lilypond-book (GNU LilyPond) 2.11.43
Reading test.tex...
Running latex...This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
%&-line parsing enabled.
entering extended mode
(/tmp/tmpUlfqXl.tex
LaTeX2e <2005/12/01>
Babel ...

\@input{test-preamble.aux}
No file test-preamble.tex.
No file tmpUlfqXl.aux.

! LaTeX Error: The font size command \normalsize is not defined:
there is probably something wrong with the class file.

See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.
...

l.5 \begin{document}

textwidth=8191.99998pt
columnsep=0.0pt
(./tmpUlfqXl.aux) )
(see the transcript file for additional information)
No pages of output.
Transcript written on tmpUlfqXl.log.
command failed: latex /tmp/tmpUlfqXl.tex
Child returned 1

So does lilypond-book know how to process LaTeX \includes? Or is this a known limitation for which the workaround is not to externalize when using lilypond-book?

Sunday, April 13, 2008

Fixing lilypond-book 2.11.43

Upgrading from LilyPond 2.11.41 to 2.11.43 this morning broke lilypond-book. The problem seems to be due to a python versioning problem. A special import statement makes an easy fix. Details follow.

lilypond-book is a python script with the shell directive #!/usr/bin/python as the first line. No problem unless /usr/bin/python points to a version of python older than 2.4. This is, on my system, in fact the case.

$ /usr/bin/python -V
Python 2.3.5

Why is this is a problem? Because the python set( ) constructor didn't become a language built-in until version 2.4 or so. Prior to that, you had to invoke set( ) with something like sets.Set( ) after importing the sets module somewhere.

On my box I have python 2.5 installed and set as to run as the default python in my path.

$ which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python

$ `which python` --version
Python 2.5

So I have two options.

  1. Fix lilypond-book to look at the python 2.5 install on my user path
  2. Stick an import statement somewhere at the top of lilypond-book so python 2.3.5 can reference sets.Set( ) globally as set( )

I don't know enough lilypond-book for option #1 so I went the option #2 route instead and stuck from sets import Set as set at line 37. And now lilypond-book 2.11.43 is happy.

There's a bug-lilypond thread open on lilypond-book 2.11.43 troubles. Graham started the thread, Han-Wen replied, and maybe these notes will help find the fix.



Friday, April 11, 2008

Right- and left-aligned LilyPond page numbers

Use \fill-line with an empty " " string followed by the magic page number incantation to right-align page numbers.

\markup {
\fill-line {
" "
\on-the-fly #print-page-number-check-first
\fromproperty #'page:page-number-string
}
}

Swap both arguments to left-align.

\markup {
\fill-line {
\on-the-fly #print-page-number-check-first
\fromproperty #'page:page-number-string
" "
}
}