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