]> git.donarmstrong.com Git - lilypond.git/blob - tex/lilyponddefs.tex
(convert-to-ps): invoke dvips with -t
[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 %% Avoid \par while reading this file.
10 \edef\lilyponddefsELC{\the\endlinechar}%
11 \endlinechar -1\relax
12
13 %% This runs with plain TeX, LaTeX, pdftex, and texinfo.
14 %%
15 %% To avoid interferences, lilyponddefs.tex must be loaded within a group.
16 %% It is loaded only once, so the definitions must be global.
17 %%
18 %% The overall structure of a file created by LilyPond is as follows:
19 %%
20 %%   <lilypond parameter definitions>
21 %%   <font setup>
22 %%   \ifx\lilypondstart \undefined
23 %%     \input lilyponddefs
24 %%   \fi
25 %%   \lilypondstart
26 %%   <note output>
27 %%   \lilypondend
28
29 \newdimen\lytempdim
30 \newdimen\outputscale
31
32 %% Handy macros from the LaTeX manual.
33 \long\gdef\lilypondfirst#1#2{#1}
34 \long\gdef\lilypondsecond#1#2{#2}
35 \gdef\lilypondifundefined#1{
36   \expandafter\ifx\csname#1\endcsname\relax
37     \expandafter\lilypondfirst
38   \else
39     \expandafter\lilypondsecond
40   \fi
41 }
42
43 %% Urgh.  Lilypond uses EC fonts, but texinfo is based on CM.  We thus
44 %% have to handle T1 font encoding by ourselves.  Note that the following
45 %% code only provides the texinfo interface, not complete access to all
46 %% EC glyphs.
47
48 \begingroup
49 \catcode `\@=11\relax
50 \gdef\lilypondECencoding{
51   \def\"##1{
52     {\accent4 ##1}}
53   \def\'##1{
54     {\accent1 ##1}}
55   \def\,##1{
56     {\leavevmode
57      \setbox\z@\hbox{##1}
58      \ifdim\ht\z@=1ex
59        \accent11 ##1
60      \else
61        {\ooalign{
62           \unhbox\z@
63           \crcr
64           \hidewidth
65           \char11
66           \hidewidth}}
67      \fi}}
68   \def\=##1{
69     {\accent9 ##1}}
70   \def\^##1{
71     {\accent2 ##1}}
72   \def\`##1{
73     {\accent0 ##1}}
74   \def\~##1{
75     {\accent3 ##1}}
76   \def\dotaccent##1{
77     {\accent10 ##1}}
78   \def\H##1{
79     {\accent5 ##1}}
80   \def\ringaccent##1{
81     {\accent6 ##1}}
82 % \def\tieaccent##1{}        % unsupported: this is TS1
83   \def\u##1{
84     {\accent8 ##1}}
85   \def\ubaraccent##1{
86     {\o@lign{
87        \relax
88        ##1
89        \crcr
90        \hidewidth
91        \sh@ft{29}\vbox to.2ex{
92          \hbox{\char9}
93          \vss}
94        \hidewidth}}}
95   \def\udotaccent##1{
96     {\o@lign{
97        \relax
98        ##1
99        \crcr
100        \hidewidth
101        \sh@ft{10}.
102        \hidewidth}}}
103   \def\v##1{
104     {\accent7 ##1}}
105
106   \chardef\exclamdown=189
107   \chardef\questiondown=190
108
109   \def\aa{
110     \ringaccent{a}}
111   \def\AA{
112     \ringaccent{A}}
113   \chardef\AE=198
114   \chardef\ae=230
115   \chardef\ptexi=25
116   \chardef\j=26
117   \chardef\L=138
118   \chardef\l=170
119   \chardef\O=216
120   \chardef\o=248
121   \chardef\OE=215
122   \chardef\oe=247
123   \chardef\ss=255
124 }
125 \endgroup
126
127 \gdef\lilypondstart{
128   \frenchspacing
129   \begingroup
130   \catcode `\@=11\relax
131   %% \@nodocument is defined as \relax after `\begin{document}'
132   \lilypondifundefined{@nodocument}
133     {%% either plain TeX or texinfo or not at the beginning of LaTeX input
134      \def\x{
135        \endgroup
136        \def\lilypondfontencoding####1{
137          \lilypondECencoding}}}
138     {%% FIXME: a4
139      %% provide a proper LaTeX preamble (for A4 paper format)
140      \def\x{
141        \endgroup
142        \def\lilyponddocument{}
143        \def\lilypondfontencoding####1{
144          \fontencoding{####1}
145          \selectfont}
146        \documentclass[\lilyponddocumentclassoptions]{article}
147        %% safe-mode
148        \nofiles
149        \usepackage[\lilypondpaperinputencoding]{inputenc}
150        \pagestyle{empty}
151        \lilypondifundefined{lilypondclassic}
152          {%% Nullify [La]TeX page layout settings, page layout by LilyPond.
153           \topmargin-1in
154           \headheight0pt\headsep0pt
155           \oddsidemargin-1in
156           \evensidemargin\oddsidemargin}
157          {%% Center staves horizontally on page
158           \ifdim\lilypondpaperlinewidth\lilypondpaperunit > 0pt
159             \hsize\lilypondpaperlinewidth\lilypondpaperunit
160             \lytempdim \paperwidth
161             \advance\lytempdim -\the\hsize
162             \lytempdim 0.5\lytempdim
163             \advance\lytempdim -1in
164             \oddsidemargin \lytempdim
165             \evensidemargin \lytempdim
166           \fi}
167        \parindent 0pt
168        %% TEXINFO workaround: \begin is defined as \outer, use \csname.
169        \csname begin\endcsname{document}}}
170   \x}
171
172 \gdef\lilypondend{
173   \lilypondifundefined{lilypondbook}
174     {\lilypondifundefined{lilypondpaperlastpagefill}
175        {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
176        {}}
177     {}
178   \begingroup
179   \lilypondifundefined{lilyponddocument}
180     {\def\x{\endgroup}}
181     {\def\x{\endgroup\csname end\endcsname{document}}}
182   \x}
183
184 %% Allow overriding of pagebreak
185 \lilypondifundefined{lilypondpagebreak}
186   {\lilypondifundefined{@nodocument}
187      {\gdef\lilypondpagebreak{\eject}}
188      {\gdef\lilypondpagebreak{\newpage}}}
189   {}
190       
191 %% Allow overriding of pagebreak
192 \lilypondifundefined{lilypondnopagebreak}
193 {\lilypondifundefined{@nodocument}
194    {\gdef\lilypondnopagebreak{}}
195    {\gdef\lilypondnopagebreak{\nopagebreak}}}
196 {}
197 %% Include \special only once.
198 \gdef\lilypondspecial{
199   \special{header=music-drawing-routines.ps}
200   \gdef\lilypondspecial{}}
201
202 %% The feta characters.
203 \input feta20
204
205 \global\font\fetasixteen = feta16
206 \gdef\fetafont{\fetasixteen}
207 \gdef\fetachar#1{\hbox{\fetasixteen#1}}
208
209 \gdef\topalign#1{\vbox to 0pt{\hbox{#1}\vss}}
210 \gdef\leftalign#1{\hbox to 0pt{#1\hss}}
211
212 \gdef\lyitem#1#2#3{
213   \topalign{\raise#2\outputscale\leftalign{\kern#1\outputscale#3}}}
214
215 \gdef\lybox#1#2#3#4#5{
216   \lytempdim\baselineskip
217   \advance\lytempdim-#4\outputscale
218   \raise\lytempdim
219   \vbox to#4\outputscale{
220     \leftalign{\kern#1\outputscale\lower#2\outputscale\topalign{#5}}
221     \vss}}
222
223 \gdef\lyvrule#1#2#3#4{
224   \kern#1\outputscale
225   \vrule width #2\outputscale depth #3\outputscale height #4\outputscale}
226
227 %% FIXME: 'interscoreline' and 'lilypondPAPERinterscoreline
228 \lilypondifundefined{lilypondpaperinterscorelinefill}
229   {\gdef\lilypondpaperinterscorelinefill{0}}
230   {\gdef\lilypondpaperinterscorelinefill{1}}
231
232 %% Allow overriding of interscoreline, e.g. for lilypond.py's --preview
233 \lilypondifundefined{interscoreline}
234   {\lilypondifundefined{lilypondclassic}
235      {\gdef\interscoreline{}}
236      {\gdef\interscoreline{
237         \vskip\lilypondpaperinterscoreline\lilypondpaperunit
238         plus \lilypondpaperinterscorelinefill fill}}}
239   {}
240
241 %% Include postscript definitions unless using PDFTeX,
242 %% in that case use pdf definitions.
243 %% MiKTeX workaround: use \csname.
244 \lilypondifundefined{lilypondpostscript}
245   {\lilypondifundefined{pdfoutput}
246      {\input lily-ps-defs }
247      {\pdfoutput = 1
248       \input lily-pdf-defs }}
249   {}
250
251 %% Restore newline functionality (disabled to avoid \par).
252 \endlinechar \lilyponddefsELC
253 \endinput
254
255 %% end lilyponddefs.tex