]> git.donarmstrong.com Git - lilypond.git/commitdiff
Further improve TeX output. The produced files are about 40%
authorWerner Lemberg <wl@gnu.org>
Mon, 14 Oct 2002 22:18:30 +0000 (22:18 +0000)
committerWerner Lemberg <wl@gnu.org>
Mon, 14 Oct 2002 22:18:30 +0000 (22:18 +0000)
smaller.  `lilyponddefs.tex' is now read only once.

* tex/lilyponddefs.tex: Remove footer stuff.
(\ifundefined): Renamed to...
(\lilypondundefined): This.  Use LaTeX's definition to
make it nestable and make it global.
(\lilypondstart, \lilypondend): New macro to initialize LilyPond
output.
(\lilypondspecial): New macro to read `music-drawing-routines.ps'.
(\fetasixteen, \fetafont, \fetachar, \botalign, \leftalign): Make
them global.
(\placebox): Renamed to...
(\lyitem): This.
Make it global and call \outputscale by itself.
(\lybox, \lyvrule): New macros to reduce input data.
(\lilypondfirst, \lilypondsecond, \lilypondloop, \lilyponditerate):
New auxiliary macros.
(\SkipLilydefs, \EndLilyPondOutput): Removed.
* tex/lily-pdf-defs.tex, tex/lily-ps-defs.tex (\lilySpace): Renamed
to...
(\lilypondspace): This and made it global.
(\turnOnPostScript): Renamed to...
(\lilypondpostscript): This and made it global.
(\turnOnExperimentalFeatures): Renamed to...
(\lilypondexperimentalfeatures): This and made it global.
* tex/lily-ps-defs.tex (\PSsetTeXdimen): Renamed to...
(\lilypondsetdimen): This and made it global.
* tex/lilypond-latex.tex, tex/lilypond-plaintex.tex: Removed.
* tex/GNUmakefile (TEX_FILES): Add `music-drawing-routines.ps'
(all, $(outdir)/music-drawing-routines.ps): New rules.
* buildscripts/mf-to-table.py (write_tex_defs): Use \gdef.
* scm/pdftex.scm, scm/tex.scm (end-output, header-end, placebox,
start-system, stop-system, stop-last-system, filledbox): Updated to
use the changed macros from lilyponddefs.tex.
* scripts/lilypond-book.ly (output_dict) <latex, texi>: Ditto.

ChangeLog
buildscripts/mf-to-table.py
scm/pdftex.scm
scm/tex.scm
scripts/lilypond-book.py
tex/GNUmakefile
tex/lily-pdf-defs.tex
tex/lily-ps-defs.tex
tex/lilypond-latex.tex [deleted file]
tex/lilypond-plaintex.tex [deleted file]
tex/lilyponddefs.tex

index cd7a00f1efdd4ffacb4e93e710547d8fdbe47457..156abc9d7c9f26a6d65abc67e273fc11fe5d7575 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2002-10-14  Werner Lemberg  <wl@gnu.org>
+
+       Further improve TeX output.  The produced files are about 40%
+       smaller.  `lilyponddefs.tex' is now read only once.
+
+       * tex/lilyponddefs.tex: Remove footer stuff.
+       (\ifundefined): Renamed to...
+       (\lilypondundefined): This.  Use LaTeX's definition to
+       make it nestable and make it global.
+       (\lilypondstart, \lilypondend): New macro to initialize LilyPond
+       output.
+       (\lilypondspecial): New macro to read `music-drawing-routines.ps'.
+       (\fetasixteen, \fetafont, \fetachar, \botalign, \leftalign): Make
+       them global.
+       (\placebox): Renamed to...
+       (\lyitem): This.
+       Make it global and call \outputscale by itself.
+       (\lybox, \lyvrule): New macros to reduce input data.
+       (\lilypondfirst, \lilypondsecond, \lilypondloop, \lilyponditerate):
+       New auxiliary macros.
+       (\SkipLilydefs, \EndLilyPondOutput): Removed.
+       * tex/lily-pdf-defs.tex, tex/lily-ps-defs.tex (\lilySpace): Renamed
+       to...
+       (\lilypondspace): This and made it global.
+       (\turnOnPostScript): Renamed to...
+       (\lilypondpostscript): This and made it global.
+       (\turnOnExperimentalFeatures): Renamed to...
+       (\lilypondexperimentalfeatures): This and made it global.
+       * tex/lily-ps-defs.tex (\PSsetTeXdimen): Renamed to...
+       (\lilypondsetdimen): This and made it global.
+       * tex/lilypond-latex.tex, tex/lilypond-plaintex.tex: Removed.
+       * tex/GNUmakefile (TEX_FILES): Add `music-drawing-routines.ps'
+       (all, $(outdir)/music-drawing-routines.ps): New rules.
+       * buildscripts/mf-to-table.py (write_tex_defs): Use \gdef.
+       * scm/pdftex.scm, scm/tex.scm (end-output, header-end, placebox,
+       start-system, stop-system, stop-last-system, filledbox): Updated to
+       use the changed macros from lilyponddefs.tex.
+       * scripts/lilypond-book.ly (output_dict) <latex, texi>: Ditto.
+
 2002-10-07  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * Documentation/windows/installing.texi: Update.
index d8aa7275d931866e163999ab3f4f9b967172225f..998893c9f0e596cb690a4454b407270d568afbe7 100644 (file)
@@ -120,7 +120,7 @@ Comment Automatically generated by mf-to-table.py
 def write_tex_defs (file, global_info, charmetrics):
        nm = global_info['FontFamily']
        for m in charmetrics:
-               file.write (r'''\def\%s%s{\char%d}%%%s''' % (nm, m['tex'], m['code'],'\n'))
+               file.write (r'''\gdef\%s%s{\char%d}%%%s''' % (nm, m['tex'], m['code'],'\n'))
        file.write ('\\endinput\n')
 
 def write_ps_encoding (file, global_info, charmetrics):
index d6fb88196917035e2b9ed7b2faf64f16122d5319..25ba5b604f34eea81fda891376f6a7cb96d40570 100644 (file)
   (begin
                                        ; uncomment for some stats about lily memory      
                                        ;               (display (gc-stats))
-    (string-append "%\n\\EndLilyPondOutput\n"
+    (string-append "%\n\\lilypondend\n"
                                        ; Put GC stats here.
                   )))
 
                    (else (error "unknown unit" (ly-unit)))
                    ))
    "}%\n"
-   "\\input lilyponddefs\n"
+   "\\ifx\\lilypondstart\\undefined\n"
+   "  \\input lilyponddefs\n"
+   "\\fi\n"
    "\\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit\n"
-   "\\turnOnPostScript\n"
+   "\\lilypondpostscript\n"
    "\\pdfcompresslevel=0"))
 
 ;; Note: this string must match the string in ly2dvi.py!!!
    (ly-number->string x) " \\outputscale "))
 
 (define (placebox x y s) 
-  (string-append 
-   "\\placebox{"
-   (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
+  (string-append "\\lyitem{"
+                (ly-number->string y) "}{"
+                (ly-number->string x) "}{"
+                s "}%\n"))
 
 (define (bezier-bow l thick)
   (embedded-pdf (list 'bezier-bow  `(quote ,l) thick)))
 (define (start-system wd ht)
   (string-append "\\leavevmode\n"
                 "\\scoreshift = " (number->dim (* ht 0.5)) "\n"
-                "\\ifundefined{lilypondscoreshift}%\n"
-                "\\else\n"
-                "  \\advance\\scoreshift by -\\lilypondscoreshift\n"
-                "\\fi\n"
-                "\\hbox to " (number->dim wd) "{%\n"
-                "\\lower\\scoreshift\n"
-                "\\vbox to " (number->dim ht) "{\\hbox{%\n"))
+                "\\lilypondifundefined{lilypondscoreshift}%\n"
+                "  {}%\n"
+                "  {\\advance\\scoreshift by -\\lilypondscoreshift}%\n"
+                "\\lybox{"
+                (ly-number->string wd) "}{"
+                (ly-number->string ht) "{%\n"))
 
 (define (stop-system) 
-  "}\\vss}\\hss}\\interscoreline\n")
+  "}%\n%\n\\interscoreline\n%\n")
 (define (stop-last-system)
-  "}\\vss}\\hss}")
+  "}%\n")
+
 (define (filledbox breapth width depth height) 
-  (string-append 
-   "\\kern" (number->dim (- breapth))
-   "\\vrule width " (number->dim (+ breapth width))
-   "depth " (number->dim depth)
-   "height " (number->dim height) " "))
+  (string-append "\\lyvrule{"
+                (ly-number->string (- breapth)) "}{"
+                (ly-number->string (+ breapth width)) "}{"
+                (ly-number->string depth) "}{"
+                (ly-number->string height) "}"))
 
 (define (roundfilledbox x y width height blotdiam)
   (embedded-pdf (list 'roundfilledbox  x y width height blotdiam)))
index dba7f1955cd750abe93b4af25012a4cf7327cba1..9073bf6cd6dde878f254f0d7b9199077c0ad2904 100644 (file)
                                        ; uncomment for some stats about lily memory      
                                        ;               (display (gc-stats))
     (string-append
-     "%\n"
-     "\\EndLilyPondOutput\n"
-     "\\begingroup\n"
-     "\\ifx\\LilyPondDocument\\undefined\n"
-     "  \\def\\x{\\endgroup}%\n"
-     "\\else\n"
-     "  \\def\\x{%\n"
-     "    \\endgroup\n"
-     "    \\enddocument\n"
-     "  }\n"
-     "\\fi\n"
-     "\\x\n"
+     "\\lilypondend\n"
                                        ; Put GC stats here.
                   )))
 
                     ((equal? (ly-unit) "pt") (/ 72.0  72.27))
                     (else (error "unknown unit" (ly-unit)))
                     ))
-    " mul }%\n"
-   "\\special{\\string! "
-   
-   ;; URG: ly-gulp-file: now we can't use scm output without Lily
-   (if use-regex
-       ;; fixed in 1.3.4 for powerpc -- broken on Windows
-       (regexp-substitute/global #f "\n"
-                                (ly-gulp-file "music-drawing-routines.ps") 'pre " %\n" 'post)
-       (ly-gulp-file "music-drawing-routines.ps"))
-;   (if (defined? 'ps-testing) "/testing true def%\n" "")
-   "}%\n"
-   "\\begingroup\n"
-   "\\catcode `\\@=11\n"
-   "\\expandafter\\ifx\\csname @nodocument\\endcsname \\relax\n"
-   "  \\def\\x{\\endgroup}%\n"
-   "\\else\n"
-   "  \\def\\x{%\n"
-   "    \\endgroup\n"
-   "    \\def\\LilyPondDocument{}\n"
-   "    \\documentclass{article}\n"
-   "    \\pagestyle{empty}\n"
-   ; argh, we can't say \begin{document} because \begin is defined as
-   ; \outer in texinfo
-   "    \\begingroup\n"
-   "    \\document\n"
-   "    \\ifdim\\lilypondpaperlinewidth\\lilypondpaperunit > 0pt\n"
-   "      \\hsize\\lilypondpaperlinewidth\\lilypondpaperunit\n"
-   "    \\fi\n"
-   "    \\parindent 0pt\n"
-   "  }\n"
+   " mul }%\n"
+   "\\ifx\\lilypondstart\\undefined\n"
+   "  \\input lilyponddefs\n"
    "\\fi\n"
-   "\\x\n"
-   "\\input lilyponddefs\n"
-   "\\outputscale=\\lilypondpaperoutputscale \\lilypondpaperunit\n"
-   "\\turnOnPostScript\n"))
+   "\\outputscale = \\lilypondpaperoutputscale\\lilypondpaperunit\n"
+   "\\lilypondstart\n"
+   "\\special{\\string!\\lilypondspecial}%\n"
+   "\\lilypondpostscript\n"))
 
 ;; Note: this string must match the string in ly2dvi.py!!!
 (define (header creator generate) 
    (ly-number->string x) " \\outputscale "))
 
 (define (placebox x y s) 
-  (string-append 
-   "\\placebox{"
-   (number->dim y) "}{" (number->dim x) "}{" s "}%\n"))
+  (string-append "\\lyitem{"
+                (ly-number->string y) "}{"
+                (ly-number->string x) "}{"
+                s "}%\n"))
 
 (define (bezier-bow l thick)
   (embedded-ps (list 'bezier-bow  `(quote ,l) thick)))
 (define (start-system wd ht)
   (string-append "\\leavevmode\n"
                 "\\scoreshift = " (number->dim (* ht 0.5)) "\n"
-                "\\ifundefined{lilypondscoreshift}%\n"
-                "\\else\n"
-                "  \\advance\\scoreshift by -\\lilypondscoreshift\n"
-                "\\fi\n"
-                "\\hbox to " (number->dim wd) "{%\n"
-                "\\lower\\scoreshift\n"
-                "\\vbox to " (number->dim ht) "{\\hbox{%\n"))
+                "\\lilypondifundefined{lilypondscoreshift}%\n"
+                "  {}%\n"
+                "  {\\advance\\scoreshift by -\\lilypondscoreshift}%\n"
+                "\\lybox{"
+                (ly-number->string wd) "}{"
+                (ly-number->string ht) "}{%\n"))
 
 (define (stop-system) 
-  "}\\vss}\\hss}\\interscoreline\n")
+  "}%\n%\n\\interscoreline\n%\n")
 (define (stop-last-system)
-  "}\\vss}\\hss}")
+  "}%\n")
 
 (define (filledbox breapth width depth height)
   (if (and #f (defined? 'ps-testing))
       (embedded-ps
        (string-append (numbers->string (list breapth width depth height))
                      " draw_box" ))
-      (string-append 
-       "\\kern" (number->dim (- breapth))
-       "\\vrule width " (number->dim (+ breapth width))
-       "depth " (number->dim depth)
-       "height " (number->dim height) " ")))
+      (string-append "\\lyvrule{"
+                    (ly-number->string (- breapth)) "}{"
+                    (ly-number->string (+ breapth width)) "}{"
+                    (ly-number->string depth) "}{"
+                    (ly-number->string height) "}")))
 
 (define (roundfilledbox x y width height blotdiam)
   (embedded-ps (list 'roundfilledbox  x y width height blotdiam)))
index 77870ede96f1d07a741e8d1c0a8b21ace083efca..fcd0f6fb47181929231f62719fd9a28ad2936920 100644 (file)
@@ -4,7 +4,6 @@
 # * junk --outdir for --output
 # * Figure out clean set of options.
 # *
-# * EndLilyPondOutput is def'd as vfil. Causes large white gaps.
 # * texinfo: add support for @pagesize
 
 # todo: dimension handling (all the x2y) is clumsy. (tca: Thats
@@ -462,16 +461,12 @@ output_dict= {
 %s@end example
 ''',
                # do some tweaking: @ is needed in some ps stuff.
-               # override EndLilyPondOutput, since @tex is done
-               # in a sandbox, you can't do \input lilyponddefs at the
-               # top of the document.
                #
                # ugh, the <p> below breaks inline images...
                'output-texi-noquote': r'''@tex
 \catcode`\@=12
 \parindent 0pt
-\input lilyponddefs
-\def\EndLilyPondOutput{}
+\def\lilypondbook{}
 \input %(fn)s.tex
 \catcode`\@=0
 @end tex
@@ -484,8 +479,7 @@ output_dict= {
                'output-texi-quoted': r'''@quotation
 @tex
 \catcode`\@=12
-\input lilyponddefs
-\def\EndLilyPondOutput{}
+\def\lilypondbook{}
 \input %(fn)s.tex
 \catcode`\@=0
 @end tex
index c9f4c4b19bde51bef61237946a64879403d07092..b58a7e55ce2ba1a92530cfed9b8ce8db76e0e23f 100644 (file)
@@ -1,6 +1,6 @@
 depth = ..
 
-TEX_FILES = $(wildcard *.tex)
+TEX_FILES = $(wildcard *.tex) $(outdir)/music-drawing-routines.ps
 
 EXTRA_DIST_FILES = $(TEX_FILES)
 STEPMAKE_TEMPLATES=install
@@ -10,3 +10,7 @@ INSTALLATION_FILES=$(TEX_FILES)
 
 include $(depth)/make/stepmake.make
 
+$(outdir)/music-drawing-routines.ps: $(depth)/ps/music-drawing-routines.ps
+       -cp $< $@
+
+all: $(INSTALLATION_FILES)
index f85aa5b1e8b5b5bbdf6348c375e5ec444d83db2a..69af9f0465e0dd222e475fad836cd989c6b07663 100644 (file)
@@ -5,23 +5,23 @@
 \edef\lilypdfdefsELC{\the\endlinechar}%
 \endlinechar -1\relax
 
-\def\lilySpace{ }
+\gdef\lilypondspace{ }
 
-\def\turnOnPostScript{
+\gdef\lilypondpostscript{
   % This sets CTM so that you get to the currentpoint
   % by executing a 0 0 moveto
   \def\embeddedpdf##1{
     \pdfliteral{
-      q \lilypondpaperoutputscale\lilySpace 0 0 %
-        \lilypondpaperoutputscale\lilySpace 0 0 cm %
-        \lilyoutputscalefactor\lilySpace 0 0 %
-        \lilyoutputscalefactor\lilySpace 0 0 cm %
+      q \lilypondpaperoutputscale\lilypondspace 0 0 %
+        \lilypondpaperoutputscale\lilypondspace 0 0 cm %
+        \lilyoutputscalefactor\lilypondspace 0 0 %
+        \lilyoutputscalefactor\lilypondspace 0 0 cm %
       ##1 Q
     }
   }
 }
 
-\def\turnOnExperimentalFeatures{}
+\gdef\lilypondexperimentalfeatures{}
 
 \endlinechar \lilypdfdefsELC
 \endinput
index 4efc3c418cb7c622207c37707adba1d3d897bb3c..71e31e8aabc6aadcf9f58ddc710e51b82a66d6d2 100644 (file)
@@ -9,30 +9,30 @@
 % Escape the colon with \string to avoid problems with French while using
 % the Babel package.
 
-\def\PSsetTeXdimen#1{
+\gdef\lilypondsetdimen#1{
   \expandafter\special{
     ! /#1 (\csname #1\endcsname) set_tex_dimen
   }
 }
 
-\def\lilySpace{ }
+\gdef\lilypondspace{ }
 
-\def\turnOnPostScript{
+\gdef\lilypondpostscript{
   % This sets CTM so that you get to the currentpoint
   % by executing a 0 0 moveto
   \def\embeddedps##1{
     \special{
       ps\string: @beginspecial @setspecial %
-                 \lilypondpaperoutputscale\lilySpace\scaletounit %
-                 \lilypondpaperoutputscale\lilySpace\scaletounit %
+                 \lilypondpaperoutputscale\lilypondspace\scaletounit %
+                 \lilypondpaperoutputscale\lilypondspace\scaletounit %
                  % FUCKING REDHAT XDVI -- ARG!
                  skeel ##1 @endspecial
     }
   }
-  \PSsetTeXdimen{lilypondpaperblotdiameter}
+  \lilypondsetdimen{lilypondpaperblotdiameter}
 }
 
-\def\turnOnExperimentalFeatures{}
+\gdef\lilypondexperimentalfeatures{}
 
 \endlinechar \lilypsdefsELC
 \endinput
diff --git a/tex/lilypond-latex.tex b/tex/lilypond-latex.tex
deleted file mode 100644 (file)
index e139af7..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-% lilypond-latex.tex
-%
-\edef\lilypondlatexELC{\the\endlinechar}%
-\endlinechar -1\relax
-
-\message{LaTeX definitions}
-
-\def\texsuffix{LaTeX}
-
-\def\lilyfooterLaTeX{
-  \let\nopagenumbers\relax
-
-  %% FIXME
-  \def\ps@plain{
-    \renewcommand{\@oddhead}{}
-    \renewcommand{\@evenfoot}{}
-    \renewcommand{\@evenhead}{}
-    \renewcommand{\@oddfoot}{
-      \ifnum\thepage = 1\relax
-        {\hfil \lilypondtagline}
-      \else
-        {foo\hfil \the\pageno \hfil}
-      \fi
-    }
-  }
-
-  \def\ps@empty{
-    \renewcommand{\@oddhead}{}
-    \renewcommand{\@evenfoot}{}
-    \renewcommand{\@evenhead}{}
-    \renewcommand{\@oddfoot}{
-      \ifnum\thepage = 1\relax
-        {\hfil \lilypondtagline}
-      \else
-        {foo\hfil \the\pageno \hfil}
-      \fi
-    }
-  }
-
-  \nopagenumbers
-}
-
-\def\nolilyfooterLaTeX{}
-
-\endlinechar \lilypondlatexELC
-\endinput
diff --git a/tex/lilypond-plaintex.tex b/tex/lilypond-plaintex.tex
deleted file mode 100644 (file)
index b269993..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-% lilypond-plaintex.tex
-%
-\edef\lilypondplaintexELC{\the\endlinechar}%
-\endlinechar -1\relax
-
-\message{LilyPond Plain TeX settings}
-
-\def\texsuffix{PlainTeX}
-
-\def\lilyfooterPlainTeX{
-  \footline = {
-    \ifnum\pageno = 1\relax
-      \smalltextfont\lilypondcopyright\hfil \lilypondtagline
-    \else
-      \hfil \the\pageno \hfil
-    \fi
-  }
-}
-
-
-%% make plain work ok Out Of The Box
-
-\ifundefined{lilypondpaperunit}
-\def\lhsize{\hsize} 
-\else
-\def\lhsize{\lilypondpaperlinewidth\lilypondpaperunit}
-\fi
-
-\ifdim0pt<\lhsize
-\hsize=\lhsize
-\fi
-
-\advance\hoffset by -.6in
-
-\def\nolilyfooterPlainTeX{\nopagenumbers}
-
-\endlinechar \lilypondplaintexELC
-\endinput
index acacba8e3db41ce8396528a2815d9e2015c026c6..1cf39f92d319ed03fff4ae93469919e1f8999264 100644 (file)
 %
 % Include file for LilyPond.
 %
-% This file defines various macros to accomodate lilypond output.
+% This file defines various macros to acommodate lilypond output.
+%
+% It should run with plain TeX, LaTeX, pdftex, and texinfo.
+%
+% To avoid interferences, lilyponddefs.tex should be loaded within a group.
+% To load it only once, most of the definitions must be global.
+%
+% The overall structure of a file created by LilyPond is as follows:
+%
+%   <lilypond parameter definitions>
+%   \ifx\lilypondstart \undefined
+%     \input lilyponddefs
+%   \fi
+%   \lilypondstart
+%   <font setup and note output>
+%   \lilypondend
+%
+% No footers and headers are provided for the stand-alone run (i.e., for
+% directly saying `latex <LilyPond output>'.
+%
 %
 % Avoid \par while reading this file.
 \edef\lilyponddefsELC{\the\endlinechar}%
 \endlinechar -1\relax
 
-% TeXbook ex 7.7
-\def\ifundefined#1{
-  \expandafter\ifx\csname#1\endcsname\relax
-}
+% the next three macros are taken from LaTeX
+\long\gdef\lilypondfirst#1#2{#1}
 
-% If we must make titles, do so, before we're skipped.
+\long\gdef\lilypondsecond#1#2{#2}
 
-\ifx\mustmakelilypondtitle\undefined
-\else
-  \makelilypondtitle
-\fi
+\gdef\lilypondifundefined#1{
+  \expandafter\ifx\csname#1\endcsname\relax
+    \expandafter\lilypondfirst
+  \else
+    \expandafter\lilypondsecond
+  \fi
+}
 
-\ifx\mustmakelilypondpiecetitle\undefined
-\else
-  \makelilypondpiecetitle
-\fi
+\gdef\lilypondstart{
+  \begingroup
+  \catcode `\@=11\relax
+  % \@nodocument is defined as \relax after `\begin{document}'
+  \lilypondifundefined{@nodocument}
+    {
+      % either plain TeX or texinfo or not at the beginning of LaTeX input
+      \def\x{\endgroup}
+    }
+    {
+      % provide a proper LaTeX preamble (for A4 paper format)
+      \def\x{
+        \endgroup
+        \def\lilyponddocument{}
+        \documentclass[a4paper]{article}
+        \pagestyle{empty}
+        % \begin is defined as \outer in texinfo, thus we use \csname
+        \csname begin\endcsname{document}
+        % center staves horizontally on page
+        \ifdim\lilypondpaperlinewidth\lilypondpaperunit > 0pt
+          \hsize\lilypondpaperlinewidth\lilypondpaperunit
+          % we abuse \scoreshift temporarily
+          \scoreshift \paperwidth
+          \advance\scoreshift -\the\hsize
+          \scoreshift 0.5\scoreshift
+          \advance\scoreshift -1in
+          \oddsidemargin \scoreshift
+          \evensidemargin \scoreshift
+        \fi
+        \parindent 0pt
+      }
+    }
+
+  \x
+
+  \lilypondifundefined{mustmakelilypondtitle}
+    {}
+    {\makelilypondtitle}
+
+  \lilypondifundefined{mustmakelilypondpiecetitle}
+    {}
+    {\makelilypondpiecetitle}
+}
 
-% skip if included already
+\gdef\lilypondend{
+  \lilypondifundefined{lilypondbook}
+    {\lilypondifundefined{lilypondpaperlastpagefill}
+      {\vskip 0pt plus \lilypondpaperinterscorelinefill00 fill}
+      {}
+    }
+    {}
+
+  \begingroup
+  \lilypondifundefined{lilyponddocument}
+    {
+      \def\x{\endgroup}
+    }
+    {
+      \def\x{
+        \endgroup
+        \csname end\endcsname{document}
+      }
+    }
+
+  \x
+}
 
-\def\SkipLilydefs{
-  \endlinechar \lilyponddefsELC
-  \endinput}
-\ifundefined{EndLilyPondOutput}
-  \def\EndLilyPondOutput{\csname bye\endcsname}
-  \def\SkipLilydefs{}
-\fi
-\SkipLilydefs
+% this is an inversed \loop ... \repeat macro
+\def\lilypondloop#1\lilypondrepeat{
+  \def\lilypondbody{#1}
+  \lilyponditerate
+}
 
-% need to do some stuff to turn page numbering off
+\def\lilyponditerate{
+  % \if ...
+    \lilypondbody
+    \let\lilypondnext \relax
+  \else
+    \let\lilypondnext \lilyponditerate
+  \fi
+  \lilypondnext
+}
 
-\ifundefined{documentclass}
-  \input lilypond-plaintex
-\else
-  \input lilypond-latex
-\fi
+\newread\lilypondinput
+
+% after executing the following code, \lilypondspecial contains the
+% contents of `music-drawing-routines.ps'
+\lilypondifundefined{lilypondspecial}
+  {
+    \begingroup
+      \openin\lilypondinput music-drawing-routines.ps
+      \xdef\lilypondspecial{}
+      \lilypondloop
+        \endlinechar \lilyponddefsELC
+        \catcode`\^^M 10\relax
+        \read\lilypondinput to \lilypondspecialline
+        \expandafter\xdef\expandafter\lilypondspecial\expandafter{
+          \lilypondspecial\lilypondspecialline
+        }
+        \ifeof\lilypondinput
+      \lilypondrepeat
+      \closein\lilypondinput
+    \endgroup
+  }
+  {}
 
-% The feta characters
+% the feta characters
 \input feta20
 
-\font\fetasixteen = feta16
-\def\fetafont{\fetasixteen}
-\def\fetachar#1{\hbox{\fetasixteen#1}}
+\global\font\fetasixteen = feta16
+\gdef\fetafont{\fetasixteen}
+\gdef\fetachar#1{\hbox{\fetasixteen#1}}
 
-\def\botalign#1{
+\gdef\botalign#1{
   \vbox to 0pt{\vss #1}
 }
-\def\leftalign#1{
+\gdef\leftalign#1{
   \hbox to 0pt{#1\hss}
 }
 
-% Attempt to keep lilypiecetitle together with the piece:
+\gdef\lyitem#1#2#3{
+  \botalign{
+    \hbox{\raise #1\outputscale
+          \leftalign{\kern #2\outputscale #3}}
+  }
+}
 
-%
-% TODO: figure this out.
-%
+\gdef\lybox#1#2#3{
+  \hbox to #1\outputscale {
+    \lower\scoreshift \vbox to #2\outputscale {
+      \hbox{#3}
+      \vss
+    }
+    \hss
+  }
+}
 
-\def\myfilbreak{}%\par\vfil\penalty200\vfilneg}
+\gdef\lyvrule#1#2#3#4{
+  \kern #1\outputscale
+  \vrule width #2\outputscale depth #3\outputscale height #4\outputscale
+}
 
+% Attempt to keep lilypiecetitle together with the piece:
+%
+% TODO: figure this out.
+\gdef\myfilbreak{}%\par\vfil\penalty200\vfilneg}
 
-\ifundefined{lilypondpaperinterscorelinefill}
-  \def\lilypondpaperinterscorelinefill{0}
-\else
-  \def\lilypondpaperinterscorelinefill{1}
-\fi
+\lilypondifundefined{lilypondpaperinterscorelinefill}
+  {\gdef\lilypondpaperinterscorelinefill{0}}
+  {\gdef\lilypondpaperinterscorelinefill{1}}
 
-\def\interscoreline{
+\gdef\interscoreline{
   \vskip \lilypondpaperinterscoreline \lilypondpaperunit
     plus \lilypondpaperinterscorelinefill fill
 }
 
-\def\placebox#1#2#3{
-  \botalign{
-    \hbox{\raise #1\leftalign{\kern #2{}#3}}
-  }
-}
-
 % Are we using PDFTeX?  If so, use pdf definitions.
-% MiKTeX checks \pdfoutput the wrong way; this makes our
-% check more complicated.
-\ifx\pdfoutput\undefined  
-  \input lily-ps-defs
-\else
-  \ifx\pdfoutput\relax
-    \input lily-ps-defs
-  \else
-    \pdfoutput = 1
-    \input lily-pdf-defs
-  \fi
-\fi
-
-\def\EndLilyPondOutput{
-  \ifundefined{lilypondpaperlastpagefill}
-    \vskip 0pt plus \lilypondpaperinterscorelinefill00 fill
-  \fi
-  \csname bye\endcsname
-}
+% MiKTeX checks \pdfoutput the wrong way, thus we use \csname.
+\lilypondifundefined{lilypondpostscript}
+  {
+    \lilypondifundefined{pdfoutput}
+      {\input lily-ps-defs }
+      {
+        \pdfoutput = 1
+        \input lily-pdf-defs
+      }
+  }
+  {}
 
-% Need to do some stuff to turn page numbering off;
-% they seriously mess up your fragments.
-
-\ifx\csname nolilyfooter\endcsname\relax
-  \message{[footer defined]}
-  \csname lilyfooter\texsuffix\endcsname
-\else
-  \message{[footer empty]}
-  \csname nolilyfooter\texsuffix\endcsname
-\fi
-
-% It is very bad that lilyponddefs.tex gets included in every lilypond
-% output snippet.  This is necessary because these output snippets
-% often get encapsulated, eg by texinfo. This should be fixed by
-% putting the variable parts in this file into a macro so that loading
-% the file multiple times can be avoided.
-\ifx\outputscale\undefined
-  \csname global\endcsname\csname newdimen\endcsname\outputscale
-  \csname global\endcsname\csname newdimen\endcsname\scoreshift
-\fi
+\newdimen\outputscale
+\newdimen\scoreshift
 
 % Restore newline functionality (disabled to avoid \par).
 \endlinechar \lilyponddefsELC
 \endinput
+
+% EOF