]> git.donarmstrong.com Git - lilypond.git/blob - tex/lilyponddefs.tex
* scm/framework-tex.scm (header-end): Don't set \outputscale.
[lilypond.git] / tex / lilyponddefs.tex
1 %%% lilyponddefs.tex -- TeX macros for LilyPond output.
2 %%%
3 %%%  source file of the GNU LilyPond music typesetter
4 %%% 
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>
8 %%%
9 %%
10 %% Avoid \par while reading this file.
11 %%
12 \edef\lilyponddefsELC{\the\endlinechar}%
13 \endlinechar -1\relax
14
15 %% This runs with plain TeX, LaTeX, pdftex, and texinfo.
16 %%
17 %% To avoid interferences, lilyponddefs.tex must be loaded within a group.
18 %% It is loaded only once, so the definitions must be global.
19 %%
20 %% The overall structure of a file created by LilyPond is as follows:
21 %%
22 %%   <lilypond parameter definitions>
23 %%   <font setup>
24 %%   \ifx\lilypondstart \undefined
25 %%     \input lilyponddefs
26 %%   \fi
27 %%   \lilypondstart
28 %%   <note output>
29 %%   \lilypondend
30
31 %% A temporary variable.
32 %%
33 \newdimen\lytempdim
34
35 %% The scaling factor for all dimensions.
36 %%
37 \newdimen\outputscale
38
39 \long\gdef\lilypondfirst#1#2{#1}
40 \long\gdef\lilypondsecond#1#2{#2}
41
42 %% \lilypondundefined{xxx}{foo}{bar}
43 %%
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.
47 %%
48 \gdef\lilypondifundefined#1{
49   \expandafter\ifx\csname#1\endcsname\relax
50     \expandafter\lilypondfirst
51   \else
52     \expandafter\lilypondsecond
53   \fi
54 }
55
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.
61 %%
62 %% All definitions are taken from texinfo or LaTeX (with modifications
63 %% if necessary).
64 %%
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
105        ##1
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
115        ##1
116        \crcr
117        \hidewidth
118        \sh@ft{10}.
119        \hidewidth}}}
120   \def\v##1{
121     {\accent7 ##1}}
122
123   \chardef\exclamdown=189
124   \chardef\questiondown=190
125
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
141 }
142 \endgroup
143
144 %% This macro provides the necessary setup to make the lilypond data
145 %% work with plain TeX, LaTeX, and texinfo.
146 %%
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.
151 %%
152 %% \lilypondfontencoding is emitted by LilyPond to set the encoding of
153 %% text strings.
154 %%
155 \gdef\lilypondstart{
156   \frenchspacing
157   \outputscale \lilypondpaperoutputscale\lilypondpaperunit
158
159   \begingroup
160   \catcode `\@=11\relax
161
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
167
168        \def\lilypondfontencoding####1{
169          \lilypondECencoding}
170        \def\lilypondpagebreak{
171          \eject}
172        \def\lilypondnopagebreak{
173          \ifvmode
174            \penalty 10000\relax
175          \fi}}}
176
177     {%% LaTeX mode: Provide a complete preamble.
178      \def\x{
179        \endgroup
180
181        %% Indicate that we shall emit `\end{document}' while executing
182        %% \lilypondend.
183        \def\lilyponddocument{}
184
185        \def\lilypondfontencoding####1{
186          \fontencoding{####1}
187          \selectfont}
188        \def\lilypondpagebreak{
189          \newpage}
190        \def\lilypondnopagebreak{
191          \nopagebreak}
192
193        \documentclass[\lilyponddocumentclassoptions]{article}
194
195        %% As a safety guard, don't produce auxiliary files.
196        \nofiles
197
198        \usepackage[\lilypondpaperinputencoding]{inputenc}
199        \pagestyle{empty}
200
201        \lilypondifundefined{lilypondclassic}
202          {%% If not in `classic' mode, undo LaTeX's page layout settings
203           %% since LilyPond does the layout by itself.
204           \topmargin-1in
205           \headheight0pt\headsep0pt
206           \oddsidemargin-1in
207           \evensidemargin\oddsidemargin}
208
209          {%% Otherwise center output horizontally, without changing the
210           %% vertical positioning.
211           \hsize\lilypondpaperlinewidth\lilypondpaperunit
212           \lytempdim \paperwidth
213           \advance\lytempdim -\the\hsize
214           \lytempdim 0.5\lytempdim
215           \advance\lytempdim -1in
216           \oddsidemargin \lytempdim
217           \evensidemargin \lytempdim}
218
219        \parindent 0pt
220
221        %% We can't directly say `\begin{document}' in this macro since
222        %% older versions of texinfo.tex define \begin as \outer; this
223        %% means that it causes an error if \begin is found within another
224        %% macro (even if the corresponding code will never be executed).
225        %% As a workaround we use \csname to call \begin.
226        \csname begin\endcsname{document}}}
227   \x}
228
229 %% The opposite of \lilypondstart.
230 %%
231 \gdef\lilypondend{
232   %% Handle the `lastpagefill' parameter from the \layout block.
233   \lilypondifundefined{lilypondpaperlastpagefill}
234     {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
235     {}
236
237   \begingroup
238   \lilypondifundefined{lilyponddocument}
239     {\def\x{
240        \endgroup}}
241     {\def\x{
242        \endgroup
243        \csname end\endcsname{document}}}
244   \x}
245
246 %% Load the PostScript drawing routines.  This is done using \special.
247 %% To avoid multiple inclusions, redefine \lilypondspecial to a no-op
248 %% afterwards.
249 %%
250 \gdef\lilypondspecial{
251   \special{header=music-drawing-routines.ps}
252   \gdef\lilypondspecial{}}
253
254 %% Put the argument into a box which has zero height and depth (the
255 %% \vss forces the latter -- TeXbook, page 80).
256 %%
257 \gdef\topalign#1{
258   \vbox to 0pt{
259     \hbox{#1}
260     \vss}}
261
262 %% Put the argument into a box which has zero width.
263 %%
264 \gdef\leftalign#1{
265   \hbox to 0pt{
266     #1
267     \hss}}
268
269 %% The most used macro in LilyPond output.  Put #3 into a zero-width box
270 %% which is moved to the right by #1 (scaled by \outputscale) and moved
271 %% up by #2 (also scaled by \outputscale).  Note that negative values for
272 %% #2 change the depth of the box defined by \leftalign, not the height.
273 %%
274 \gdef\lyitem#1#2#3{
275   \raise#2\outputscale \leftalign{
276     \kern#1\outputscale
277     #3}}
278
279 %% All LilyPond music data is enclosed in this macro (as fifth argument).
280 %% The data is first put into a box with zero height and depth which is
281 %% then moved to the right by #1 and moved down by #2.  After this, it is
282 %% put into a zero-width box, giving it a height #4 (and depth zero).
283 %% Finally, the box is raised so that its true height is exactly the
284 %% distance from one baseline to the next.
285 %%
286 %% Parameters #1 to #4 are scaled by \outputscale.
287 %%
288 \gdef\lybox#1#2#3#4#5{
289   \lytempdim\baselineskip
290   \advance\lytempdim -#4\outputscale
291   \raise\lytempdim
292   \vbox to #4\outputscale{
293     \leftalign{
294       \kern #1\outputscale
295       \lower #2\outputscale \topalign{
296         #5}}
297     \vss}}
298
299 %% Produce a black bar (width #2, depth #3, height #4) with a vertical
300 %% offset #1.  Everything is scaled by \outputscale.
301 %%
302 \gdef\lyvrule#1#2#3#4{
303   \kern#1\outputscale
304   \vrule width #2\outputscale depth #3\outputscale height #4\outputscale}
305
306 %% FIXME: 'interscoreline' and 'lilypondPAPERinterscoreline
307 %%
308 \lilypondifundefined{lilypondpaperinterscorelinefill}
309   {\gdef\lilypondpaperinterscorelinefill{0}}
310   {\gdef\lilypondpaperinterscorelinefill{1}}
311
312 %% Allow overriding of interscoreline, e.g., for LilyPond's --preview
313 %%
314 \lilypondifundefined{interscoreline}
315   {\lilypondifundefined{lilypondclassic}
316      {\gdef\interscoreline{}}
317      {\gdef\interscoreline{
318         \vskip\lilypondpaperinterscoreline\lilypondpaperunit
319         plus \lilypondpaperinterscorelinefill fill}}}
320   {}
321
322 %% Include PostScript definitions (which are differently defined for
323 %% TeX and pdfTeX).  This is loaded once only because the inputted files
324 %% define \lilypondpostscript.
325 %%
326 %% (Don't remove the spaces after the arguments to \input!)
327 %%
328 \lilypondifundefined{lilypondpostscript}
329   {\lilypondifundefined{pdfoutput}
330      {\input lily-ps-defs }
331      {\pdfoutput = 1
332       \input lily-pdf-defs }}
333   {}
334
335 %% Restore newline functionality (disabled to avoid \par).
336 %%
337 \endlinechar \lilyponddefsELC
338 \endinput
339
340 %% end lilyponddefs.tex