+%% This macro provides the necessary setup to make the lilypond data
+%% work with plain TeX, LaTeX, and texinfo.
+%%
+%% The reason of using \begingroup and \endgroup is to make the macro \x
+%% immediately disappear after it has been executed. Since we have \def
+%% within \def within \gdef, four hash signs (`#') are needed for
+%% parameters.
+%%
+%% \lilypondfontencoding is emitted by LilyPond to set the encoding of
+%% text strings.
+%%
+\gdef\lilypondstart{
+ \frenchspacing
+ \outputscale \lilypondpaperoutputscale\lilypondpaperunit
+
+ \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
+
+ \def\lilypondfontencoding####1{
+ \lilypondECencoding}
+ \def\lilypondpagebreak{
+ \eject}
+ \def\lilypondnopagebreak{
+ \ifvmode
+ \penalty 10000\relax
+ \fi}}}
+
+ {%% LaTeX mode: Provide a complete preamble.
+ \def\x{
+ \endgroup
+
+ %% Indicate that we shall emit `\end{document}' while executing
+ %% \lilypondend.
+ \def\lilyponddocument{}
+
+ \def\lilypondfontencoding####1{
+ \fontencoding{####1}
+ \selectfont}
+ \def\lilypondpagebreak{
+ \newpage}
+ \def\lilypondnopagebreak{
+ \nopagebreak}
+
+ \documentclass[\lilyponddocumentclassoptions]{article}
+
+ %% As a safety guard, don't produce auxiliary files.
+ \nofiles
+
+ %% FIXME: workaround non-existent TeX.def.
+ \def\TeXdef{TeX}\ifx\TeXdef\lilypondpaperinputencoding
+ \usepackage[latin1]{inputenc}
+ \else
+ \usepackage[\lilypondpaperinputencoding]{inputenc}
+ \fi
+ \pagestyle{empty}
+
+ \usepackage{color}
+
+ \lilypondifundefined{lilypondclassic}
+ {%% If not in `classic' mode, undo LaTeX's page layout settings
+ %% since LilyPond does the layout by itself.
+ \topmargin-1in
+ \headheight0pt\headsep0pt
+ \oddsidemargin-1in
+ \evensidemargin\oddsidemargin}
+
+ {%% Otherwise center output horizontally, without changing the
+ %% vertical positioning.
+ \hsize\lilypondpaperlinewidth\lilypondpaperunit
+ \lytempdim \paperwidth
+ \advance\lytempdim -\the\hsize
+ \lytempdim 0.5\lytempdim
+ \advance\lytempdim -1in
+ \oddsidemargin \lytempdim
+ \evensidemargin \lytempdim}
+
+ \parindent 0pt
+
+ %% We can't directly say `\begin{document}' in this macro since
+ %% older versions of texinfo.tex define \begin as \outer; this
+ %% means that it causes an error if \begin is found within another
+ %% macro (even if the corresponding code will never be executed).
+ %% As a workaround we use \csname to call \begin.
+ \csname begin\endcsname{document}}}
+ \x}
+
+%% The opposite of \lilypondstart.
+%%
+\gdef\lilypondend{
+ %% Handle the `lastpagefill' parameter from the \layout block.
+ %% Ignore it if \lilypondbook is defined.
+ \lilypondifundefined{lilypondbook}
+ {\lilypondifundefined{lilypondpaperlastpagefill}
+ {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
+ {}}
+ {}
+
+ \begingroup
+ \lilypondifundefined{lilyponddocument}
+ {\def\x{
+ \endgroup}}
+ {\def\x{
+ \endgroup
+ \csname end\endcsname{document}}}
+ \x}
+
+%% Load the PostScript drawing routines. This is done using \special.
+%% To avoid multiple inclusions, redefine \lilypondspecial to a no-op
+%% afterwards.
+%%
+\gdef\lilypondspecial{
+ \special{header=music-drawing-routines.ps}
+ \gdef\lilypondspecial{}}