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