On 06.11.2013 09:34, Urs Liska wrote:
Am 06.11.2013 07:05, schrieb Joshua Nichols:
I guess in the end I didn't understand anything at all, and my hard head saw LaTeX and 
didn't see "preprocessed with lilypond-book."

Maybe this is a good opportunity to hook in.
If there is anybody out there experienced with LaTeX and Lua I'd be glad he/she 
would get in touch with me.

I have written a LaTeX package 'musicexamples' 
(http://www.openlilylib.org/musicexamples) which is currently useful but not 
spectacularly unique. I'm using it for managing music examples in my LaTeX 
documents.
It's on my agenda however to extend this package through Lua (although the new 
functionality would of course be restricted to LuaLaTeX) in order to accept 
embedded LilyPond code like lilypond-book does.

For bigger projects I prefer separate files, but maybe the attached file is 
useful for your project.
It demonstrates how to include a lilypond file in a lualatex document.

   lualatex --shell-escape lilyinluatex.tex

will generate a lilypond file, call lillypond and pdfcrop to generate a proper 
pdf and include it in lilyinluatex.pdf
Lilypond lyrics font and size exactly match the default TeX font.

It's not the explicit intention to make a verbatim copy of lilypond-book, but 
moving the functionality _inside_ the LaTeX compilation process would offer at 
least the following fixes for problems that have so far led me not to use 
lilypond-book:

- You can compile the document at any time directly, no need for preprocessing 
and intermediate .tex files
- You don't have to chose between cluttering your working directory with 
intermediate files
  or causing relative-path problems by using the -out option
- You have reliable access to the _currently effective_ text width, e.g. in 
multicolumn context

I know that even without any prior Lua experience I would be able to dive into that and somehow manage to come up with something.

lualatex is a good engine as it has native utf8 support.  I don't think that 
you do need lua, TeX is enough

cu,
 Knut
\NeedsTeXFormat{LaTeX2e}
\documentclass[10pt,twoside]{letter}
\usepackage{geometry}
\geometry{a4paper,noheadfoot,nomarginpar,left=1.5cm,right=1.5cm,top=1.5cm,bottom=1.5cm,}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=old]{german}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}
\usepackage{graphicx}
\usepackage{luatex}
\pdfcompresslevel=9

% lualatex and lilypond mixed in one file
%
% tex, lilypond headers and lyrics use the same fonts.
%
% lyrics fontsize matches the fontsize of the TeX \normalsize.
%
% Use lualatex --shell-escape lilyinluatex to generate pdf.
%
% lualatex will
%   write tmplily.ly,
%   call lilypond to generate tmplily.pdf
%   call pdfcrop to remove extra white space
%

\def\tmplilyname{tmplily.ly }
\def\tmppdfname{tmplily.pdf }
\def\lilycommand{lilypond }

\newwrite\tmplilyfile

{
  \catcode`|=0 \catcode`[=1 \catcode`]=2
  \catcode`\{=12 \catcode`\}=12 \catcode`\\=12
  |gdef|eolily[\end{lilypage}]
]

\obeylines
\def\doline#1
{
  \def\oneline{#1}
  \ifx\oneline\eolily
     \def\next{\end{lilypage}}
  \else
     \immediate\write\tmplilyfile{\oneline}
     \let\next\doline
  \fi
  \next%
}

\makeatletter
\newenvironment{lilypage}[1]{
  \gdef\lilypdf{#1}
  \immediate\openout\tmplilyfile=\tmplilyname
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\closeout\tmplilyfile
  \immediate\write18{\lilycommand \tmplilyname}%
  \immediate\write18{pdfcrop \tmppdfname \lilypdf}%
}

\makeatother

\begin{document}
\pagestyle{empty}

Remember to use \verb+lualtex --shell-escape example.tex+

\begin{lilypage}{example1.pdf}
\version "2.18.2"
\include "deutsch.ly"
#(set! paper-alist (cons '("mySize" . (cons (* 10 cm) (* 4.5 cm))) paper-alist))

\paper {
  #(set-paper-size "mySize") left-margin = 0\cm top-margin = 0\cm bottom-margin = 0\cm 
  line-width = \paper-width indent = 0 page-count = #1 
  ragged-bottom = ##f ragged-last-bottom = ##f annotate-spacing=##f
}

\header {
  title = \markup { \override #'(font-name . "CMU Serif Bold") "Macht hoch die Tür" }
  subtitle = \markup { \override #'(font-name . "CMU Serif Bold") "Only an example" }
  tagline = ##f
}

#(set-global-staff-size 17)
allowGrobCallback = #(define-scheme-function (parser location syms) (symbol-list?)
  (let ((interface (car syms)) (sym (cadr syms))) #{ \with { \consists #(lambda (context)
  `((acknowledgers . ((,interface . ,(lambda (engraver grob source-engraver)
  (let ((prop (ly:grob-property grob sym))) (if (procedure? prop) 
  (ly:grob-set-property! grob sym (prop grob))))))))))}#}))

absFontSize = #(define-scheme-function (parser location pt)(number?)
  (lambda (grob) (let* ((layout (ly:grob-layout grob))
  (ref-size (ly:output-def-lookup (ly:grob-layout grob) 'text-font-size 12)))
  (magnification->font-size (/ pt ref-size))))) 

\score {
  <<
    \new Voice = "Melody" \relative g'{
      \key es \major \time 6/4 \partial 4
      g4 b2 as4 g2 f4 es (f) g f2 \breathe \bar"" \break
      b4 as2 as4 g2 g4 f (es) f es2 \breathe
    }
    \new Lyrics \lyricsto "Melody" {
      \set stanza = "1."
      Macht hoch die Tür, die Tor macht weit;
      es kommt der Herr der Herr -- lich -- keit,
    }
  >>
  \layout {
    \context {
      \Score
      \allowGrobCallback font-interface.font-size
      \omit BarNumber
    }
    \override LyricText.font-size = \absFontSize #10
    \override Lyrics.LyricText  #'font-name = #"CMU Serif"
    \override StanzaNumber.font-name = #"CMU Serif Extra"
    \override StanzaNumber.font-size = \absFontSize #10
  }
}
\end{lilypage}

\includegraphics{\lilypdf} 

\end{document}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to