]> git.donarmstrong.com Git - lilypond.git/blob - tex/lilyponddefs.tex
* lily/paper-book.cc (classic_output):
[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\outputscale
29
30 %% Handy macros from the LaTeX manual.
31 \long\gdef\lilypondfirst#1#2{#1}
32 \long\gdef\lilypondsecond#1#2{#2}
33 \gdef\lilypondifundefined#1{
34   \expandafter\ifx\csname#1\endcsname\relax
35     \expandafter\lilypondfirst
36   \else
37     \expandafter\lilypondsecond
38   \fi
39 }
40
41 \gdef\lilypondstart{
42   \begingroup
43   \catcode `\@=11\relax
44   %% \@nodocument is defined as \relax after `\begin{document}'
45   \lilypondifundefined{@nodocument}
46     {
47       %% either plain TeX or texinfo or not at the beginning of LaTeX input
48       \def\x{\endgroup}}
49     {
50       %% FIXME: a4
51       %% provide a proper LaTeX preamble (for A4 paper format)
52       \def\x{
53         \endgroup
54         \def\lilyponddocument{}
55         \documentclass[a4paper]{article}
56         %% safe-mode
57         \nofiles
58         %% Nullify [La]TeX page layout settings, page layout by LilyPond.
59         \pagestyle{empty}
60         \topmargin-1in
61         \headheight0pt\headsep0pt
62         \oddsidemargin-1in
63         \evensidemargin\oddsidemargin
64         \parindent 0pt
65         %% TEXINFO workaround: \begin is defined as \outer, use \csname.
66         \csname begin\endcsname{document}}}
67   \x}
68
69 \gdef\lilypondend{
70   \lilypondifundefined{lilypondbook}
71   {\lilypondifundefined{lilypondpaperlastpagefill}
72     {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
73     {}}
74   {}
75   \begingroup
76   \lilypondifundefined{lilyponddocument}
77     {\def\x{\endgroup}}
78     {\def\x{\endgroup\csname end\endcsname{document}}}
79   \x}
80
81 %% Inversed \loop ... \repeat macro
82 \def\lilypondloop#1\lilypondrepeat{
83   \def\lilypondbody{#1}
84   \lilyponditerate
85 }
86
87 \def\lilyponditerate{
88   % \if ...
89     \lilypondbody
90     \let\lilypondnext \relax
91   \else
92     \let\lilypondnext \lilyponditerate
93   \fi
94   \lilypondnext
95 }
96
97 %% Include \special only once.
98 \gdef\lilypondspecial{
99   \special{header=music-drawing-routines.ps}
100   \gdef\lilypondspecial{}
101 }
102
103 %% The feta characters.
104 \input feta20
105
106 \global\font\fetasixteen = feta16
107 \gdef\fetafont{\fetasixteen}
108 \gdef\fetachar#1{\hbox{\fetasixteen#1}}
109
110 \gdef\topalign#1{\vbox to 0pt{\hbox{#1}\vss}}
111 \gdef\leftalign#1{\hbox to 0pt{#1\hss}}
112
113 \gdef\lyitem#1#2#3{
114   \topalign{\raise#2\outputscale\leftalign{\kern#1\outputscale#3}}}
115
116 \newdimen\lytempdim
117 \gdef\lybox#1#2#3#4#5{
118   \lytempdim\baselineskip
119   \advance\lytempdim-#4\outputscale
120   \raise\lytempdim
121   \vbox to#4\outputscale{
122     \leftalign{\kern#1\outputscale\lower#2\outputscale\topalign{#5}}
123     \vss}}
124
125 \gdef\lyvrule#1#2#3#4{
126   \kern#1\outputscale
127   \vrule width #2\outputscale depth #3\outputscale height #4\outputscale}
128
129 \lilypondifundefined{lilypondpaperinterscorelinefill}
130   {\gdef\lilypondpaperinterscorelinefill{0}}
131   {\gdef\lilypondpaperinterscorelinefill{1}}
132
133 %% Allow overriding of interscoreline, e.g. for lilypond.py's --preview
134 \lilypondifundefined{interscoreline}
135 {\gdef\interscoreline{}}{}
136
137 %% Include postscript definitions unless using PDFTeX,
138 %% in that case use pdf definitions.
139 %% MiKTeX workaround: use \csname.
140 \lilypondifundefined{lilypondpostscript}
141 {\lilypondifundefined{pdfoutput}
142   {\input lily-ps-defs }
143   {\pdfoutput = 1
144     \input lily-pdf-defs }}
145 {}
146
147 %% Restore newline functionality (disabled to avoid \par).
148 \endlinechar \lilyponddefsELC
149 \endinput
150
151 %% end lilyponddefs.tex