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