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