Allow for nested properties in list form when using \override.
[lilypond.git] / tex / lilyponddefs.tex
blob467f5639951c6118cbba7060c057a05af1f12b25
1 %%% lilyponddefs.tex -- TeX macros for LilyPond output.
2 %%%
3 %%% source file of the GNU LilyPond music typesetter
4 %%%
5 %%% (c) 1998--2007 Jan Nieuwenhuizen <janneke@gnu.org>
6 %%% Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 %%% Mats Bengtsson <mats.bengtsson@s3.kth.se>
8 %%%
9 %%
10 %% Avoid \par while reading this file.
12 \edef\lilyponddefsELC{\the\endlinechar}%
13 \endlinechar -1\relax
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>
23 %% <font setup>
24 %% \ifx\lilypondstart \undefined
25 %% \input lilyponddefs
26 %% \fi
27 %% \lilypondstart
28 %% <note output>
29 %% \lilypondend
31 %% A temporary variable.
33 \newdimen\lytempdim
35 %% The scaling factor for all dimensions.
37 \newdimen\outputscale
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
51 \else
52 \expandafter\lilypondsecond
53 \fi
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
60 %% EC glyphs.
62 %% All definitions are taken from texinfo or LaTeX (with modifications
63 %% if necessary).
65 \begingroup
66 \catcode `\@=11\relax
67 \gdef\lilypondECencoding{
68 \def\"##1{
69 {\accent4 ##1}}
70 \def\'##1{
71 {\accent1 ##1}}
72 \def\,##1{
73 {\leavevmode
74 \setbox\z@\hbox{##1}
75 \ifdim\ht\z@=1ex
76 \accent11 ##1
77 \else
78 {\ooalign{
79 \unhbox\z@
80 \crcr
81 \hidewidth
82 \char11
83 \hidewidth}}
84 \fi}}
85 \def\=##1{
86 {\accent9 ##1}}
87 \def\^##1{
88 {\accent2 ##1}}
89 \def\`##1{
90 {\accent0 ##1}}
91 \def\~##1{
92 {\accent3 ##1}}
93 \def\dotaccent##1{
94 {\accent10 ##1}}
95 \def\H##1{
96 {\accent5 ##1}}
97 \def\ringaccent##1{
98 {\accent6 ##1}}
99 % \def\tieaccent##1{} % unsupported: this is TS1
100 \def\u##1{
101 {\accent8 ##1}}
102 \def\ubaraccent##1{
103 {\o@lign{
104 \relax
106 \crcr
107 \hidewidth
108 \sh@ft{29}\vbox to.2ex{
109 \hbox{\char9}
110 \vss}
111 \hidewidth}}}
112 \def\udotaccent##1{
113 {\o@lign{
114 \relax
116 \crcr
117 \hidewidth
118 \sh@ft{10}.
119 \hidewidth}}}
120 \def\v##1{
121 {\accent7 ##1}}
123 \chardef\exclamdown=189
124 \chardef\questiondown=190
126 \def\aa{
127 \ringaccent{a}}
128 \def\AA{
129 \ringaccent{A}}
130 \chardef\AE=198
131 \chardef\ae=230
132 \chardef\ptexi=25
133 \chardef\j=26
134 \chardef\L=138
135 \chardef\l=170
136 \chardef\O=216
137 \chardef\o=248
138 \chardef\OE=215
139 \chardef\oe=247
140 \chardef\ss=255
142 \endgroup
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
150 %% parameters.
152 %% \lilypondfontencoding is emitted by LilyPond to set the encoding of
153 %% text strings.
155 \gdef\lilypondstart{
156 \frenchspacing
157 \outputscale \lilypondpaperoutputscale\lilypondpaperunit
159 \begingroup
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.
165 \def\x{
166 \endgroup
168 \def\lilypondfontencoding####1{
169 \lilypondECencoding}
170 \def\lilypondpagebreak{
171 \eject}
172 \def\lilypondnopagebreak{
173 \ifvmode
174 \penalty 10000\relax
175 \fi}}}
177 {%% LaTeX mode: Provide a complete preamble.
178 \def\x{
179 \endgroup
181 %% Indicate that we shall emit `\end{document}' while executing
182 %% \lilypondend.
183 \def\lilyponddocument{}
185 \def\lilypondfontencoding####1{
186 \fontencoding{####1}
187 \selectfont}
188 \def\lilypondpagebreak{
189 \newpage}
190 \def\lilypondnopagebreak{
191 \nopagebreak}
193 \documentclass[\lilyponddocumentclassoptions]{article}
195 %% As a safety guard, don't produce auxiliary files.
196 \nofiles
198 %% FIXME: workaround non-existent TeX.def.
199 \def\TeXdef{TeX}\ifx\TeXdef\lilypondpaperinputencoding
200 \usepackage[latin1]{inputenc}
201 \else
202 \usepackage[\lilypondpaperinputencoding]{inputenc}
204 \pagestyle{empty}
206 \usepackage{color}
208 \lilypondifundefined{lilypondclassic}
209 {%% If not in `classic' mode, undo LaTeX's page layout settings
210 %% since LilyPond does the layout by itself.
211 \topmargin-1in
212 \headheight0pt\headsep0pt
213 \oddsidemargin-1in
214 \evensidemargin\oddsidemargin}
216 {%% Otherwise center output horizontally, without changing the
217 %% vertical positioning.
218 \hsize\lilypondpaperlinewidth\lilypondpaperunit
219 \lytempdim \paperwidth
220 \advance\lytempdim -\the\hsize
221 \lytempdim 0.5\lytempdim
222 \advance\lytempdim -1in
223 \oddsidemargin \lytempdim
224 \evensidemargin \lytempdim}
226 \parindent 0pt
228 %% We can't directly say `\begin{document}' in this macro since
229 %% older versions of texinfo.tex define \begin as \outer; this
230 %% means that it causes an error if \begin is found within another
231 %% macro (even if the corresponding code will never be executed).
232 %% As a workaround we use \csname to call \begin.
233 \csname begin\endcsname{document}}}
236 %% The opposite of \lilypondstart.
238 \gdef\lilypondend{
239 %% Handle the `lastpagefill' parameter from the \layout block.
240 %% Ignore it if \lilypondbook is defined.
241 \lilypondifundefined{lilypondbook}
242 {\lilypondifundefined{lilypondpaperlastpagefill}
243 {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
247 \begingroup
248 \lilypondifundefined{lilyponddocument}
249 {\def\x{
250 \endgroup}}
251 {\def\x{
252 \endgroup
253 \csname end\endcsname{document}}}
256 %% Load the PostScript drawing routines. This is done using \special.
257 %% To avoid multiple inclusions, redefine \lilypondspecial to a no-op
258 %% afterwards.
260 \gdef\lilypondspecial{
261 \special{header=music-drawing-routines.ps}
262 \gdef\lilypondspecial{}}
264 %% The most used macro in LilyPond output. Put #3 into a zero-width box
265 %% which is moved to the right by #1 (scaled by \outputscale) and moved
266 %% up by #2 (also scaled by \outputscale).
268 \gdef\lyitem#1#2#3{
269 \raise #2\outputscale \hbox to 0pt {
270 \kern #1\outputscale
272 \hss}}
274 %% All LilyPond music data is enclosed in this macro (as third argument).
275 %% The data (which consists of boxes with zero width) gets an artificial
276 %% width of #1 and a height of #2. The resulting box is then centered
277 %% vertically along the x-height of the current font.
279 %% Parameters #1 and #2 are scaled by \outputscale.
281 \gdef\lybox#1#2#3{
282 \lytempdim #2\outputscale
283 \lytempdim -0.5\lytempdim
284 \advance\lytempdim 1ex
285 \leavevmode
286 \raise \lytempdim \hbox to #1\outputscale {
287 %% Convert depth of #3 into height only.
288 \vbox to #2\outputscale {\hbox{#3}\vss}
289 \hss}}
291 %% Produce a black bar (width #2, depth #3, height #4) with a vertical
292 %% offset #1. Everything is scaled by \outputscale.
294 \gdef\lyvrule#1#2#3#4{
295 \kern#1\outputscale
296 \vrule width #2\outputscale depth #3\outputscale height #4\outputscale}
298 %% FIXME: 'interscoreline' and 'lilypondPAPERinterscoreline
300 \lilypondifundefined{lilypondpaperinterscorelinefill}
301 {\gdef\lilypondpaperinterscorelinefill{0}}
302 {\gdef\lilypondpaperinterscorelinefill{1}}
304 %% Allow overriding of interscoreline, e.g., for LilyPond's --preview
306 \lilypondifundefined{interscoreline}
307 {\lilypondifundefined{lilypondclassic}
308 {\gdef\interscoreline{}}
309 {\gdef\interscoreline{
310 \vskip\lilypondpaperinterscoreline\lilypondpaperunit
311 plus \lilypondpaperinterscorelinefill fill}}}
314 %% Include PostScript definitions (which are differently defined for
315 %% TeX and pdfTeX). This is loaded once only because the inputted files
316 %% define \lilypondpostscript.
318 %% (Don't remove the spaces after the arguments to \input!)
321 %% In teTeX-3.0, latex is actually pdfetex, and we need
322 %% ifpdf.sty to determinine if we are really *tex or pdf*tex.
324 %% \input ifpdf.sty
326 %% However, ifpfd.sty is too smart for LilyPond, so we copy the
327 %% logic here. Using \input ifpdf.sty is a no-op when using latex,
328 %% and the \ifpdf switch is needed before \documentclass, using
329 %% \usepackage{ifpdf} is not an option.
331 \input lily-ps-defs
333 % barfs with texi
334 % Runaway argument?
336 %! Forbidden control sequence found while scanning use of \lilypondfirst.
337 %<inserted text>
338 % \par
339 %<to be read again>
340 % \newif
341 %l.330 {\newif
342 % \ifpdf
346 %\lilypondifundefined{lilypondpostscript}
347 % {\newif\ifpdf
348 % \ifx\pdfoutput\undefined
349 % \else
350 % \ifx\pdfoutput\relax
351 % \else
352 % \ifcase\pdfoutput
353 % \else
354 % \pdftrue
355 % \fi
356 % \fi
357 % \fi
358 % \ifpdf
359 % {\input lily-pdf-defs }
360 % \else
361 % {\input lily-ps-defs }
362 % \fi}
363 % {}
365 %% Restore newline functionality (disabled to avoid \par).
367 \endlinechar \lilyponddefsELC
368 \endinput
370 %% end lilyponddefs.tex