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