]> git.donarmstrong.com Git - lilypond.git/blob - tex/lilyponddefs.tex
* Merge from stable:
[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 \newread\lilypondinput
127
128 % the following macro is executed only once
129 \gdef\lilypondspecial{
130   \special{header=music-drawing-routines.ps}
131   \gdef\lilypondspecial{}
132 }
133
134 % the feta characters
135 \input feta20
136
137 \global\font\fetasixteen = feta16
138 \gdef\fetafont{\fetasixteen}
139 \gdef\fetachar#1{\hbox{\fetasixteen#1}}
140
141 \gdef\botalign#1{
142   \vbox to 0pt{\vss #1}
143 }
144 \gdef\leftalign#1{
145   \hbox to 0pt{#1\hss}
146 }
147
148 \gdef\lyitem#1#2#3{
149   \botalign{
150     \hbox{\raise #1\outputscale
151           \leftalign{\kern #2\outputscale #3}}
152   }
153 }
154
155 \gdef\lybox#1#2#3{
156   \hbox to #1\outputscale {
157     \lower\scoreshift \vbox to #2\outputscale {
158       \hbox{#3}
159       \vss
160     }
161     \hss
162   }
163 }
164
165 \gdef\lyvrule#1#2#3#4{
166   \kern #1\outputscale
167   \vrule width #2\outputscale depth #3\outputscale height #4\outputscale
168 }
169
170 % Attempt to keep lilypiecetitle together with the piece:
171 %
172 % TODO: figure this out.
173 \gdef\myfilbreak{}%\par\vfil\penalty200\vfilneg}
174
175 \lilypondifundefined{lilypondpaperinterscorelinefill}
176   {\gdef\lilypondpaperinterscorelinefill{0}}
177   {\gdef\lilypondpaperinterscorelinefill{1}}
178
179 \gdef\interscoreline{
180   \vskip \lilypondpaperinterscoreline \lilypondpaperunit
181     plus \lilypondpaperinterscorelinefill fill
182 }
183
184 % Are we using PDFTeX?  If so, use pdf definitions.
185 % MiKTeX checks \pdfoutput the wrong way, thus we use \csname.
186 \lilypondifundefined{lilypondpostscript}
187   {
188     \lilypondifundefined{pdfoutput}
189       {\input lily-ps-defs }
190       {
191         \pdfoutput = 1
192         \input lily-pdf-defs
193       }
194   }
195   {}
196
197 \newdimen\outputscale
198 \newdimen\scoreshift
199
200 % Restore newline functionality (disabled to avoid \par).
201 \endlinechar \lilyponddefsELC
202 \endinput
203
204 % EOF