]> git.donarmstrong.com Git - lilypond.git/blob - tex/lilyponddefs.tex
update
[lilypond.git] / tex / lilyponddefs.tex
1 % lilyponddefs.tex
2 %
3 % Include file for LilyPond.
4 %
5 % This file defines various macros to acommodate lilypond output.
6 %
7 % It should run with plain TeX, LaTeX, pdftex, and texinfo.
8 %
9 % To avoid interferences, lilyponddefs.tex should be loaded within a group.
10 % To load it only once, most of the definitions must be global.
11 %
12 % The overall structure of a file created by LilyPond is as follows:
13 %
14 %   <lilypond parameter definitions>
15 %   \ifx\lilypondstart \undefined
16 %     \input lilyponddefs
17 %   \fi
18 %   \lilypondstart
19 %   <font setup and note output>
20 %   \lilypondend
21 %
22 % No footers and headers are provided for the stand-alone run (i.e., for
23 % directly saying `latex <LilyPond output>'.
24 %
25 %
26 % Avoid \par while reading this file.
27 \edef\lilyponddefsELC{\the\endlinechar}%
28 \endlinechar -1\relax
29
30 % the next three macros are taken from LaTeX
31 \long\gdef\lilypondfirst#1#2{#1}
32
33 \long\gdef\lilypondsecond#1#2{#2}
34
35 \gdef\lilypondifundefined#1{
36   \expandafter\ifx\csname#1\endcsname\relax
37     \expandafter\lilypondfirst
38   \else
39     \expandafter\lilypondsecond
40   \fi
41 }
42
43 \gdef\lilypondstart{
44   \begingroup
45   \catcode `\@=11\relax
46   % \@nodocument is defined as \relax after `\begin{document}'
47   \lilypondifundefined{@nodocument}
48     {
49       % either plain TeX or texinfo or not at the beginning of LaTeX input
50       \def\x{\endgroup}
51     }
52     {
53       % provide a proper LaTeX preamble (for A4 paper format)
54       \def\x{
55         \endgroup
56         \def\lilyponddocument{}
57         \documentclass[a4paper]{article}
58         \nofiles
59         \pagestyle{empty}
60         % \begin is defined as \outer in texinfo, thus we use \csname
61         \csname begin\endcsname{document}
62         % center staves horizontally on page
63         \ifdim\lilypondpaperlinewidth\lilypondpaperunit > 0pt
64           \hsize\lilypondpaperlinewidth\lilypondpaperunit
65           % we abuse \scoreshift temporarily
66           \scoreshift \paperwidth
67           \advance\scoreshift -\the\hsize
68           \scoreshift 0.5\scoreshift
69           \advance\scoreshift -1in
70           \oddsidemargin \scoreshift
71           \evensidemargin \scoreshift
72         \fi
73         \parindent 0pt
74       }
75     }
76
77   \x
78
79   \lilypondifundefined{mustmakelilypondtitle}
80     {}
81     {\makelilypondtitle}
82
83   \lilypondifundefined{mustmakelilypondpiecetitle}
84     {}
85     {\makelilypondpiecetitle}
86 }
87
88 \gdef\lilypondend{
89   \lilypondifundefined{lilypondbook}
90     {\lilypondifundefined{lilypondpaperlastpagefill}
91       {\vskip 0pt plus \lilypondpaperinterscorelinefill00 fill}
92       {}
93     }
94     {}
95
96   \begingroup
97   \lilypondifundefined{lilyponddocument}
98     {
99       \def\x{\endgroup}
100     }
101     {
102       \def\x{
103         \endgroup
104         \csname end\endcsname{document}
105       }
106     }
107
108   \x
109 }
110
111 % this is an inversed \loop ... \repeat macro
112 \def\lilypondloop#1\lilypondrepeat{
113   \def\lilypondbody{#1}
114   \lilyponditerate
115 }
116
117 \def\lilyponditerate{
118   % \if ...
119     \lilypondbody
120     \let\lilypondnext \relax
121   \else
122     \let\lilypondnext \lilyponditerate
123   \fi
124   \lilypondnext
125 }
126
127 % the following macro is executed only once
128 \gdef\lilypondspecial{
129   \special{header=music-drawing-routines.ps}
130   \gdef\lilypondspecial{}
131 }
132
133 % the feta characters
134 \input feta20
135
136 \global\font\fetasixteen = feta16
137 \gdef\fetafont{\fetasixteen}
138 \gdef\fetachar#1{\hbox{\fetasixteen#1}}
139
140 \gdef\botalign#1{
141   \vbox to 0pt{\vss #1}
142 }
143 \gdef\leftalign#1{
144   \hbox to 0pt{#1\hss}
145 }
146
147 \gdef\lyitem#1#2#3{
148   \botalign{
149     \hbox{\raise #1\outputscale
150           \leftalign{\kern #2\outputscale #3}}
151   }
152 }
153
154 \gdef\lybox#1#2#3{
155   \hbox to #1\outputscale {
156     \lower\scoreshift \vbox to #2\outputscale {
157       \hbox{#3}
158       \vss
159     }
160     \hss
161   }
162 }
163
164 \gdef\lyvrule#1#2#3#4{
165   \kern #1\outputscale
166   \vrule width #2\outputscale depth #3\outputscale height #4\outputscale
167 }
168
169 % Attempt to keep lilypiecetitle together with the piece:
170 %
171 % TODO: figure this out.
172 \gdef\myfilbreak{}%\par\vfil\penalty200\vfilneg}
173
174 \lilypondifundefined{lilypondpaperinterscorelinefill}
175   {\gdef\lilypondpaperinterscorelinefill{0}}
176   {\gdef\lilypondpaperinterscorelinefill{1}}
177
178 %% Allow overriding of interscoreline, eg for lilypond --preview
179 \lilypondifundefined{interscoreline}
180 {\gdef\interscoreline{
181   \vskip \lilypondpaperinterscoreline \lilypondpaperunit
182     plus \lilypondpaperinterscorelinefill fill
183 }}{}
184
185 % Are we using PDFTeX?  If so, use pdf definitions.
186 % MiKTeX checks \pdfoutput the wrong way, thus we use \csname.
187 \lilypondifundefined{lilypondpostscript}
188   {
189     \lilypondifundefined{pdfoutput}
190       {\input lily-ps-defs }
191       {
192         \pdfoutput = 1
193         \input lily-pdf-defs %
194       }
195   }
196   {}
197
198 \newdimen\outputscale
199 \newdimen\scoreshift
200
201 % Restore newline functionality (disabled to avoid \par).
202 \endlinechar \lilyponddefsELC
203 \endinput
204
205 % EOF