]> git.donarmstrong.com Git - lilypond.git/blob - tex/lilyponddefs.tex
* tex/lilyponddefs.tex (\lilypondstart): Define
[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 \gdef\lilypondstart{
44   \frenchspacing
45   \begingroup
46   \catcode `\@=11\relax
47   %% \@nodocument is defined as \relax after `\begin{document}'
48   \lilypondifundefined{@nodocument}
49     {%% either plain TeX or texinfo or not at the beginning of LaTeX input
50      \def\x{
51        \endgroup
52        \def\lilypondfontencoding##1{}}}
53     {%% FIXME: a4
54      %% provide a proper LaTeX preamble (for A4 paper format)
55      \def\x{
56        \endgroup
57        \def\lilyponddocument{}
58        \def\lilypondfontencoding##1{
59          \fontencoding{##1}\selectfont}
60        \documentclass[a4paper]{article}
61        %% safe-mode
62        \nofiles
63        \usepackage[\lilypondpaperinputencoding]{inputenc}
64        \pagestyle{empty}
65        \lilypondifundefined{lilypondclassic}
66          {%% Nullify [La]TeX page layout settings, page layout by LilyPond.
67           \topmargin-1in
68           \headheight0pt\headsep0pt
69           \oddsidemargin-1in
70           \evensidemargin\oddsidemargin}
71          {%% Center staves horizontally on page
72           \ifdim\lilypondpaperlinewidth\lilypondpaperunit > 0pt
73             \hsize\lilypondpaperlinewidth\lilypondpaperunit
74             \lytempdim \paperwidth
75             \advance\lytempdim -\the\hsize
76             \lytempdim 0.5\lytempdim
77             \advance\lytempdim -1in
78             \oddsidemargin \lytempdim
79             \evensidemargin \lytempdim
80           \fi}
81        \parindent 0pt
82        %% TEXINFO workaround: \begin is defined as \outer, use \csname.
83        \csname begin\endcsname{document}}}
84   \x}
85
86 \gdef\lilypondend{
87   \lilypondifundefined{lilypondbook}
88     {\lilypondifundefined{lilypondpaperlastpagefill}
89        {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
90        {}}
91     {}
92   \begingroup
93   \lilypondifundefined{lilyponddocument}
94     {\def\x{\endgroup}}
95     {\def\x{\endgroup\csname end\endcsname{document}}}
96   \x}
97
98 %% Inversed \loop ... \repeat macro
99 \def\lilypondloop#1\lilypondrepeat{
100   \def\lilypondbody{#1}
101   \lilyponditerate}
102
103 \def\lilyponditerate{
104   % \if ...
105     \lilypondbody
106     \let\lilypondnext \relax
107   \else
108     \let\lilypondnext \lilyponditerate
109   \fi
110   \lilypondnext}
111
112 %% Allow overriding of pagebreak
113 \lilypondifundefined{lilypondpagebreak}
114 {\lilypondifundefined{@nodocument}
115    {\gdef\lilypondpagebreak{\eject}}
116    {\gdef\lilypondpagebreak{\newpage}}}
117 {}
118       
119 %% Include \special only once.
120 \gdef\lilypondspecial{
121   \special{header=music-drawing-routines.ps}
122   \gdef\lilypondspecial{}}
123
124 %% The feta characters.
125 \input feta20
126
127 \global\font\fetasixteen = feta16
128 \gdef\fetafont{\fetasixteen}
129 \gdef\fetachar#1{\hbox{\fetasixteen#1}}
130
131 \gdef\topalign#1{\vbox to 0pt{\hbox{#1}\vss}}
132 \gdef\leftalign#1{\hbox to 0pt{#1\hss}}
133
134 \gdef\lyitem#1#2#3{
135   \topalign{\raise#2\outputscale\leftalign{\kern#1\outputscale#3}}}
136
137 \gdef\lybox#1#2#3#4#5{
138   \lytempdim\baselineskip
139   \advance\lytempdim-#4\outputscale
140   \raise\lytempdim
141   \vbox to#4\outputscale{
142     \leftalign{\kern#1\outputscale\lower#2\outputscale\topalign{#5}}
143     \vss}}
144
145 \gdef\lyvrule#1#2#3#4{
146   \kern#1\outputscale
147   \vrule width #2\outputscale depth #3\outputscale height #4\outputscale}
148
149 %% FIXME: 'interscoreline' and 'lilypondPAPERinterscoreline
150 \lilypondifundefined{lilypondpaperinterscorelinefill}
151   {\gdef\lilypondpaperinterscorelinefill{0}}
152   {\gdef\lilypondpaperinterscorelinefill{1}}
153
154 %% Allow overriding of interscoreline, e.g. for lilypond.py's --preview
155 \lilypondifundefined{interscoreline}
156 {\lilypondifundefined{lilypondclassic}
157    {\gdef\interscoreline{}}
158    {\gdef\interscoreline{
159       \vskip\lilypondpaperinterscoreline\lilypondpaperunit
160       plus \lilypondpaperinterscorelinefill fill}}}
161 {}
162
163 %% Include postscript definitions unless using PDFTeX,
164 %% in that case use pdf definitions.
165 %% MiKTeX workaround: use \csname.
166 \lilypondifundefined{lilypondpostscript}
167 {\lilypondifundefined{pdfoutput}
168    {\input lily-ps-defs }
169    {\pdfoutput = 1
170     \input lily-pdf-defs }}
171 {}
172
173 %% Restore newline functionality (disabled to avoid \par).
174 \endlinechar \lilyponddefsELC
175 \endinput
176
177 %% end lilyponddefs.tex