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