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