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

That would be great of course.
Just recently I discovered that there are packages to use Python from within 
LaTeX. I think I'll have a look at that too. Not only is that a language I 
already know, but as it's the same as lilypond-book it might be possible to 
reuse some of that.

A bit cleaned up and extended, can be compiled to with lualatex and xelatex.

cu,
 Knut
\NeedsTeXFormat{LaTeX2e}
\documentclass[10pt]{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}

%
% compile with
%   lualatex --shell-escape lily_xe_lua_latex.tex
% or
%   xelatex --shell-scape lily_xe_lua_latex.tex
%

\def\tmpNameFull{tmplily.ly}       \newwrite\tmpFileFull
\def\tmpNameHead{tmplilyhead.ly}   \newwrite\tmpFileHead
\def\tmpNameTail{tmplilytail.ly}   \newwrite\tmpFileTail
\def\tmpNamePaper{tmplilypaper.ly} \newwrite\tmpFilePaper
\def\tmpNamePdf{tmplily.pdf }      \newwrite\tmpFilePdf

\def\tmpfragprefix{tmplilyfrag}

\def\lilycommand{lilypond }

\newcount\fragcount

{
  \catcode`|=0 \catcode`[=1 \catcode`]=2 \catcode`\#=12
  \catcode`\{=12 \catcode`\}=12 \catcode`\\=12
  |gdef|eofull[\end{lilyfull}]
  |gdef|eohead[\end{lilyhead}]
  |gdef|eofrag[\end{lilyfrag}]
  |gdef|eotail[\end{lilytail}]
  |gdef|hashtag[#]
  |gdef|escape[\]
  |gdef|definepaper[\definepaper]
]

{
  \obeylines
  \gdef\doline#1
  {
    \def\oneline{#1}
    \ifx\oneline\eofull
       \def\next{\end{lilyfull}}
    \else
       \ifx\oneline\eohead
          \def\next{\end{lilyhead}}
       \else 
          \ifx\oneline\eofrag
             \def\next{\end{lilyfrag}}
          \else 
             \ifx\oneline\eotail
                \def\next{\end{lilytail}}
             \else 
                \ifx\oneline\definepaper
                   \immediate\write\tmpFile{\escape include "\tmpNamePaper"}
                   \let\next\doline
                \else
                   \immediate\write\tmpFile{\oneline}
                   \let\next\doline
                \fi
             \fi
          \fi
       \fi
    \fi
    \next%
  }
}

\makeatletter

\newenvironment{lilyfull}[2]{
  \global\advance\fragcount by 1
  \immediate\openout\tmpFileFull=\tmpNameFull
  \gdef\tmpFile{\tmpFileFull}
  \immediate\openout\tmpFilePaper=\tmpNamePaper
  \immediate\write\tmpFilePaper{\hashtag(set!
     paper-alist (cons '("mySize" . (cons (* #1) (* #2))) paper-alist))}
  \immediate\closeout\tmpFilePaper
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\closeout\tmpFileFull
  \immediate\write18{\lilycommand \tmpNameFull}
  \immediate\write18{pdfcrop \tmpNamePdf \tmpfragprefix\the\fragcount.pdf}
  \begin{center}\includegraphics{\tmpfragprefix\the\fragcount.pdf}\end{center}
}

\newenvironment{lilyfrag}[2]{
  \global\advance\fragcount by 1
  \immediate\openout\tmpFileFull=\tmpNameFull
  \gdef\tmpFile{\tmpFileFull}
  \immediate\write\tmpFileFull{\escape include "\tmpNameHead"}
  \immediate\openout\tmpFilePaper=\tmpNamePaper
  \immediate\write\tmpFilePaper{\hashtag(set!
     paper-alist (cons '("mySize" . (cons (* #1) (* #2))) paper-alist))}
  \immediate\closeout\tmpFilePaper
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\write\tmpFileFull{\escape include "\tmpNameTail"}
  \immediate\closeout\tmpFileFull
  \immediate\write18{\lilycommand \tmpNameFull}
  \immediate\write18{pdfcrop \tmpNamePdf \tmpfragprefix\the\fragcount.pdf}
  \begin{center}\includegraphics{\tmpfragprefix\the\fragcount.pdf}\end{center}
}

\newenvironment{lilyhead}{
  \immediate\openout\tmpFileHead=\tmpNameHead
  \gdef\tmpFile{\tmpFileHead}
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\closeout\tmpFileHead
}

\newenvironment{lilytail}{
  \immediate\openout\tmpFileTail=\tmpNameTail
  \gdef\tmpFile{\tmpFileTail}
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\closeout\tmpFileTail
}

\makeatother

\def\lorem{
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
  labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco 
  laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in 
  voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 
  non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
}

\begin{document}
\pagestyle{empty}

\lorem

\begin{lilyfull}{10 cm}{4.5 cm}
\version "2.18.2"
\include "deutsch.ly"

% Below a page size definition will be inserted instead of \definepaper!
\definepaper

\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 Lyrics.LyricText  #'font-name = #"CMU Serif"
    \override LyricText.font-size = \absFontSize #10
    \override StanzaNumber.font-name = #"CMU Serif Extra"
    \override StanzaNumber.font-size = \absFontSize #10
  }
}
\end{lilyfull}

\begin{lilyhead}
\version "2.18.2"
\include "deutsch.ly"
% Below a page size definition will be inserted instead of \definepaper!
\definepaper
\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 = ##t ragged-last-bottom = ##t ragged-right = ##f
}
\header {
  tagline = ##f
}
#(set-global-staff-size 17)
\score {
  <<
\end{lilyhead}

\begin{lilytail}
  >>
  \layout {
    \context {
      \Score
      \omit BarNumber
    }
  }
}
\end{lilytail}

\lorem 

\begin{lilyfrag}{8 cm}{5 cm}
 \relative g'{ \key es \major \time 6/4 \partial 4 g4 b2 as4 g2 f4 es (f) g f2 \breathe}
\end{lilyfrag}

\lorem

\begin{lilyfrag}{9 cm}{5 cm}
  \relative g'{\key es \major \time 6/4 \partial 4 b4 as2 as4 g2 g4 f (es) f es2 \breathe }
\end{lilyfrag}

\lorem

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

Reply via email to