]> mj.ucw.cz Git - saga.git/blob - macros.tex
pubs: Convert to UTF-8
[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 % Parameters for final typesetting (bigger inner margins etc.)
20 \newif\iffinal
21 \finaltrue
22 \newdimen\hwobble
23 \hwobble=10mm
24 \advance\hsize by -10mm
25
26 %%% Miscellanea %%%
27
28 \def\em#1{{\it #1\/}}
29 \def\df#1{{\it #1\/}}   % when we define something
30 \def\O{{\cal O}}
31 \let\>=\noindent
32 \def\qed{{\parfillskip=0pt\allowbreak\hfill\nobreak $\spadesuit$\par}}
33 \def\qeditem{{\parfillskip=0pt\hfill\rlap{\hskip\rightskip\llap{$\spadesuit$}}\par}}
34 \def\qedmath{\eqno{\spadesuit}}
35 \def\FIXME#1{\>{\bo TODO:} #1}
36 \def\symdiff{\mathbin{\Delta}}
37 \def\rack#1#2{\setbox0=\hbox{#1}\hbox to \wd0{#2}}
38 \def\o#1{\accent23 #1}
39 \def\mst{\mathop{\rm mst}}
40 \def\msf{\mathop{\rm msf}}
41 \def\deg{\mathop{\rm deg}}
42 \def\timesalpha{\mskip2mu\alpha}
43 \def\timesbeta{\mskip2mu\beta}
44 \def\tower{\mathbin\uparrow}
45 \def\Forb{{\rm Forb}}
46 \def\minorof{\preccurlyeq}
47 \def\per{\mathop{\rm per}}
48 \def\poly{\mathop{\rm poly}}
49 \def\E{{\bb E}}
50 \def\crpt{\mathbin{\Uparrow}}
51 \def\C{{\cal C}}
52 \def\sgc{\mathbin{.}}
53
54 \def\brk{\hfil\break}
55
56 % Bit strings
57 \def\0{{\bf 0}}
58 \def\1{{\bf 1}}
59 \def\(#1){\mathord{\left<#1\right>}}
60
61 % Bitwise operations
62 \def\shl{\mathbin{<\!<}}
63 \def\shr{\mathbin{>\!>}}
64 \def\bop#1{\mathbin{\hbox{\sc #1}}}
65 \def\band{\bop{and}}
66 \def\bor{\bop{or}}
67 \def\bxor{\bop{xor}}
68 \def\bnot{\mathop{\hbox{\sc not}}}
69
70 % A reversed version of \ddots with extra space at the top to get good alignment of exponents.
71 \def\rddots{\mathinner{\mkern1mu\raise\p@\vbox{\kern7\p@\hbox{.}}\mkern2mu
72     \raise4\p@\hbox{.}\mkern2mu\raise7\p@\hbox{.}\raise11\p@\hbox{}\mkern1mu}}
73
74 % Footnotes
75 \newcount\footcnt
76 \footcnt=0
77 \def\foot#1{\global\advance\footcnt by 1{\parindent=0.25in\parskip=0pt\footnote{$^{\bf\the\footcnt}$}{#1}}}
78
79 %%% Font definition macros (used in fonts<size>.tex) %%%
80
81 \def\mathf@nt#1#2#3#4{%
82 \toks0=\expandafter{\csname#1#2\endcsname}%
83 \expandafter\ifx\the\toks0\relax%
84 %\immediate\write-1{bb \the\toks0=#4#2#3}%
85 \global\expandafter\font\the\toks0=#4#2#3%
86 \fi%
87 \edef\m@@f{\the\toks0}}
88
89 %%% Enumerated lists %%%
90
91 \newif\ifitem\itemtrue
92 \newbox\itembox
93 \newcount\itemcount
94
95 \def\interlistskip{\vskip 3pt plus 2pt minus 1pt}
96
97 \def\itemspacingrules{\ifitem\advance\leftskip by \parindent\parindent=0pt\itemfalse\else
98 \advance\leftskip by 2.5em\fi\rightskip=\leftskip}
99
100 \def\inititemize{\interlistskip\begingroup
101 \parskip=1pt plus 0.3pt minus 0.1pt
102 \itemspacingrules}
103
104 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip 0.4em}%
105 \let\:=\singleitem}
106
107 \def\singleitem{\par\leavevmode\copy\itembox}
108
109 \def\endlist{\interlistskip\endgroup}
110
111 \def\ibull{\raise0.2ex\hbox{$\bullet$}} % Signs frequently used for \itemize
112 \def\icirc{\raise0.2ex\hbox{$\circ$}} % Signs frequently used for \itemize
113 \def\idot{\raise0.2ex\hbox{$\cdot$}}
114 \def\istar{\raise0.2ex\hbox{$\ast$}}
115
116 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
117 \let\itemnumbering=#1}
118
119 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
120 \llap{\itemnumbering\hskip 0.4em}}
121
122 \def\nnorm{\the\itemcount}
123 \def\ndotted{\nnorm.}
124 \def\nparen{\nnorm)}
125 \def\nroman{\romannumeral\itemcount}
126 \def\nromanp{\nroman)}
127 \def\nalpha{\count@=96\advance\count@ by\itemcount\char\count@)}
128 \def\nAlpha{\count@=64\advance\count@ by\itemcount\char\count@)}
129 \def\ngreek{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
130 \zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
131 \or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$)}
132
133 % New \frenchspacing, which doesn't leave unwanted spaces in text.
134 \def\frenchsp@cing{\sfcode`\.\@m \sfcode`\?\@m \sfcode`\!\@m%
135 \sfcode`\:\@m \sfcode`\;\@m \sfcode`\,\@m}
136
137 %%% Local verbatim mode %%%
138
139 \def\make@ther#1{\catcode`#1=12\relax}
140 \def\setverb@tim{\tt\frenchsp@cing\catcode`\`=13\catcode`\'=13\n@ligs%
141 \let\do=\make@ther\dospecials\obeyspaces}
142
143 {\catcode`'=13
144 \catcode``=13
145 \gdef\n@ligs{\def`{\relax\lq}\def'{\relax\rq}}}
146
147 {\obeyspaces
148 \global\chardef\sp@ce=32
149 \gdef\showspaces{\let =\sp@ce}
150 \global\let =\ }
151
152 \catcode124=\active % Make | active
153 \def\ttst@rt{\begingroup\setverb@tim\let|=\endgroup}
154 \let|=\ttst@rt
155
156 %%% Verbatim mode for text in { } %%%
157
158 \newskip\verbglue\newskip\verblineglue
159 \verbglue=3pt plus 1pt minus 0.3pt
160 \verblineglue=0pt plus 1.5pt
161 \def\verblocaldefs{}
162
163 \newdimen\tabwidth
164 \newcount\tabsize
165 \tabsize=8
166 \newdimen\t@b
167
168 \newcount\vercnt
169 \def\v@rbend{\par\endgroup\vskip\verbglue}
170 \def\v@rbl{\ifnum\vercnt>0\{\fi\global\advance\vercnt by 1\relax}
171 \def\v@rbr{\ifnum\vercnt>1\}\else\v@rbend\fi\global\advance\vercnt by -1\relax}
172 \def\v@rbparams{\setverb@tim\parskip=\verblineglue\parindent=0pt\raggedbottom%
173 \rightskip\z@ plus1fil\pretolerance=10000\tolerance=10000\vercnt=0%
174 \catcode124=12\setupt@bs\vskip\verbglue\defb@x\obeylines}
175
176 \def\startb@x{\setbox0=\hbox\bgroup}
177 \def\defb@x{\def\par{\leavevmode\egroup\box0\endgraf}%
178 \everypar{\startb@x}}
179
180 {\catcode`\^^I=\active
181 \gdef\setupt@bs{\catcode`\^^I=\active
182 \setbox0=\hbox{\tt\ }\tabwidth=\wd0\multiply\tabwidth by \tabsize
183 \def^^I{\leavevmode\egroup\t@b=\wd0\divide\t@b by \tabwidth%
184 \multiply\t@b by \tabwidth%
185 \advance\t@b by \tabwidth\advance\t@b by -\wd0\box0\hbox to \t@b{}\startb@x}
186 }}
187
188 {
189 \catcode`[=1\catcode`]=2\catcode123=\active\catcode125=\active
190 \gdef\verbatim[\begingroup\v@rbparams\catcode123=\active\catcode125=\active%
191 \let{=\v@rbl\let}=\v@rbr\chardef\{=123\chardef\}=125\verblocaldefs
192 ]]
193
194 \def\verbinput#1{\begingroup\v@rbparams\input #1\endgroup}
195
196 %%% Algorithms %%%
197
198 %       \algo{jmeno algoritmu}
199 %       \algin popis vstupu
200 %       \:krok
201 %       \:krok
202 %       \::vnoreny krok
203 %       \algout popis vystupu
204 %       \endalgo
205
206 \def\algo{
207 \interlistskip
208 \begingroup
209 \let\:=\algoitem
210 \parskip=1pt plus 1pt minus 0.3pt
211 \rightskip=2em
212 \itemcount=0
213 \smallskip
214 }
215 \def\endalgo{\interlistskip\endgroup}
216 \def\algopar{\par
217 \parindent=2em
218 \hangindent=4em
219 \hangafter=1
220 \leavevmode
221 }
222 \def\algoitem{
223 \algopar\advance\itemcount by 1
224 \hbox to 2em{\hss \the\itemcount. }%
225 \futurelet\next\algoitemh}
226 \def\algoitemh{\ifx\next:\let\next=\algohang\else\let\next=\relax\fi\next}
227 \def\algohang:{\advance\hangindent by 2em \hskip 2em\futurelet\next\algoitemh}
228 \def\algin{\par{\sl Input:\/} }
229 \def\algout{\par{\sl Output:\/} }
230
231 %%% Constructs used in algorithms %%%
232
233 \def\={\leftarrow}
234 \def\cmt#1{~~{\sl (#1)}}
235
236 %%% Chapters, sections and proclamations %%%
237
238 \newcount\chapcount
239 \newcount\seccount
240 \newcount\thmcount
241 \newcount\tmpcount
242 \chapcount=0
243 \seccount=0
244 \thmcount=0
245 \def\currentid{??}
246 \def\currentchap{??}
247
248 \def\appendices{\chapcount=99}
249
250 \def\oddpage{%
251 \iffinal
252   \ifodd\pageno
253   \else
254     \hglue 1in \vfill\supereject
255   \fi
256 \fi
257 }
258
259 \def\rawchapter#1{\vfill\supereject
260 \oddpage
261 \leftline{\chapfont #1}
262 \bigskip
263 }
264
265 \def\unchapter#1{
266 \rawchapter{#1}
267 \writetoc{unchap}{#1}
268 }
269
270 \def\chapter#1{\advance\chapcount by 1
271 \seccount=0
272 \thmcount=0
273 \footcnt=0
274 % Chapter name
275   \ifnum\chapcount>99
276     \tmpcount=\chapcount
277     \advance\tmpcount by -100
278     \edef\currentchap{\ifcase\tmpcount A\or B\or C\or D\or E\or ZZZ\fi}
279   \else
280     \edef\currentchap{\the\chapcount}
281   \fi
282 \edef\currentid{\currentchap}
283 \rawchapter{\currentid. #1}
284 \writetoc{chap}{#1}
285 }
286
287 \def\vensure#1{\dimen0=#1
288 \vskip 0pt plus \dimen0
289 \penalty-1000
290 \vskip 0pt plus -\dimen0
291 }
292
293 \def\rawsection#1{\bigskip\vensure{0.5in}
294 \leftline{\secfont #1}
295 \nobreak
296 \medskip
297 \nobreak
298 }
299
300 \def\section#1{\advance\seccount by 1
301 \thmcount=0
302 \edef\currentid{\currentchap.\the\seccount}
303 \rawsection{\currentid. #1}
304 \writetoc{sec}{#1}
305 }
306
307 \def\para{\advance\thmcount by 1
308 \edef\currentid{\currentchap.\the\seccount.\the\thmcount}
309 \noindent {\bo \currentid.\enspace}}
310
311 \def\proclaim#1{\para {\bo #1.\enspace}}
312
313 \def\thm{\proclaim{Theorem}}
314 \def\lemma{\proclaim{Lemma}}
315 \def\defn{\proclaim{Definition}}
316 \def\problem{\proclaim{Problem}}
317 \def\obs{\proclaim{Observation}}
318 \def\rem{\proclaim{Remark}}
319 \def\alg{\proclaim{Algorithm}}
320 \def\impl{\proclaim{Implementation}}
321 \def\cor{\proclaim{Corollary}}
322 \def\nota{\proclaim{Notation}}
323 \def\example{\proclaim{Example}}
324
325 \def\label#1{{\sl (#1)\/}\enspace}
326 \def\labelx#1{\label{#1}\hfil\break\eatspaces}
327 \def\eatspaces{\kern0pt}
328
329 \def\thmn{\thm\labelx}
330 \def\lemman{\lemma\labelx}
331 \def\defnn{\defn\labelx}
332 \def\corn{\cor\labelx}
333 \def\algn{\alg\label}
334 \def\notan{\nota\labelx}
335 \def\examplen{\example\labelx}
336 \def\problemn{\problem\labelx}
337 \def\remn{\rem\labelx}
338
339 \def\paran#1{\para {\sl #1.\/}\enspace\eatspaces}
340
341 \def\proof{\noindent {\sl Proof.}\enspace}
342 \def\proofsketch{\noindent {\sl Proof sketch.}\enspace}
343
344 %%% Table of contents %%%
345
346 \newwrite\toc
347 \immediate\openout\toc=\jobname.toc
348 \newif\iftoc
349 \tocfalse
350
351 \def\writetoc#1#2{
352   \toctrue
353   \toks0={\the\pageno}
354   \edef\tocaux{\write\toc{\noexpand\expandafter\noexpand\string\noexpand\csname toc#1\noexpand\endcsname{\currentid}{#2}{\the\toks0}}}
355   \tocaux
356   \tocfalse
357 }
358
359 \newwrite\tok
360 \def\includetoc{
361 \immediate\openin\tok=\jobname.tok
362 \ifeof\tok
363 \else
364 \input \jobname.tok
365 \fi
366 \immediate\closein\tok
367 }
368
369 \def\tocchap#1#2#3{\smallskip\line{\bo #1.~~#2 \dotfill ~#3}}
370 \def\tocsec#1#2#3{\line{#1.~~#2 \dotfill ~#3}}
371 \def\tocunchap#1#2#3{\smallskip\line{\bo #2 \dotfill ~#3}}
372
373 %%% References %%%
374
375 \newwrite\ids
376 \def\writeid#1#2{\immediate\write\ids{\string\def\expandafter\string\csname id#1\endcsname{#2}}}
377
378 \immediate\openin\ids=\jobname.ids
379 \ifeof\ids
380 \else
381 \input \jobname.ids
382 \fi
383 \immediate\closein\ids
384 \immediate\openout\ids=\jobname.ids
385
386 \def\ref#1{\expandafter\ifx\csname id#1\endcsname\relax
387 {\bo ??}%
388 \immediate\write16{*** Warning: Reference #1 undefined ***}%
389 \else
390 \csname id#1\endcsname
391 \fi
392 }
393
394 \def\id#1{\writeid{#1}{\currentid}}
395
396 %%% Bibliography %%%
397
398 %\bibliographystyle{abbrv}
399 \bibliographystyle{mjalpha}
400 \def\dumpbib{
401   \def\bblhook{\parskip=2pt plus 1pt minus 0.5pt}
402   \bibliography{biblio}
403 }
404
405 %%% Figures %%%
406
407 \def\float#1#2{\midinsert
408 \medskip
409 \centerline{#1}
410 \medskip
411 \smallskip
412 \centerline{#2}
413 \endinsert}
414
415 \def\figure#1#2#3{\float{\epsfxsize=#2\epsfbox{pic/#1}}{#3}}
416
417 \def\multicap#1{
418 \let\\=\break
419 \vbox{\hsize=0.7\hsize
420 \parindent=0pt
421 \leftskip=0pt plus 0.3\hsize
422 \rightskip=\leftskip
423 \parfillskip=0pt
424 #1
425 }}
426
427 %%% Stand-alone chapters %%%
428
429 \def\endpart{
430   \section{Bibliography}
431   \dumpbib
432   \vfill\supereject\end
433 }
434
435 %%% Hyphenation %%%
436
437 \hyphenation{Ra-ma-chan-dran}
438
439 %%% Output routine %%%
440
441 \output{\sagaoutput}
442
443 \def\sagaoutput{
444 \iffinal
445   \ifodd\pageno \hoffset=\hwobble \else \hoffset=0pt \fi
446 \fi
447 \plainoutput}
448
449 \def\makefootline{\baselineskip30pt\lineskiplimit 0pt\line{\the\footline}}
450
451 \footline={\ifodd\pageno
452   {\hfil\mi\the\pageno}%
453 \else
454   {\mi\the\pageno\hfil}%
455 \fi
456 }
457
458 %%% The End %%%
459
460 \catcode`@=12