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