1 %%% lilyponddefs.tex -- TeX macros for LilyPond output.
3 %%% source file of the GNU LilyPond music typesetter
5 %%% (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 %%% Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 %%% Mats Bengtsson <mats.bengtsson@s3.kth.se>
10 %% Avoid \par while reading this file.
12 \edef\lilyponddefsELC{\the\endlinechar}%
15 %% This runs with plain TeX, LaTeX, pdftex, and texinfo.
17 %% To avoid interferences, lilyponddefs.tex must be loaded within a group.
18 %% It is loaded only once, so the definitions must be global.
20 %% The overall structure of a file created by LilyPond is as follows:
22 %% <lilypond parameter definitions>
24 %% \ifx\lilypondstart \undefined
25 %% \input lilyponddefs
31 %% A temporary variable.
35 %% The scaling factor for all dimensions.
39 \long\gdef\lilypondfirst#1#2{#1}
40 \long\gdef\lilypondsecond#1#2{#2}
42 %% \lilypondundefined{xxx}{foo}{bar}
44 %% If `xxx' (without the leading backslash) is an undefined macro,
45 %% execute block `foo'. Otherwise, execute block `bar'. Based on
46 %% a similar macro from the LaTeX kernel.
48 \gdef\lilypondifundefined#1{
49 \expandafter\ifx\csname#1\endcsname\relax
50 \expandafter\lilypondfirst
52 \expandafter\lilypondsecond
56 %% Urgh. LilyPond uses EC fonts, but texinfo is based on CM. We thus
57 %% have to handle T1 font encoding by ourselves; all manipulations are
58 %% collected in the macro \lilypondECencoding. Note that the following
59 %% code only provides the texinfo interface, not complete access to all
62 %% All definitions are taken from texinfo or LaTeX (with modifications
67 \gdef\lilypondECencoding{
99 % \def\tieaccent##1{} % unsupported: this is TS1
108 \sh@ft{29}\vbox to.2ex{
123 \chardef\exclamdown=189
124 \chardef\questiondown=190
144 %% This macro provides the necessary setup to make the lilypond data
145 %% work with plain TeX, LaTeX, and texinfo.
147 %% The reason of using \begingroup and \endgroup is to make the macro \x
148 %% immediately disappear after it has been executed. Since we have \def
149 %% within \def within \gdef, four hash signs (`#') are needed for
152 %% \lilypondfontencoding is emitted by LilyPond to set the encoding of
157 \outputscale \lilypondpaperoutputscale\lilypondpaperunit
160 \catcode `\@=11\relax
162 %% \@nodocument is defined as \relax after `\begin{document}'
163 \lilypondifundefined{@nodocument}
164 {%% Either plain TeX or texinfo or not at the beginning of LaTeX input.
168 \def\lilypondfontencoding####1{
170 \def\lilypondpagebreak{
172 \def\lilypondnopagebreak{
177 {%% LaTeX mode: Provide a complete preamble.
181 %% Indicate that we shall emit `\end{document}' while executing
183 \def\lilyponddocument{}
185 \def\lilypondfontencoding####1{
188 \def\lilypondpagebreak{
190 \def\lilypondnopagebreak{
193 \documentclass[\lilyponddocumentclassoptions]{article}
195 %% As a safety guard, don't produce auxiliary files.
198 %% FIXME: workaround non-existent TeX.def.
199 \def\TeXdef{TeX}\ifx\TeXdef\lilypondpaperinputencoding
200 \usepackage[latin1]{inputenc}
202 \usepackage[\lilypondpaperinputencoding]{inputenc}
206 \lilypondifundefined{lilypondclassic}
207 {%% If not in `classic' mode, undo LaTeX's page layout settings
208 %% since LilyPond does the layout by itself.
210 \headheight0pt\headsep0pt
212 \evensidemargin\oddsidemargin}
214 {%% Otherwise center output horizontally, without changing the
215 %% vertical positioning.
216 \hsize\lilypondpaperlinewidth\lilypondpaperunit
217 \lytempdim \paperwidth
218 \advance\lytempdim -\the\hsize
219 \lytempdim 0.5\lytempdim
220 \advance\lytempdim -1in
221 \oddsidemargin \lytempdim
222 \evensidemargin \lytempdim}
226 %% We can't directly say `\begin{document}' in this macro since
227 %% older versions of texinfo.tex define \begin as \outer; this
228 %% means that it causes an error if \begin is found within another
229 %% macro (even if the corresponding code will never be executed).
230 %% As a workaround we use \csname to call \begin.
231 \csname begin\endcsname{document}}}
234 %% The opposite of \lilypondstart.
237 %% Handle the `lastpagefill' parameter from the \layout block.
238 %% Ignore it if \lilypondbook is defined.
239 \lilypondifundefined{lilypondbook}
240 {\lilypondifundefined{lilypondpaperlastpagefill}
241 {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
246 \lilypondifundefined{lilyponddocument}
251 \csname end\endcsname{document}}}
254 %% Load the PostScript drawing routines. This is done using \special.
255 %% To avoid multiple inclusions, redefine \lilypondspecial to a no-op
258 \gdef\lilypondspecial{
259 \special{header=music-drawing-routines.ps}
260 \gdef\lilypondspecial{}}
262 %% The most used macro in LilyPond output. Put #3 into a zero-width box
263 %% which is moved to the right by #1 (scaled by \outputscale) and moved
264 %% up by #2 (also scaled by \outputscale).
267 \raise #2\outputscale \hbox to 0pt {
272 %% All LilyPond music data is enclosed in this macro (as third argument).
273 %% The data (which consists of boxes with zero width) gets an artificial
274 %% width of #1 and a height of #2. The resulting box is then centered
275 %% vertically along the x-height of the current font.
277 %% Parameters #1 and #2 are scaled by \outputscale.
280 \lytempdim #2\outputscale
281 \lytempdim -0.5\lytempdim
282 \advance\lytempdim 1ex
284 \raise \lytempdim \hbox to #1\outputscale {
285 %% Convert depth of #3 into height only.
286 \vbox to #2\outputscale {\hbox{#3}\vss}
289 %% Produce a black bar (width #2, depth #3, height #4) with a vertical
290 %% offset #1. Everything is scaled by \outputscale.
292 \gdef\lyvrule#1#2#3#4{
294 \vrule width #2\outputscale depth #3\outputscale height #4\outputscale}
296 %% FIXME: 'interscoreline' and 'lilypondPAPERinterscoreline
298 \lilypondifundefined{lilypondpaperinterscorelinefill}
299 {\gdef\lilypondpaperinterscorelinefill{0}}
300 {\gdef\lilypondpaperinterscorelinefill{1}}
302 %% Allow overriding of interscoreline, e.g., for LilyPond's --preview
304 \lilypondifundefined{interscoreline}
305 {\lilypondifundefined{lilypondclassic}
306 {\gdef\interscoreline{}}
307 {\gdef\interscoreline{
308 \vskip\lilypondpaperinterscoreline\lilypondpaperunit
309 plus \lilypondpaperinterscorelinefill fill}}}
312 %% Include PostScript definitions (which are differently defined for
313 %% TeX and pdfTeX). This is loaded once only because the inputted files
314 %% define \lilypondpostscript.
316 %% (Don't remove the spaces after the arguments to \input!)
319 %% In teTeX-3.0, latex is actually pdfetex, and we need
320 %% ifpdf.sty to determinine if we are really *tex or pdf*tex.
324 %% However, ifpfd.sty is too smart for LilyPond, so we copy the
325 %% logic here. Using \input ifpdf.sty is a no-op when using latex,
326 %% and the \ifpdf switch is needed before \documentclass, using
327 %% \usepackage{ifpdf} is not an option.
334 %! Forbidden control sequence found while scanning use of \lilypondfirst.
344 %\lilypondifundefined{lilypondpostscript}
346 % \ifx\pdfoutput\undefined
348 % \ifx\pdfoutput\relax
357 % {\input lily-pdf-defs }
359 % {\input lily-ps-defs }
363 %% Restore newline functionality (disabled to avoid \par).
365 \endlinechar \lilyponddefsELC
368 %% end lilyponddefs.tex