]> mj.ucw.cz Git - saga.git/blob - macros.tex
More Fibonacci.
[saga.git] / macros.tex
1 % TeX macros for typesetting my PhD thesis
2 % (c) 2008 Martin Mares <mj@ucw.cz>
3
4 \input epsf.tex
5 \input btxmac.tex
6
7 \catcode`@=11
8
9 %%% Basic parameters %%%
10
11 % A4 with 1in margins, leaving 20pt for page numbering at the bottom
12 \hsize=159mm
13 \vsize=246mm
14 \advance\vsize by -20pt
15 \parindent=0.8cm
16 \parskip=3pt plus 1pt minus 1pt
17
18 \smallskipamount=4pt plus 1.2pt minus 1.2pt
19 \medskipamount=7pt plus 2.5pt minus 2pt
20 \bigskipamount=15pt plus 5pt minus 4pt
21
22 \abovedisplayskip=15pt plus 4pt minus 10pt
23 \abovedisplayshortskip=0pt plus 3pt
24 \belowdisplayskip=15pt plus 4pt minus 10pt
25 \belowdisplayshortskip=8.5pt plus 3.5pt minus 4.5pt
26
27 %%% Miscellanea %%%
28
29 \def\em#1{{\it #1\/}}
30 \def\df#1{{\it #1\/}}   % when we define something
31 \def\O{{\cal O}}
32 \def\<#1>{\leavevmode\hbox{\it #1\/}}
33 \let\>=\noindent
34 \def\qed{{\parfillskip=0pt\allowbreak\hfill\nobreak $\spadesuit$\par}}
35 \def\FIXME#1{\>{\bo TODO:} #1}
36 \def\symdiff{\mathbin{\Delta}}
37 \def\hphantas#1#2{\setbox0=\hbox{#2}\hbox to \wd0{#1\hss}}
38 \def\o#1{\accent23 #1}
39 \def\mst{\mathop{\rm mst}}
40 \def\deg{\mathop{\rm deg}}
41 \def\timesalpha{\mskip2mu\alpha}
42
43 % Footnotes
44 \newcount\footcnt
45 \footcnt=0
46 \def\foot#1{\global\advance\footcnt by 1{\parindent=0.25in\parskip=0pt\footnote{$^{\bf\the\footcnt}$}{#1}}}
47
48 %%% Fonts %%%
49
50 \font\twelverm=cmr12
51 \font\twelveit=cmti12
52 \font\twelvebf=cmbx12
53
54 %\font\twelverm=pplr8z at 12pt
55 %\font\twelveit=pplri8z at 12pt
56 %\font\twelvebf=pplb8z at 12pt
57
58 \font\twelvesl=cmsl12
59 \font\twelveb=cmb12
60 \font\twelvesc=cmcsc12
61
62 \def\mathf@nt#1#2#3#4{%
63 \toks0=\expandafter{\csname#1#2\endcsname}%
64 \expandafter\ifx\the\toks0\relax%
65 %\immediate\write-1{bb \the\toks0=#4#2#3}%
66 \global\expandafter\font\the\toks0=#4#2#3%
67 \fi%
68 \edef\m@@f{\the\toks0}}
69
70 \def\fntmathsize{12}
71 \def\fntmathtok{twelve}
72 \def\fntmathssize{8}
73 \def\fntmathstok{eight}
74 \def\fntmathsssize{6}
75 \def\fntmathsstok{six}
76
77 \mathf@nt{\fntmathtok}{r}{\fntmathsize}{cm}\textfont0=\m@@f
78 \mathf@nt{\fntmathstok}{r}{\fntmathssize}{cm}\scriptfont0=\m@@f
79 \mathf@nt{\fntmathsstok}{r}{\fntmathsssize}{cm}\scriptscriptfont0=\m@@f
80 \mathf@nt{\fntmathtok}{mi}{\fntmathsize}{cm}\skewchar\m@@f='177\textfont1=\m@@f
81 \mathf@nt{\fntmathstok}{mi}{\fntmathssize}{cm}\skewchar\m@@f='177\scriptfont1=\m@@f
82 \mathf@nt{\fntmathsstok}{mi}{\fntmathsssize}{cm}\skewchar\m@@f='177\scriptscriptfont1=\m@@f
83 \mathf@nt{\fntmathtok}{sy}{\fntmathsize}{cm}\skewchar\m@@f='60\textfont2=\m@@f
84 \mathf@nt{\fntmathstok}{sy}{\fntmathssize}{cm}\skewchar\m@@f='60\scriptfont2=\m@@f
85 \mathf@nt{\fntmathsstok}{sy}{\fntmathsssize}{cm}\skewchar\m@@f='60\scriptscriptfont2=\m@@f
86 \mathf@nt{\fntmathtok}{ex}{\fntmathsize}{cm}\textfont3=\m@@f\scriptfont3=\m@@f\scriptscriptfont3=\m@@f
87 \mathf@nt{\fntmathtok}{ti}{\fntmathsize}{cm}\textfont\itfam=\m@@f
88 \mathf@nt{\fntmathtok}{sl}{\fntmathsize}{cm}\textfont\slfam=\m@@f
89 \mathf@nt{\fntmathtok}{bx}{\fntmathsize}{cm}\textfont\bffam=\m@@f
90 \mathf@nt{\fntmathtok}{tt}{\fntmathsize}{cm}\hyphenchar\m@@f=-1\textfont\ttfam=\m@@f
91
92 % Blackboard bold font
93 \newfam\bbfam
94 \font\bbtwelve=bbm12
95 \font\bbeight=bbm8
96 \font\bbsix=bbm6
97 \textfont\bbfam=\bbtwelve
98 \scriptfont\bbfam=\bbeight
99 \scriptscriptfont\bbfam=\bbsix
100 \def\bb{\bbtwelve\fam\bbfam}
101
102 % Font switches
103 \def\rm{\fam\z@\twelverm}
104 \def\it{\fam\itfam\twelveit}
105 \def\bo{\fam\bffam\twelveb}
106 \def\bf{\fam\bffam\twelvebf}
107 \def\tt{\fam\ttfam\twelvett\hyphenchar\twelvett=-1\relax}
108 \def\sc{\twelvesc}
109 \def\sl{\fam\slfam\twelvesl}
110
111 % Switch to 12pt baselines
112 \rm
113 \baselineskip=14.4pt
114 \lineskip=1.2pt
115 \setbox\strutbox=\hbox{\vrule height 10.2pt depth 4.2pt width 0pt}
116
117 % Other fonts
118 \font\chapfont=csssdc17 scaled \magstep1
119 \font\secfont=csb14
120
121 %%% FIXME
122 \footline={\hss\twelverm\folio\hss}
123
124 %%% Enumerated lists %%%
125
126 \newif\ifitem\itemtrue
127 \newbox\itembox
128 \newcount\itemcount
129
130 \def\interlistskip{\vskip 3pt plus 2pt minus 1pt}
131
132 \def\itemspacingrules{\ifitem\advance\leftskip by \parindent\parindent=0pt\itemfalse\else
133 \advance\leftskip by 2.5em\fi\rightskip=\leftskip}
134
135 \def\inititemize{\interlistskip\begingroup
136 \parskip=1pt plus 0.3pt minus 0.1pt
137 \itemspacingrules}
138
139 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip 0.4em}%
140 \let\:=\singleitem}
141
142 \def\singleitem{\par\leavevmode\copy\itembox}
143
144 \def\endlist{\interlistskip\endgroup}
145
146 \def\ibull{\raise0.2ex\hbox{$\bullet$}} % Signs frequently used for \itemize
147 \def\idot{\raise0.2ex\hbox{$\cdot$}}
148 \def\istar{\raise0.2ex\hbox{$\ast$}}
149
150 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
151 \let\itemnumbering=#1}
152
153 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
154 \llap{\itemnumbering\hskip 0.4em}}
155
156 \def\nnorm{\the\itemcount}
157 \def\ndotted{\nnorm.}
158 \def\nparen{\nnorm)}
159 \def\nroman{\romannumeral\itemcount}
160 \def\nromanp{\nroman)}
161 \def\nalpha{\count@=96\advance\count@ by\itemcount\char\count@)}
162 \def\nAlpha{\count@=64\advance\count@ by\itemcount\char\count@)}
163 \def\ngreek{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
164 \zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
165 \or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$)}
166
167 % New \frenchspacing, which doesn't leave unwanted spaces in text.
168 \def\frenchsp@cing{\sfcode`\.\@m \sfcode`\?\@m \sfcode`\!\@m%
169 \sfcode`\:\@m \sfcode`\;\@m \sfcode`\,\@m}
170
171 %%% Local verbatim mode %%%
172
173 \def\make@ther#1{\catcode`#1=12\relax}
174 \def\setverb@tim{\tt\frenchsp@cing\catcode`\`=13\catcode`\'=13\n@ligs%
175 \let\do=\make@ther\dospecials\obeyspaces}
176
177 {\catcode`'=13
178 \catcode``=13
179 \gdef\n@ligs{\def`{\relax\lq}\def'{\relax\rq}}}
180
181 {\obeyspaces
182 \global\chardef\sp@ce=32
183 \gdef\showspaces{\let =\sp@ce}
184 \global\let =\ }
185
186 \catcode124=\active % Make | active
187 \def\ttst@rt{\begingroup\setverb@tim\let|=\endgroup}
188 \let|=\ttst@rt
189
190 %%% Verbatim mode for text in { } %%%
191
192 \newskip\verbglue\newskip\verblineglue
193 \verbglue=3pt plus 1pt minus 0.3pt
194 \verblineglue=0pt plus 1.5pt
195 \def\verblocaldefs{}
196
197 \newdimen\tabwidth
198 \newcount\tabsize
199 \tabsize=8
200 \newdimen\t@b
201
202 \newcount\vercnt
203 \def\v@rbend{\par\endgroup\vskip\verbglue}
204 \def\v@rbl{\ifnum\vercnt>0\{\fi\global\advance\vercnt by 1\relax}
205 \def\v@rbr{\ifnum\vercnt>1\}\else\v@rbend\fi\global\advance\vercnt by -1\relax}
206 \def\v@rbparams{\setverb@tim\parskip=\verblineglue\parindent=0pt\raggedbottom%
207 \rightskip\z@ plus1fil\pretolerance=10000\tolerance=10000\vercnt=0%
208 \catcode124=12\setupt@bs\vskip\verbglue\defb@x\obeylines}
209
210 \def\startb@x{\setbox0=\hbox\bgroup}
211 \def\defb@x{\def\par{\leavevmode\egroup\box0\endgraf}%
212 \everypar{\startb@x}}
213
214 {\catcode`\^^I=\active
215 \gdef\setupt@bs{\catcode`\^^I=\active
216 \setbox0=\hbox{\tt\ }\tabwidth=\wd0\multiply\tabwidth by \tabsize
217 \def^^I{\leavevmode\egroup\t@b=\wd0\divide\t@b by \tabwidth%
218 \multiply\t@b by \tabwidth%
219 \advance\t@b by \tabwidth\advance\t@b by -\wd0\box0\hbox to \t@b{}\startb@x}
220 }}
221
222 {
223 \catcode`[=1\catcode`]=2\catcode123=\active\catcode125=\active
224 \gdef\verbatim[\begingroup\v@rbparams\catcode123=\active\catcode125=\active%
225 \let{=\v@rbl\let}=\v@rbr\chardef\{=123\chardef\}=125\verblocaldefs
226 ]]
227
228 \def\verbinput#1{\begingroup\v@rbparams\input #1\endgroup}
229
230 %%% Algorithms %%%
231
232 %       \algo{jmeno algoritmu}
233 %       \algin popis vstupu
234 %       \:krok
235 %       \:krok
236 %       \::vnoreny krok
237 %       \algout popis vystupu
238 %       \endalgo
239
240 \def\algo{
241 \interlistskip
242 \begingroup
243 \let\:=\algoitem
244 \parskip=1pt plus 1pt minus 0.3pt
245 \rightskip=2em
246 \itemcount=0
247 \smallskip
248 }
249 \def\endalgo{\interlistskip\endgroup}
250 \def\algopar{\par
251 \parindent=2em
252 \hangindent=4em
253 \hangafter=1
254 \leavevmode
255 }
256 \def\algoitem{
257 \algopar\advance\itemcount by 1
258 \hbox to 2em{\hss \the\itemcount. }%
259 \futurelet\next\algoitemh}
260 \def\algoitemh{\ifx\next:\let\next=\algohang\else\let\next=\relax\fi\next}
261 \def\algohang:{\advance\hangindent by 2em \hskip 2em\futurelet\next\algoitemh}
262 \def\algin{\par{\sl Input:\/} }
263 \def\algout{\par{\sl Output:\/} }
264
265 %%% Constructs used in algorithms %%%
266
267 \def\={\leftarrow}
268 \def\cmt#1{~~{\sl (#1)}}
269
270 %%% Chapters, sections and proclamations %%%
271
272 \newcount\chapcount
273 \newcount\seccount
274 \newcount\thmcount
275 \chapcount=0
276 \seccount=0
277 \thmcount=0
278 \def\currentid{??}
279
280 \def\chapter#1{\vfill\supereject
281 \advance\chapcount by 1
282 \seccount=0
283 \thmcount=0
284 \edef\currentid{\the\chapcount}
285 \leftline{\chapfont\currentid. #1}
286 \bigskip
287 }
288
289 \def\section#1{\bigskip
290 \advance\seccount by 1
291 \thmcount=0
292 \edef\currentid{\the\chapcount.\the\seccount}
293 \leftline{\secfont\currentid. #1}
294 \medskip
295 }
296
297 \def\para{\advance\thmcount by 1
298 \edef\currentid{\the\chapcount.\the\seccount.\the\thmcount}
299 \noindent {\bo \currentid.\enspace}}
300
301 \def\proclaim#1{\para {\bo #1.\enspace}}
302
303 \def\thm{\proclaim{Theorem}}
304 \def\lemma{\proclaim{Lemma}}
305 \def\defn{\proclaim{Definition}}
306 \def\problem{\proclaim{Problem}}
307 \def\obs{\proclaim{Observation}}
308 \def\rem{\proclaim{Remark}}
309 \def\alg{\proclaim{Algorithm}}
310 \def\impl{\proclaim{Implementation}}
311 \def\cor{\proclaim{Corollary}}
312 \def\nota{\proclaim{Notation}}
313 \def\example{\proclaim{Example}}
314
315 \def\label#1{{\sl (#1)\/}\enspace}
316
317 \def\thmn{\thm\label}
318 \def\lemman{\lemma\label}
319 \def\defnn{\defn\label}
320 \def\algn{\alg\label}
321
322 \def\proof{\noindent {\sl Proof.}\enspace}
323
324 %%% References %%%
325
326 \newwrite\ids
327 \def\writeid#1#2{\immediate\write\ids{\string\def\expandafter\string\csname id#1\endcsname{#2}}}
328
329 \immediate\openin\ids=\jobname.ids
330 \ifeof\ids
331 \else
332 \input \jobname.ids
333 \fi
334 \immediate\closein\ids
335 \immediate\openout\ids=\jobname.ids
336
337 \def\ref#1{\expandafter\ifx\csname id#1\endcsname\relax
338 {\bo ??}%
339 \immediate\write16{*** Warning: Reference #1 undefined ***}%
340 \else
341 \csname id#1\endcsname
342 \fi
343 }
344
345 \def\id#1{\writeid{#1}{\currentid}}
346
347 %%% Bibliography %%%
348
349 %\bibliographystyle{abbrv}
350 \bibliographystyle{alpha}
351 \def\dumpbib{
352   \def\bblhook{\parskip=2pt plus 1pt minus 0.5pt}
353   \bibliography{biblio}
354 }
355
356 %%% Figures %%%
357
358 \def\figure#1#2#3{\midinsert
359 \medskip
360 \centerline{\epsfxsize=#2\epsfbox{pic/#1}}
361 \medskip
362 \smallskip
363 \centerline{#3}
364 \endinsert}
365
366 %%% Stand-alone chapters %%%
367
368 \def\endpart{
369   \section{Bibliography}
370   \dumpbib
371   \vfill\supereject\end
372 }
373
374 %%% The End %%%
375
376 \catcode`@=12