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