]> mj.ucw.cz Git - ads1.git/blob - mjmac.tex
Uvod od Karla
[ads1.git] / mjmac.tex
1 % MJ's TeX Macro Collection
2 % (c) 1995--2004 Martin Mares <mj@ucw.cz>
3 % Freely distributable as long as the author's copyright is left intact
4
5 % History:
6 % 2.0 (05-11-95)  Itemization and list system completely rewritten. Hopefully
7 %                 it's usable now.
8 % 2.1 (11-05-96)  Added \fixfont.
9 % 2.2 (15-02-97)  Modified \fixfont not to leave extra spaces.
10 %                 Added \relax at the end of \tt.
11 %                 Added a very limited support for picture drawing.
12 % 2.3 (21-05-01)  Modified \fixfont to use \fntdesignsize,
13 %                 Added \fntmath(|s|ss)size and used it in \setmath
14 %                 Added \twelvepoint
15 % 2.4 (10-07-03)  Added \bo
16 % 2.5 (27-09-03)  Added \verblocaldefs
17 % 2.6 (21-03-04)  Added \itemspacingrules
18 % 2.7 (10-04-04)  There were collisions between our \[bB]ig and the same
19 %                 macro used in plain to implement \bigl et al. Now we rename
20 %                 the original \[bB]ig to \plain[bB]ig and re-define \[bB]ig[lrm]
21 %                 to call the renamed version instead.
22
23 % We'll use internal macros of plain TeX
24
25 \catcode`@=11
26
27 \newcount\mjtempcount
28
29 % Page size definition
30 % --------------------
31
32 % Standard A4 dimensions are used. For different set of dimensions, redefine the
33 % \setpagesize macro to set everything you want in true units. Don't forget to
34 % call the macro immediately to refresh current setting. \magnification can be
35 % set prior to inclusion of these macros.
36
37 \def\setpagesize{\hsize=7truein\vsize=9.2truein}
38 \def\m@g{\mag\count@\setpagesize\dimen\footins8truein}
39 \setpagesize
40
41 % Spacing
42 % -------
43
44 \parindent=1.4cm
45 \parskip=3pt plus 1pt minus 1pt
46
47 % We want to override \[bB]ig in plain, so save the original definition
48 % ---------------------------------------------------------------------
49
50 \let\plainbig=\big
51 \let\plainBig=\Big
52 \def\bigl{\mathopen\plainbig}
53 \def\bigm{\mathrel\plainbig}
54 \def\bigr{\mathclose\plainbig}
55 \def\Bigl{\mathopen\plainBig}
56 \def\Bigm{\mathrel\plainBig}
57 \def\Bigr{\mathclose\plainBig}
58
59 % Font selection system
60 % ---------------------
61
62 % The heart of the font selection system is the \setfont macro which selects
63 % the current font according to the following settings:
64 % \fntprefix - font name prefix (usually cm or cs)
65 % \fntdesignsize - font design size in points (normally 10)
66 % \fnttokprefix - prefix of control sequence the font is assigned to ('ten')
67 % \fntmag - font magnification factor
68 % \fnttoksuffix - control sequence suffix ('A' to 'G' according to mag)
69 % \fntstyle - font name suffix determining font style ('bx', 'r' etc.)
70
71 \def\fntprefix{cs}
72 \def\fntdesignsize{10}
73 \def\fnttokprefix{ten}
74 \def\fntmag{\magstep0}
75 \def\fnttoksuffix{A}
76 \def\fntstyle{r}
77
78 \def\setfont{%
79 \toks0=\expandafter{\csname\fnttokprefix\fntstyle\fnttoksuffix\endcsname}%
80 \expandafter\ifx\the\toks0\relax%
81 %\immediate\write-1{aa \the\toks0=\fntprefix\fntstyle\fntdesignsize\space scaled \fntmag}%
82 \global\expandafter\font\the\toks0=\fntprefix\fntstyle\fntdesignsize\space scaled \fntmag%
83 \fi%
84 \edef\currentfont{\the\toks0}\currentfont}
85
86 \setfont  % Initialize the whole mechanism
87
88 \def\mathf@nt#1#2#3#4{%
89 \toks0=\expandafter{\csname#1#2\fnttoksuffix\endcsname}%
90 \expandafter\ifx\the\toks0\relax%
91 %\immediate\write-1{bb \the\toks0=#4#2#3\space scaled \fntmag}%
92 \global\expandafter\font\the\toks0=#4#2#3\space scaled \fntmag%
93 \fi%
94 \edef\m@@f{\the\toks0}}
95
96 \def\fntmathsize{10}
97 \def\fntmathtok{ten}
98 \def\fntmathssize{7}
99 \def\fntmathstok{seven}
100 \def\fntmathsssize{5}
101 \def\fntmathsstok{five}
102
103 \def\setmath{%
104 \mathf@nt{\fntmathtok}{r}{\fntmathsize}{cs}\textfont0=\m@@f
105 \mathf@nt{\fntmathstok}{r}{\fntmathssize}{cs}\scriptfont0=\m@@f
106 \mathf@nt{\fntmathsstok}{r}{\fntmathsssize}{cs}\scriptscriptfont0=\m@@f
107 \mathf@nt{\fntmathtok}{mi}{\fntmathsize}{cm}\skewchar\m@@f='177\textfont1=\m@@f
108 \mathf@nt{\fntmathstok}{mi}{\fntmathssize}{cm}\skewchar\m@@f='177\scriptfont1=\m@@f
109 \mathf@nt{\fntmathsstok}{mi}{\fntmathsssize}{cm}\skewchar\m@@f='177\scriptscriptfont1=\m@@f
110 \mathf@nt{\fntmathtok}{sy}{\fntmathsize}{cm}\skewchar\m@@f='60\textfont2=\m@@f
111 \mathf@nt{\fntmathstok}{sy}{\fntmathssize}{cm}\skewchar\m@@f='60\scriptfont2=\m@@f
112 \mathf@nt{\fntmathsstok}{sy}{\fntmathsssize}{cm}\skewchar\m@@f='60\scriptscriptfont2=\m@@f
113 \mathf@nt{\fntmathtok}{ex}{\fntmathsize}{cm}\textfont3=\m@@f\scriptfont3=\m@@f\scriptscriptfont3=\m@@f
114 \mathf@nt{\fntmathtok}{ti}{\fntmathsize}{cs}\textfont\itfam=\m@@f
115 \mathf@nt{\fntmathtok}{sl}{\fntmathsize}{cs}\textfont\slfam=\m@@f
116 \mathf@nt{\fntmathtok}{bx}{\fntmathsize}{cs}\textfont\bffam=\m@@f
117 \mathf@nt{\fntmathtok}{tt}{\fntmathsize}{cs}\hyphenchar\m@@f=-1\textfont\ttfam=\m@@f
118 }
119
120 % Call \fixfont to fix lineskip, math fonts and the strut box
121
122 \def\fixfont{\setfont\setmath
123 \mjtempcount=\fntdesignsize
124 \multiply\mjtempcount by \fntmag
125 \normalbaselineskip=0.12pt
126 \multiply\normalbaselineskip by \mjtempcount
127 \divide\normalbaselineskip by 100
128 \normallineskip=0.01pt
129 \multiply\normallineskip by \mjtempcount
130 \divide\normallineskip by 100
131 \normalbaselines
132 \dimen0=0.085pt
133 \multiply\dimen0 by \mjtempcount
134 \divide\dimen0 by 100
135 \dimen1=0.035pt
136 \multiply\dimen1 by \mjtempcount
137 \divide\dimen1 by 100
138 \setbox\strutbox=\hbox{\vrule height\dimen0 depth\dimen1 width\z@}}
139
140 % You can use the following macros to change the magnification:
141
142 \def\normal{\def\fntmag{\magstep0}\def\fnttoksuffix{A}\setfont}       % Normal size
143 \def\halflarge{\def\fntmag{\magstephalf}\def\fnttoksuffix{b}\setfont} % Magstephalf
144 \def\large{\def\fntmag{\magstep1}\def\fnttoksuffix{B}\setfont}        % Magstep 1
145 \def\Large{\def\fntmag{\magstep2}\def\fnttoksuffix{C}\setfont}
146 \def\big{\def\fntmag{\magstep3}\def\fnttoksuffix{D}\setfont}
147 \def\Big{\def\fntmag{\magstep4}\def\fnttoksuffix{E}\setfont}
148 \def\huge{\def\fntmag{\magstep5}\def\fnttoksuffix{F}\setfont}
149 \def\Huge{\def\fntmag{\magstep6}\def\fnttoksuffix{G}\setfont}         % Magstep 6
150 \def\fm#1{\def\fntmag{\magstep#1}\edef\fnttoksuffix{\ifcase #1 A\or B\or C%
151 \or D\or E\or F\or G\fi}\setfont}                                     % User mag
152
153 % And to change the style:
154
155 \def\rm{\fam\z@\def\fntstyle{r}\setfont}        % Roman
156 \def\it{\fam\itfam\def\fntstyle{ti}\setfont}    % Italic
157 \def\bo{\fam\bffam\def\fntstyle{b}\setfont}     % Bold
158 \def\bf{\fam\bffam\def\fntstyle{bx}\setfont}    % Bold extended
159 \def\ss{\def\fntstyle{ss}\setfont}              % Sans serif
160 \def\tt{\fam\ttfam\def\fntstyle{tt}\setfont%
161 \hyphenchar\currentfont=-1\relax}               % Typewriter
162 \def\sc{\def\fntstyle{csc}\setfont}             % Caps and small caps
163 \def\ssi{\def\fntstyle{ssi}\setfont}            % Sans serif italic
164 \def\sl{\fam\slfam\def\fntstyle{sl}\setfont}    % Slanted
165 \def\ssbf{\def\fntstyle{ssbx}\setfont}          % Sans serif bold
166 \def\ssdc{\def\fntstyle{ssdc}\setfont}          % Sans serif demi condensed
167
168 % Switch to large font set
169
170 \def\twelvepoint{
171 \def\fntdesignsize{12}
172 \def\fnttokprefix{twelve}
173 \def\fntmathsize{12}\def\fntmathtok{twelve}
174 \def\fntmathssize{8}\def\fntmathstok{eight}
175 \def\fntmathsssize{6}\def\fntmathsstok{six}
176 \fixfont
177 }
178
179 % Itemization
180 % -----------
181
182 \newif\ifitem\itemtrue
183 \newbox\itembox
184 \newcount\itemcount
185
186 \def\interlistskip{\vskip 3pt plus 2pt minus 1pt}
187
188 \def\itemspacingrules{\ifitem\advance\leftskip by \parindent\parindent=0pt\itemfalse\fi
189 \advance\leftskip by 2.5em}
190
191 \def\inititemize{\interlistskip\begingroup
192 \parskip=1pt plus 0.3pt minus 0.1pt
193 \itemspacingrules}
194
195 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip 0.4em}%
196 \let\:=\singleitem}
197
198 \def\singleitem{\par\leavevmode\copy\itembox}
199
200 \def\endlist{\interlistskip\endgroup}
201
202 \def\ibull{\raise0.2ex\hbox{$\bullet$}} % Signs frequently used for \itemize
203 \def\idot{\raise0.2ex\hbox{$\cdot$}}
204 \def\istar{\raise0.2ex\hbox{$\ast$}}
205
206 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
207 \let\itemnumbering=#1}
208
209 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
210 \llap{\itemnumbering\hskip 0.4em}}
211
212 \def\nnorm{\the\itemcount}
213 \def\ndotted{\nnorm.}
214 \def\nparen{\nnorm)}
215 \def\nroman{\romannumeral\itemcount}
216 \def\nromanp{\nroman)}
217 \def\nalpha{\count@=96\advance\count@ by\itemcount\char\count@)}
218 \def\nAlpha{\count@=64\advance\count@ by\itemcount\char\count@)}
219 \def\ngreek{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
220 \zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
221 \or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$)}
222
223 \def\itm{\:}
224
225 % Additional math functions
226 % -------------------------
227
228 \def\mod{\;{\rm mod}\;}
229 \def\div{\;{\rm div}\;}
230 \def\xor{\;{\rm xor}\;}
231
232 \def\mathbox#1{  % Typeset math formula enclosed in a box.
233 $$\vbox{
234 \hrule
235 \hbox{\vrule height 10pt depth 5pt\hskip3mm\hbox{$#1$}\hskip3mm\vrule }
236 \hrule
237 }$$}
238
239 % Italic typesetting    (automatic \/)
240 % ------------------
241
242 \def\I{\it\aftergroup\/}
243
244 % New \frenchspacing, which doesn't leave unwanted spaces in text.
245
246 \def\frenchsp@cing{\sfcode`\.\@m \sfcode`\?\@m \sfcode`\!\@m%
247 \sfcode`\:\@m \sfcode`\;\@m \sfcode`\,\@m}
248
249 % Typesetting of one verbatim word
250 % --------------------------------
251
252 \def\make@ther#1{\catcode`#1=12\relax}
253 \def\setverb@tim{\tt\frenchsp@cing\catcode`\`=13\catcode`\'=13\n@ligs%
254 \let\do=\make@ther\dospecials\obeyspaces}
255
256 {\catcode`'=13
257 \catcode``=13
258 \gdef\n@ligs{\def`{\relax\lq}\def'{\relax\rq}}}
259
260 {\obeyspaces
261 \global\chardef\sp@ce=32
262 \gdef\showspaces{\let =\sp@ce}
263 \global\let =\ }
264
265 \catcode124=\active % Make | active
266 \def\ttst@rt{\begingroup\setverb@tim\let|=\endgroup}
267 \let|=\ttst@rt
268
269 % Typesetting of verbatim text  (enclosed in { } )
270 % ----------------------------
271
272 \newskip\verbglue\newskip\verblineglue
273 \verbglue=3pt plus 1pt minus 0.3pt
274 \verblineglue=0pt plus 1.5pt
275 \def\verblocaldefs{}
276
277 \newdimen\tabwidth
278 \newcount\tabsize
279 \tabsize=8
280 \newdimen\t@b
281
282 \newcount\vercnt
283 \def\v@rbend{\par\endgroup\vskip\verbglue}
284 \def\v@rbl{\ifnum\vercnt>0\{\fi\global\advance\vercnt by 1\relax}
285 \def\v@rbr{\ifnum\vercnt>1\}\else\v@rbend\fi\global\advance\vercnt by -1\relax}
286 \def\v@rbparams{\setverb@tim\parskip=\verblineglue\parindent=0pt\raggedbottom%
287 \rightskip\z@ plus1fil\pretolerance=10000\tolerance=10000\vercnt=0%
288 \catcode124=12\setupt@bs\vskip\verbglue\defb@x\obeylines}
289
290 \def\startb@x{\setbox0=\hbox\bgroup}
291 \def\defb@x{\def\par{\leavevmode\egroup\box0\endgraf}%
292 \everypar{\startb@x}}
293
294 {\catcode`\^^I=\active
295 \gdef\setupt@bs{\catcode`\^^I=\active
296 \setbox0=\hbox{\tt\ }\tabwidth=\wd0\multiply\tabwidth by \tabsize
297 \def^^I{\leavevmode\egroup\t@b=\wd0\divide\t@b by \tabwidth%
298 \multiply\t@b by \tabwidth%
299 \advance\t@b by \tabwidth\advance\t@b by -\wd0\box0\hbox to \t@b{}\startb@x}
300 }}
301
302 {
303 \catcode`[=1\catcode`]=2\catcode123=\active\catcode125=\active
304 \gdef\verbatim[\begingroup\v@rbparams\catcode123=\active\catcode125=\active%
305 \let{=\v@rbl\let}=\v@rbr\chardef\{=123\chardef\}=125\verblocaldefs
306 ]]
307
308 % Input file verbatim
309 % -------------------
310
311 \def\verbinput#1{\begingroup\v@rbparams\input #1\endgroup}
312
313 % Pictures
314 % --------
315 % Allowed direction vectors are 0<=x<=6, -6<=y<=6, GCD(x,y)=1
316
317 \def\initlines{\font\lif=line10}
318 \def\linechar#1#2{\ifnum #1=0 \hbox to 0pt{\hss\vrule height 10pt\hss}\else
319 \ifnum #2=0 \vbox to 0pt{\vss\hrule width 10pt\vss}\else
320 {\count255=#1\multiply\count255 by 8
321 \ifnum #2>0 \advance\count255 by #2 \advance\count255 by -9
322 \else\advance\count255 by -#2 \advance\count255 by 55\fi
323 \lif\char\count255}\fi\fi}
324 \def\picture#1#2#3{\initlines\medskip\centerline{\vbox to #2{\hbox to #1{#3\hss}\vss}}\medskip}
325 \def\place#1#2#3{{\setbox0=\hbox to 0pt{#3 \hss}\ht0=0pt\dp0=0pt
326 \hbox to 0pt{\hskip #1\lower #2\box0\hss}}}
327 \def\pl@celine{\ifnum \count255>0 \place{\dimen0}{\dimen1}{\copy0}\advance\dimen0 by \wd0
328 \advance\dimen1 by -\ht0 \advance\count255 by -1 \pl@celine\fi}
329 \def\placeline#1#2#3#4#5{{\setbox0=\hbox{\linechar{#3}{#4}}\ifnum #4<0\setbox0=\hbox to -\wd0{\hss\box0}\fi
330 \dimen0=#1\dimen1=#2\count255=#5\pl@celine}}
331 \def\cplace#1#2#3{\place{#1}{#2}{\hss #3}}
332
333 % Let's hide all internal macros
334
335 \catcode`@=12