(LY_DEFINE): ly:output-formats. New function.
[lilypond.git] / tex / lilyponddefs.tex
bloba64e8e01efb210a42106a4d9dcc8704fdaec04b8
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
13 %% This runs with plain TeX, LaTeX, pdftex, and texinfo.
15 %% To avoid interferences, lilyponddefs.tex must be loaded within a group.
16 %% It is loaded only once, so the definitions must be global.
18 %% The overall structure of a file created by LilyPond is as follows:
20 %% <lilypond parameter definitions>
21 %% \ifx\lilypondstart \undefined
22 %% \input lilyponddefs
23 %% \fi
24 %% \lilypondstart
25 %% <font setup and note output>
26 %% \lilypondend
28 \newdimen\lytempdim
29 \newdimen\outputscale
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
42 \gdef\lilypondstart{
43 \begingroup
44 \catcode `\@=11\relax
45 %% \@nodocument is defined as \relax after `\begin{document}'
46 \lilypondifundefined{@nodocument}
48 %% either plain TeX or texinfo or not at the beginning of LaTeX input
49 \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}
63 %% Nullify [La]TeX page layout settings, page layout by LilyPond.
64 \topmargin-1in
65 \headheight0pt\headsep0pt
66 \oddsidemargin-1in
67 \evensidemargin\oddsidemargin
70 %% Center staves horizontally on page
71 \ifdim\lilypondpaperlinewidth\lilypondpaperunit > 0pt
72 \hsize\lilypondpaperlinewidth\lilypondpaperunit
73 \lytempdim \paperwidth
74 \advance\lytempdim -\the\hsize
75 \lytempdim 0.5\lytempdim
76 \advance\lytempdim -1in
77 \oddsidemargin \lytempdim
78 \evensidemargin \lytempdim
79 \fi
81 \parindent 0pt
82 %% TEXINFO workaround: \begin is defined as \outer, use \csname.
83 \csname begin\endcsname{document}}}
84 \x}
86 \gdef\lilypondend{
87 \lilypondifundefined{lilypondbook}
88 {\lilypondifundefined{lilypondpaperlastpagefill}
89 {\vskip 0pt plus\lilypondpaperinterscorelinefill00 fill}
90 {}}
92 \begingroup
93 \lilypondifundefined{lilyponddocument}
94 {\def\x{\endgroup}}
95 {\def\x{\endgroup\csname end\endcsname{document}}}
96 \x}
98 %% Inversed \loop ... \repeat macro
99 \def\lilypondloop#1\lilypondrepeat{
100 \def\lilypondbody{#1}
101 \lilyponditerate
104 \def\lilyponditerate{
105 % \if ...
106 \lilypondbody
107 \let\lilypondnext \relax
108 \else
109 \let\lilypondnext \lilyponditerate
111 \lilypondnext
114 %% Allow overriding of pagebreak
115 \lilypondifundefined{lilypondpagebreak}
117 \lilypondifundefined{@nodocument}
118 {\gdef\lilypondpagebreak{\eject}}
119 {\gdef\lilypondpagebreak{\newpage}}
123 %% Include \special only once.
124 \gdef\lilypondspecial{
125 \special{header=music-drawing-routines.ps}
126 \gdef\lilypondspecial{}
129 %% The feta characters.
130 \input feta20
132 \global\font\fetasixteen = feta16
133 \gdef\fetafont{\fetasixteen}
134 \gdef\fetachar#1{\hbox{\fetasixteen#1}}
136 \gdef\topalign#1{\vbox to 0pt{\hbox{#1}\vss}}
137 \gdef\leftalign#1{\hbox to 0pt{#1\hss}}
139 \gdef\lyitem#1#2#3{
140 \topalign{\raise#2\outputscale\leftalign{\kern#1\outputscale#3}}}
142 \gdef\lybox#1#2#3#4#5{
143 \lytempdim\baselineskip
144 \advance\lytempdim-#4\outputscale
145 \raise\lytempdim
146 \vbox to#4\outputscale{
147 \leftalign{\kern#1\outputscale\lower#2\outputscale\topalign{#5}}
148 \vss}}
150 \gdef\lyvrule#1#2#3#4{
151 \kern#1\outputscale
152 \vrule width #2\outputscale depth #3\outputscale height #4\outputscale}
154 %% FIXME: 'interscoreline' and 'lilypondPAPERinterscoreline
155 \lilypondifundefined{lilypondpaperinterscorelinefill}
156 {\gdef\lilypondpaperinterscorelinefill{0}}
157 {\gdef\lilypondpaperinterscorelinefill{1}}
159 %% Allow overriding of interscoreline, e.g. for lilypond.py's --preview
160 \lilypondifundefined{interscoreline}
162 \lilypondifundefined{lilypondclassic}
163 {\gdef\interscoreline{}}
164 {\gdef\interscoreline{
165 \vskip\lilypondpaperinterscoreline\lilypondpaperunit
166 plus \lilypondpaperinterscorelinefill fill}}
170 %% Include postscript definitions unless using PDFTeX,
171 %% in that case use pdf definitions.
172 %% MiKTeX workaround: use \csname.
173 \lilypondifundefined{lilypondpostscript}
174 {\lilypondifundefined{pdfoutput}
175 {\input lily-ps-defs }
176 {\pdfoutput = 1
177 \input lily-pdf-defs }}
180 %% Restore newline functionality (disabled to avoid \par).
181 \endlinechar \lilyponddefsELC
182 \endinput
184 %% end lilyponddefs.tex