]> git.donarmstrong.com Git - lilypond.git/blob - tex/lilyponddefs.tex
use new syntax.
[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         \pagestyle{empty}
59         % \begin is defined as \outer in texinfo, thus we use \csname
60         \csname begin\endcsname{document}
61         % center staves horizontally on page
62         \ifdim\lilypondpaperlinewidth\lilypondpaperunit > 0pt
63           \hsize\lilypondpaperlinewidth\lilypondpaperunit
64           % we abuse \scoreshift temporarily
65           \scoreshift \paperwidth
66           \advance\scoreshift -\the\hsize
67           \scoreshift 0.5\scoreshift
68           \advance\scoreshift -1in
69           \oddsidemargin \scoreshift
70           \evensidemargin \scoreshift
71         \fi
72         \parindent 0pt
73       }
74     }
75
76   \x
77
78   \lilypondifundefined{mustmakelilypondtitle}
79     {}
80     {\makelilypondtitle}
81
82   \lilypondifundefined{mustmakelilypondpiecetitle}
83     {}
84     {\makelilypondpiecetitle}
85 }
86
87 \gdef\lilypondend{
88   \lilypondifundefined{lilypondbook}
89     {\lilypondifundefined{lilypondpaperlastpagefill}
90       {\vskip 0pt plus \lilypondpaperinterscorelinefill00 fill}
91       {}
92     }
93     {}
94
95   \begingroup
96   \lilypondifundefined{lilyponddocument}
97     {
98       \def\x{\endgroup}
99     }
100     {
101       \def\x{
102         \endgroup
103         \csname end\endcsname{document}
104       }
105     }
106
107   \x
108 }
109
110 % this is an inversed \loop ... \repeat macro
111 \def\lilypondloop#1\lilypondrepeat{
112   \def\lilypondbody{#1}
113   \lilyponditerate
114 }
115
116 \def\lilyponditerate{
117   % \if ...
118     \lilypondbody
119     \let\lilypondnext \relax
120   \else
121     \let\lilypondnext \lilyponditerate
122   \fi
123   \lilypondnext
124 }
125
126 % the following macro is executed only once
127 \gdef\lilypondspecial{
128   \special{header=music-drawing-routines.ps}
129   \gdef\lilypondspecial{}
130 }
131
132 % the feta characters
133 \input feta20
134
135 \global\font\fetasixteen = feta16
136 \gdef\fetafont{\fetasixteen}
137 \gdef\fetachar#1{\hbox{\fetasixteen#1}}
138
139 \gdef\botalign#1{
140   \vbox to 0pt{\vss #1}
141 }
142 \gdef\leftalign#1{
143   \hbox to 0pt{#1\hss}
144 }
145
146 \gdef\lyitem#1#2#3{
147   \botalign{
148     \hbox{\raise #1\outputscale
149           \leftalign{\kern #2\outputscale #3}}
150   }
151 }
152
153 \gdef\lybox#1#2#3{
154   \hbox to #1\outputscale {
155     \lower\scoreshift \vbox to #2\outputscale {
156       \hbox{#3}
157       \vss
158     }
159     \hss
160   }
161 }
162
163 \gdef\lyvrule#1#2#3#4{
164   \kern #1\outputscale
165   \vrule width #2\outputscale depth #3\outputscale height #4\outputscale
166 }
167
168 % Attempt to keep lilypiecetitle together with the piece:
169 %
170 % TODO: figure this out.
171 \gdef\myfilbreak{}%\par\vfil\penalty200\vfilneg}
172
173 \lilypondifundefined{lilypondpaperinterscorelinefill}
174   {\gdef\lilypondpaperinterscorelinefill{0}}
175   {\gdef\lilypondpaperinterscorelinefill{1}}
176
177 \gdef\interscoreline{
178   \vskip \lilypondpaperinterscoreline \lilypondpaperunit
179     plus \lilypondpaperinterscorelinefill fill
180 }
181
182 % Are we using PDFTeX?  If so, use pdf definitions.
183 % MiKTeX checks \pdfoutput the wrong way, thus we use \csname.
184 \lilypondifundefined{lilypondpostscript}
185   {
186     \lilypondifundefined{pdfoutput}
187       {\input lily-ps-defs }
188       {
189         \pdfoutput = 1
190         \input lily-pdf-defs %
191       }
192   }
193   {}
194
195 \newdimen\outputscale
196 \newdimen\scoreshift
197
198 % Restore newline functionality (disabled to avoid \par).
199 \endlinechar \lilyponddefsELC
200 \endinput
201
202 % EOF