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