Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
1169 kaklik 1
% OPmac
2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3
%% Petr Olsak, 2012, 2013, 2014
4
 
5
%% The history of versions is at the end of this file, after \endpinput
6
 
7
\ifx\OPmacversion\undefined \else \endinput \fi
8
\def\OPmacversion{May 2014}
9
 
10
\immediate\write16{This is OPmac (Olsak's Plain macros), version <\OPmacversion>}
11
 
12
%%%%%%%%%%%%%% Basic macros, sec. 3.1 in opmac-d.pdf
13
 
14
\newcount\tmpnum % auxiliary count
15
\newdimen\tmpdim % auxiliary dimen
16
 
17
\def\opwarning#1{\immediate\write16{l.\the\inputlineno\space OPmac WARNING: #1.}}
18
 
19
\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
20
 
21
\def\protectlist{}
22
\def\addprotect#1{\addto\protectlist{\doprotect#1}}
23
\addprotect~
24
 
25
\newif\ifpdftex  \pdftextrue
26
\ifx\pdfoutput\undefined \pdftexfalse \else \ifnum\pdfoutput=0 \pdftexfalse \fi \fi
27
\ifx\XeTeXversion\undefined \else \pdftextrue \fi
28
 
29
\def\sdef#1{\expandafter\def\csname#1\endcsname}
30
\def\sxdef#1{\expandafter\xdef\csname#1\endcsname}
31
 
32
\def\adef#1{\catcode`#1=13
33
   \bgroup \lccode`\~=`#1\lowercase{\egroup\def~}%
34
}
35
 
36
\def\isdefined #1#2{\expandafter\ifx \csname#1\endcsname \relax
37
     \csname iffalse\expandafter\endcsname
38
   \else
39
     \csname iftrue\expandafter\endcsname
40
   \fi
41
}
42
\def\isinlist#1#2#3{\def\tmp##1#2##2\end{\def\tmp{##2}%
43
   \ifx\tmp\empty \csname iffalse\expandafter\endcsname \else
44
                  \csname iftrue\expandafter\endcsname \fi}%
45
   \expandafter\tmp#1\endlistsep#2\end
46
}
47
\def\isnextchar#1#2#3{\def\tmpa{#2}\def\tmpb{#3}%
48
   \let\tmp=#1\futurelet\next\isnextcharA
49
}
50
\def\isnextcharA{\ifx\tmp\next\expandafter\tmpa\else\expandafter\tmpb\fi}
51
 
52
\def\uv#1{\clqq#1\crqq}
53
\let\\=\undefined
54
{\lccode`\?=`\%  \lowercase{\gdef\percent{?}}}
55
{\lccode`\?=`\\  \lowercase{\gdef\bslash{?}}}
56
\def\,{\ifmmode \mskip\thinmuskip \else \thinspace \fi}
57
\addprotect\percent \addprotect\bslash \addprotect\, \addprotect\exfont
58
 
59
%%%%%%%%%%%%%% Global parameters, sec. 3.2 in opmac-d.pdf
60
 
61
\widowpenalty=10000
62
\clubpenalty=10000
63
\showboxdepth=7
64
\showboxbreadth=30
65
 
66
\newdimen\iindent  \iindent=\parindent
67
   % indentation of items, TOC, captions, list of bib. references
68
\newdimen\ttindent \ttindent=\parindent
69
   % indentation in \begtt...\endtt and \verbinput
70
 
71
\def\ttskip{\medskip}       % space above and below \begtt, \verbinput
72
\mathchardef\ttpenalty=100  % penalty between lines in \begtt, \verbinput
73
\def\tthook{}               % hook in \begtt, \verbinput
74
\def\intthook{}             % hook in in-text verbatim
75
 
76
\def\iiskip{\medskip}     % space above and below \begitems...\enditems
77
\def\bibskip{\smallskip}  % space between bibitems
78
 
79
\def\tabstrut{\strut}     % strut in the \table
80
\def\tabiteml{\enspace}   % left material before each \table item
81
\def\tabitemr{\enspace}   % right material after each \table item
82
\def\vvkern{1pt}          % space between vertical lines
83
\def\hhkern{1pt}          % space between horizontal lines
84
 
85
\def\multiskip{\medskip}      % space above and below \begmulti...\endmulti
86
\newdimen\colsep \colsep=2em  % space between columns
87
 
88
\newdimen\mnoteindent \mnoteindent=10pt % ditance between mnote and text
89
\newdimen\mnotesize   \mnotesize=20mm   % the width of the mnote paragraph
90
 
91
\def\picdir{}      % the directory with picture files
92
\def\bibtexhook{}  % hook in \usebibtex and \usebbl macros
93
\def\chaphook{}    % hook in \chap
94
\def\sechook{}     % hook in \sec
95
\def\secchook{}    % hook in \secc
96
\def\cnvhook{}     % hook before conversion of outlines
97
\def\pghook{}      % hook in \output rutine
98
\def\toclinehook{} % hook in \tocline
99
\def\fnotehook{}   % hook in \fnote
100
\def\mnotehook{}   % hook in \mnote
101
\def\captionhook#1{} % hook in \caption (#1 is "t" or "f")
102
 
103
%%%%%%%%%%%%%% OPmac, CSplain and LaTeX logos, sec. 3.3 in opmac-d.pdf
104
 
105
\def\OPmac{\leavevmode
106
   \lower.2ex\hbox{\thefontscale[1400]O}\kern-.86em P{\em mac}}
107
\def\CS{$\cal C$\kern-.1667em\lower.5ex\hbox{$\cal S$}}
108
\def\csplain{\CS plain}
109
 
110
\def\LaTeX{\tmpdim=.42ex L\kern-.36em \kern\slantcorr % slant correction
111
  \raise\tmpdim\hbox{\thefontscale[710]A}%
112
  \kern-.15em \kern-\slantcorr \TeX}
113
\def\slantcorr{\expandafter\ignorept\the\fontdimen1\the\font\tmpdim}
114
 
115
\addprotect\TeX   \addprotect\OPmac   \addprotect\CS  \addprotect\LaTeX
116
 
117
 
118
%%%%%%%%%%%%%% Sizes of fonts and \baselineskip, sec. 3.4 in opmac-d.pdf
119
 
120
\ifx\regfont\undefined
121
   \ifx\uselanguage\undefined
122
      \opwarning{csplain version <Nov. 2012> or later is recommended}
123
   \fi
124
   % macros from csplain, file csfontsm.tex:
125
   \font\tenbi=csbxti10 \def\bi{\tenbi}
126
   \def\letfont#1#2{\ifx#2=\expandafter\letfont\expandafter#1\else
127
     \expandafter\font\expandafter#1\expandafter\rfontskipat\fontname#2 \relax\space \fi}
128
   \def\rfontskipat#1{\ifx#1"\expandafter\rfskipatX\else\expandafter\rfskipatN\expandafter#1\fi}
129
   \def\rfskipatX #1" #2\relax{"\whichtfm{#1}"}  \def\rfskipatN #1 #2\relax{\whichtfm{#1}}
130
   \def\sizespec{}   \def\whichtfm#1{#1}
131
   \def\resizefont#1{\letfont#1#1\sizespec}
132
   \def\regfont#1{\expandafter\def\expandafter\resizeall\expandafter{\resizeall \resizefont#1}}
133
   \def\resizeall{}
134
   \regfont\tenrm \regfont\tenit \regfont\tenbf \regfont\tenbi \regfont\tentt
135
\fi
136
 
137
\newdimen\ptunit    \ptunit=1pt
138
\newdimen\fontdim   \fontdim=10pt
139
 
140
\ifx\normalmath\undefined \input ams-math \fi  % ams-math.tex is in csplain package
141
 
142
{\lccode`\?=`\p \lccode`\!=`\t  \lowercase{\gdef\ignorept#1?!{#1}}}
143
 
144
\def\typosize[#1/#2]{\fontsizex[#1]\setbaselineskip[#2]\ignorespaces}
145
\def\typoscale[#1/#2]{\fontscalex[#1]\scalebaselineskip[#2]\ignorespaces}
146
 
147
\def\fontsizex[#1]{\if$#1$\else
148
  \textfontsize[#1]%
149
  \tmpdim=0.7\fontdim \edef\tmpa{\expandafter\ignorept\the\tmpdim}%
150
  \tmpdim=0.5\fontdim \edef\tmpb{\expandafter\ignorept\the\tmpdim}%
151
  \edef\tmp{\noexpand\setmathsizes[\expandafter\ignorept\the\fontdim/\tmpa/\tmpb]}%
152
  \tmp \normalmath
153
  \fi
154
}
155
\def\textfontsize[#1]{\if$#1$\else
156
  \fontdim=#1\ptunit \ifx\fontdimB\undefined \edef\fontdimB{\the\fontdim}\fi
157
  \let\dgsize=\fontdim
158
  \edef\sizespec{at\the\fontdim}%
159
  \resizeall \rm \let\dgsize=\undefined
160
  \fi
161
}
162
\def\setbaselineskip[#1]{\if$#1$\else
163
  \tmpdim=#1\ptunit
164
  \baselineskip=\tmpdim \relax 
165
  \ifx\baselineskipB\undefined \edef\baselineskipB{\the\baselineskip}\fi
166
  \bigskipamount=\tmpdim plus.33333\tmpdim minus.33333\tmpdim
167
  \medskipamount=.5\tmpdim plus.16666\tmpdim minus.16666\tmpdim
168
  \smallskipamount=.25\tmpdim plus.08333\tmpdim minus.08333\tmpdim
169
  \normalbaselineskip=\tmpdim
170
  \jot=.25\tmpdim
171
  \maxdepth=.33333\tmpdim
172
  \setbox\strutbox=\hbox{\vrule height.709\tmpdim depth.291\tmpdim width0pt}%
173
  \fi
174
}
175
\def\withoutunit#1#2{\expandafter#1\expandafter[\expandafter\ignorept\the#2]}
176
 
177
\def\fontscalex[#1]{\if$#1$\else \ifnum#1=1000 \else
178
  \tmpdim=3277sp \tmpdim=#1\tmpdim \divide\tmpdim by50
179
  \tmpdim=\expandafter\ignorept\the\tmpdim \fontdim
180
  \withoutunit\fontsizex\tmpdim
181
  \fi\fi
182
}
183
\def\textfontscale[#1]{\if$#1$\else
184
  \tmpdim=#1pt \divide\tmpdim by1000
185
  \tmpdim=\expandafter\ignorept\the\tmpdim \fontdim
186
  \withoutunit\textfontsize\tmpdim
187
  \fi
188
}
189
\def\scalebaselineskip[#1]{\if$#1$\else \ifnum#1=1000 \else
190
  \tmpdim=3277sp \tmpdim=#1\tmpdim \divide\tmpdim by50
191
  \tmpdim=\expandafter\ignorept\the\tmpdim \baselineskip
192
  \withoutunit\setbaselineskip\tmpdim
193
  \fi\fi
194
}
195
\def\thefontsize[#1]{%
196
  \expandafter\let \expandafter\thefont \the\font
197
  \def\sizespec{at#1\ptunit}\def\dgsize{#1\ptunit}\resizefont\thefont
198
  \thefont \let\dgsize=\undefined \ignorespaces
199
}
200
\def\thefontscale[#1]{%
201
  \tmpdim=#1pt \divide\tmpdim by1000
202
  \tmpdim=\expandafter\ignorept\the\tmpdim \fontdim
203
  \withoutunit\thefontsize\tmpdim
204
}
205
\def\magstep#1{\ifcase#1 1000\or1200\or1440\or1728\or2074\or2488\fi\space}
206
 
207
\def\typobase{\ifx\baselineskipB\undefined \def\baselineskipB{12pt}\fi
208
   \ifx\fontdimB\undefined \def\fontdimB{10pt}\fi
209
   \baselineskip=\baselineskipB\relax \fontdim=\fontdimB\relax
210
}
211
\def\em {\expandafter\ifx \the\font \tenit \additcorr \rm  \else
212
         \expandafter\ifx \the\font \tenbf \bi\aftergroup\afteritcorr\else
213
         \expandafter\ifx \the\font \tenbi \additcorr \bf  \else
214
         \it \aftergroup\afteritcorr\fi\fi\fi}
215
\def\additcorr{\ifdim\lastskip>0pt \skip0=\lastskip \unskip\/\hskip\skip0 \else\/\fi}
216
\def\afteritcorr{\def\tmp{\ifx\next..\else\ifx\next,,\else\/%
217
                          \expandafter\expandafter\expandafter\next\expandafter\fi\fi}%
218
   \afterassignment\tmp \let\next= }
219
 
220
\addprotect\thefontsize   \addprotect\thefontscale
221
\addprotect\typosize      \addprotect\typoscale
222
\addprotect\textfontsize  \addprotect\textfontscale
223
\addprotect\em
224
 
225
 
226
%%%%%%%%%%%%%% Multilingual support, sec. 3.5 in opmac-d.pdf
227
 
228
\def\mtext#1{\csname mt:#1:\csname lan:\the\language\endcsname\endcsname}
229
 
230
\sdef{mt:chap:en}{Chapter}  \sdef{mt:chap:cs}{Kapitola}  \sdef{mt:chap:sk}{Kapitola}
231
\sdef{mt:t:en}{Table}       \sdef{mt:t:cs}{Tabulka}      \sdef{mt:t:sk}{Tabu\v lka}
232
\sdef{mt:f:en}{Figure}      \sdef{mt:f:cs}{Obr\'azek}    \sdef{mt:f:sk}{Obr\'azok}
233
 
234
\ifx\r\undefined \csname csaccents\endcsname \fi
235
 
236
\sdef{lan:0}{en}  \sdef{lan:100}{en} \sdef{lan:101}{en}
237
\sdef{lan:5}{cs}  \sdef{lan:15}{cs}  \sdef{lan:115}{cs}
238
\sdef{lan:6}{sk}  \sdef{lan:16}{sk}  \sdef{lan:116}{sk}
239
 
240
\ifx\uselanguage\undefined \else \message{OPmac: eTeX detected}
241
  \bgroup
242
     \uselanguage{czech}  \sxdef{lan:\the\language}{cs}
243
     \uselanguage{slovak} \sxdef{lan:\the\language}{sk}
244
  \egroup
245
\fi
246
 
247
%%%%%%%%%%%%%% REF file, sec 3.6 in opmac-d.pdf
248
 
249
\newwrite\reffile
250
\newread\testin
251
 
252
\def\wrefrelax#1#2{}
253
\let\wref=\wrefrelax
254
 
255
\def\inputref{
256
  \openin\testin=\jobname.ref
257
  \ifeof\testin \else
258
    \closein\testin
259
    \input \jobname.ref
260
    \fnotenum=0 \mnotenum=0 
261
    \immediate\openout\reffile=\jobname.ref
262
    \def\wref##1##2{\write\reffile{\string##1##2}}
263
    \immediate\write\reffile {\percent\percent\space OPmac - REF file}
264
  \fi
265
}
266
\def\openref{%
267
  \ifx\wref\wrefrelax
268
     \immediate\openout\reffile=\jobname.ref
269
     \gdef\wref##1##2{\write\reffile{\string##1##2}}%
270
     \immediate\write\reffile
271
       {\percent\percent\space OPmac - REF file (\string\openref)}%
272
  \fi
273
  \gdef\openref{}%
274
}
275
 
276
%%%%%%%%%%%%%% \label, \ref, \pgref, sec. 3.7 in opmac-d.pdf
277
 
278
\def\label[#1]{\isdefined{l0:#1}%
279
  \iftrue \opwarning{duplicated label [#1], ignored}\else \xdef\lastlabel{#1}\fi
280
  \ignorespaces}
281
 
282
\def\wlabel#1{%
283
  \ifx\lastlabel\undefined \else
284
     \dest[ref:\lastlabel]%
285
     \edef\tmp{\wref\Xlabel{{\lastlabel}{#1}}}\tmp
286
     \sxdef{lab:\lastlabel}{#1}\sxdef{l0:\lastlabel}{}%
287
     \global\let\lastlabel=\undefined
288
  \fi
289
}
290
\def\ref[#1]{\isdefined{lab:#1}%
291
  \iftrue \reflink[#1]{\csname lab:#1\endcsname}%
292
  \else ??\opwarning{label [#1] unknown. Try to TeX me again}\openref
293
  \fi
294
}
295
\def\pgref[#1]{\isdefined{pgref:#1}%
296
  \iftrue \pglink{\csname pgref:#1\endcsname}%
297
  \else ??\opwarning{pg-label [#1] unknown. Try to TeX me again}\openref
298
  \fi
299
}
300
\def\Xlabel#1#2{\sxdef{lab:#1}{#2}\sxdef{pgref:#1}{\the\lastpage}}
301
 
302
 
303
%%%%%%%%%%%%%% Chapters, sections, subsections -- sec. 3.8 in opmac-d.pdf
304
 
305
\def\printchap#1{\vfil\break
306
  {\chapfont \noindent \mtext{chap} \dotocnum{\thetocnum}\par
307
   \nobreak\smallskip\noindent #1\nbpar}\mark{}%
308
  \nobreak \remskip\bigskipamount \firstnoindent
309
}
310
\def\printsec#1{\par \norempenalty-400 \bigskip
311
  {\secfont \noindent \dotocnum{\thetocnum\quad}#1\nbpar}\insertmark{#1}%
312
  \nobreak \remskip\medskipamount \firstnoindent
313
}
314
\def\printsecc#1{\par \norempenalty-200 \medskip
315
  {\seccfont \noindent \dotocnum{\thetocnum\quad}#1\nbpar}%
316
  \nobreak \remskip\medskipamount \firstnoindent
317
}
318
\def\tit#1\par{\vglue4em
319
  {\leftskip=0pt plus1fill \rightskip=\leftskip
320
   \titfont \noindent #1\unskip\par}%
321
   \nobreak\bigskip
322
}
323
\def\titfont{\typobase\typoscale[\magstep4/\magstep4]\bf}
324
\def\chapfont{\typobase\typoscale[\magstep3/\magstep3]\bfshape}
325
\def\secfont{\typobase\typoscale[\magstep2/\magstep2]\bfshape}
326
\def\seccfont{\typobase\typoscale[\magstep1/\magstep2]\bfshape}
327
\def\bfshape{\let\tenit=\tenbi \boldmath \bf}
328
 
329
\newcount\chapnum \newcount\secnum \newcount\seccnum \newcount\nonumnum
330
\newif\ifnotoc \notocfalse  \def\notoc{\global\notoctrue}
331
\newif\ifnonum \nonumfalse  \def\nonum{\global\nonumtrue}
332
 
333
\def\chap#1\par{\ifnonum\else \global\advance\chapnum by1 \fi
334
  \chaphook {\globaldefs=1 \secnum=0 \seccnum=0 \tnum=0 \fnum=0 \dnum=0}\relax
335
  \edef\thechapnum{\the\chapnum}\let\thetocnum=\thechapnum 
336
  \def\dotocnumafter{\wcontents\Xchap{#1}}%
337
  \printchap{#1\unskip}\resetnonumnotoc
338
}
339
\def\sec#1\par{\ifnonum\else \global\advance\secnum by1 \fi
340
  \sechook {\globaldefs=1 \seccnum=0 \tnum=0 \fnum=0 \dnum=0}\relax
341
  \edef\thesecnum{\othe\chapnum.\the\secnum}\let\thetocnum=\thesecnum 
342
  \def\dotocnumafter{\wcontents\Xsec{#1}}% 
343
  \printsec{#1\unskip}\resetnonumnotoc
344
}
345
\def\secc#1\par{\ifnonum\else \global\advance\seccnum by1 \fi
346
  \secchook {}\relax
347
  \edef\theseccnum{\othe\chapnum.\the\secnum.\the\seccnum}\let\thetocnum=\theseccnum
348
  \def\dotocnumafter{\wcontents\Xsecc{#1}}%
349
  \printsecc{#1\unskip}\resetnonumnotoc
350
}
351
\def\wcontents#1#2{% #1: sequence to REF, #2: titletext
352
  \ifnotoc\else
353
      \expandafter\wref\expandafter#1\expandafter
354
        {\expandafter{\thetocnum}{#2}{\the\pageno}}%
355
  \fi
356
}
357
\def\dotocnum#1{%
358
  \leavevmode 
359
     {\ifnonum \global\advance\nonumnum by1 \edef\thetocnum{!\the\nonumnum}\fi
360
      \wlabel\thetocnum \dest[toc:\thetocnum]%
361
      \dotocnumafter}\ifnonum\else#1\fi
362
  \global\let\dotocnumafter=\relax
363
}
364
\def\resetnonumnotoc{\global\notocfalse \global\nonumfalse
365
  \ifx\dotocnumafter\relax \else
366
    \opwarning{\noexpand\dotocnum unused in printchap/printsec/printsecc}\fi
367
}
368
\def\insertmark#1{\toks0={#1}\mark{{\ifnonum\else\thetocnum\fi} {\the\toks0}}}
369
 
370
\newskip\remskipamount
371
\def\remskip{\afterassignment\remskipA \global\remskipamount}
372
\def\remskipA{\vskip\remskipamount \penalty11333 }
373
\def\norempenalty{\ifnum\lastpenalty=11333 
374
   \vskip-\remskipamount \tmpnum=\else \removelastskip \penalty \fi}
375
 
376
\def\othe#1.{\ifnum#1>0 \the#1.\fi}
377
\def\thechapnum{} \def\thesecnum{} \def\theseccnum{}
378
 
379
\def\afternoindent{\global\everypar={\wipeepar\setbox7=\lastbox}}
380
\def\wipeepar{\global\everypar={}}
381
\let\firstnoindent=\afternoindent
382
\def\nbpar{{\interlinepenalty=10000\par}}
383
\def\nl{\hfil\break}
384
 
385
 
386
%%%%%%%%%%%%%% Captions, equations -- sec. 3.9 in opmac-d.pdf
387
 
388
\newcount\tnum  \newcount\fnum   \newcount\dnum
389
 
390
\def\thetnum{\thesecnum.\the\tnum}
391
\def\thefnum{\thesecnum.\the\fnum}
392
\def\thednum{(\the\dnum)}
393
 
394
\def\caption/#1 {\isdefined{#1num}%
395
   \iftrue \global\advance \csname #1num\endcsname by1
396
   \else   \opwarning{Unknown caption /#1}%
397
   \fi
398
   \bgroup
399
      \leftskip=\iindent plus1fil
400
      \rightskip=\iindent plus-1fil
401
      \parfillskip=0pt plus2fil
402
      \def\par{\endgraf\egroup}%
403
      \captionhook{#1}\noindent 
404
      \wlabel{\csname the#1num\endcsname}%
405
      \printcaption{\mtext{#1}}{\csname the#1num\endcsname}%
406
}
407
\def\printcaption#1#2{{\bf#1 #2}\enspace}
408
 
409
\expandafter\def\expandafter\endinsert\expandafter{\expandafter\par\endinsert}
410
 
411
\def\eqmark{\global\advance\dnum by1
412
  \ifinner\else\eqno \fi 
413
  \wlabel\thednum \thednum
414
}
415
 
416
%%%%%%%%%%%%%% Items -- sec. 3.10 in opmac-d.pdf
417
 
418
\newcount\itemnum  \itemnum=0
419
 
420
\def\begitems{\par\iiskip\bgroup
421
  \itemnum=0 \adef*{\startitem}
422
  \advance\leftskip by\iindent
423
  \let\printitem=\normalitem
424
}
425
\def\enditems{\par\egroup\iiskip}
426
 
427
\def\startitem{\par \advance\itemnum by1
428
   \noindent\llap{\printitem}\ignorespaces}
429
\def\normalitem{$\bullet$\enspace}
430
 
431
\def\style#1{\expandafter\let\expandafter\printitem\csname item:#1\endcsname
432
  \ifx\printitem\relax \let\printitem=\normalitem \fi
433
}
434
\sdef{item:o}{\raise.4ex\hbox{$\scriptscriptstyle\bullet$} }
435
\sdef{item:-}{- }
436
\sdef{item:n}{\the\itemnum. }
437
\sdef{item:N}{\the\itemnum) }
438
\sdef{item:i}{(\romannumeral\itemnum) }
439
\sdef{item:I}{\uppercase\expandafter{\romannumeral\itemnum}\kern.5em}
440
\sdef{item:a}{\athe\itemnum) }
441
\sdef{item:A}{\uppercase\expandafter{\athe\itemnum}) }
442
\sdef{item:x}{\raise.3ex\fullrectangle{.6ex} }
443
\sdef{item:X}{\raise.2ex\fullrectangle{1ex}\kern.5em}
444
 
445
\def\fullrectangle#1{\hbox{\vrule height#1 width#1}}
446
 
447
\def\athe#1{\ifcase#1?\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or l\or 
448
   m\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z\else ?\fi
449
}
450
 
451
%%%%%%%%%%%%%% TOC -- sec. 3.11 in opmac-d.pdf
452
 
453
\def\toclist{} \newif\ifischap \ischapfalse
454
 
455
\def\Xchap#1#2#3{\ischaptrue\addto\toclist{\tocline{0}{\bf}{#1}{#2}{#3}}}
456
\def\Xsec#1#2#3{\addto\toclist{\tocline{1}{\rm}{#1}{#2}{#3}}}
457
\def\Xsecc#1#2#3{\addto\toclist{\tocline{2}{\rm}{#1}{#2}{#3}}}
458
 
459
\def\tocline#1#2#3#4#5{{\leftskip=#1\iindent \rightskip=2\iindent
460
   \ifischap\advance\leftskip by\iindent\fi
461
   \ifnum#1>1 \advance\leftskip by\iindent\fi
462
   \toclinehook \noindent\llap{#2\toclink{#3}\enspace}%
463
         {#2#4\unskip}\nobreak\tocdotfill\pglink{#5}\nobreak\hskip-2\iindent\null\par}}
464
\def\tocdotfill{\leaders\hbox to.8em{\hss.\hss}\hskip 1em plus1fill\relax}
465
 
466
\def\maketoc{\par \ifx\toclist\empty
467
      \opwarning{\noexpand\maketoc -- data unavailable, TeX me again}\openref
468
   \else \toclist \fi}
469
 
470
\def\toclinkA#1{\def\tmp##1!##2\end{\if^##1^\kern.8em \else##1\fi}\tmp#1!\end}
471
 
472
%%%%%%%%%%%%%% Index -- sec. 3.12 on opmac-d.pdf
473
 
474
\def\iindex#1{\openref\wref\Xindex{{#1}{\the\pageno}}}
475
 
476
\def\ii #1 {\leavevmode\def\tmp{#1}\iiA #1,,}
477
 
478
\def\iiA #1,{\if$#1$\else\def\tmpa{#1}%
479
   \ifx\tmpa\iiatsign \expandafter\iiB\tmp,,%
480
   \else\iindex{#1}\fi
481
   \expandafter\iiA\fi}
482
\def\iiatsign{@}
483
 
484
\def\iiB #1,{\if$#1$\else
485
   \iiC#1/\relax
486
   \expandafter\iiB\fi
487
}
488
\def\iiC #1/#2\relax{\if$#2$\else\iindex{#2#1}\fi}
489
 
490
\def\iid #1 {\leavevmode\iindex{#1}#1\futurelet\tmp\iiD}
491
\def\iiD{\ifx\tmp,\else\ifx\tmp.\else\space\fi\fi}
492
 
493
\def\Xindex#1#2{\bgroup \def~{ }%
494
   \isdefined{,#1}\iftrue
495
     \expandafter\firstdata \csname,#1\endcsname \XindexA
496
     \ifnum#2=\tmpa % \ii on the same page
497
     \else
498
        \tmpnum=#2 \advance\tmpnum by-1
499
        \expandafter\seconddata \csname,#1\endcsname \XindexB
500
        \if\tmpb+% state: the pagelist ends by a pagenumber
501
           \ifnum\tmpnum=\tmpa  % the consecutive page
502
              \sxdef{,#1}{{#2/-}{\tmp\iiendash}}
503
           \else                % the pages drop
504
              \sxdef{,#1}{{#2/+}{\tmp, #2}}
505
           \fi
506
        \else    % state: the pagelist ends by --
507
           \ifnum\tmpnum=\tmpa  % the consecutive page
508
              \sxdef{,#1}{{#2/-}{\tmp}}
509
           \else                % the pages drop
510
              \sxdef{,#1}{{#2/+}{\tmp\tmpa, #2}}
511
           \fi
512
        \fi
513
     \fi
514
   \else % first occurrence of the index item #1
515
     \sxdef{,#1}{{#2/+}{#2}}
516
     \global \expandafter\addto \expandafter\iilist \csname,#1\endcsname
517
   \fi
518
   \egroup
519
}
520
\def\iilist{} \def\iiendash{--}
521
 
522
\def\firstdata#1#2{\expandafter\expandafter\expandafter #2\expandafter\firstdataA#1}
523
\def\firstdataA#1#2{#1&}
524
\def\seconddata#1#2{\expandafter\expandafter\expandafter #2\expandafter\seconddataA#1}
525
\def\seconddataA#1#2{#2&}
526
 
527
\def\XindexA#1/#2&{\def\tmpa{#1}\let\tmpb=#2}
528
\def\XindexB#1&{\def\tmp{#1}}
529
 
530
\def\makeindex{\par
531
  \ifx\iilist\empty \opwarning{index data-buffer is empty. TeX me again}
532
    \else
533
    \bgroup
534
      \setprimarysorting
535
      \def\act##1{\ifx##1\relax \else
536
         \firstdata##1\XindexA \seconddata##1\XindexB
537
         \if\tmpb+%
538
            \preparesorting##1% converted item by sorting data in \tmpb
539
            \xdef##1{{\tmpb}{\tmp}}
540
          \else
541
            \preparesorting##1% converted item by sorting data in \tmpb
542
            \xdef##1{{\tmpb}{\tmp\tmpa}}
543
          \fi
544
          \expandafter\act\fi}
545
      \expandafter \act \iilist \relax
546
    \egroup
547
    \dosorting  % sorting is in progress
548
    \iiparparams
549
    \gdef\act##1{\ifx##1\relax \else \prepii##1%
550
             \seconddata##1\printiipages \expandafter\act \fi}
551
      \expandafter \act \iilist \relax
552
    \orippx \global\let\act=\undefined \global\let\orippx=\undefined
553
  \fi
554
}
555
\def\printiipages#1&{ #1\par}
556
 
557
\def\prepii #1{\isinlist \iispeclist #1\iftrue
558
   \expandafter\expandafter\expandafter \printii \csname\string#1\endcsname&%
559
   \else \expandafter\prepiiA\string #1&%
560
   \fi
561
}
562
\def\prepiiA #1#2#3&{\printii#3&}
563
 
564
\def\iis #1 #2{\bgroup \def~{ }%
565
    \global\expandafter\addto\expandafter\iispeclist\csname,#1\endcsname
566
    \global\sdef{\expandafter\string\csname,#1\endcsname}{#2}%
567
  \egroup \ignorespaces
568
}
569
\def\iispeclist{}
570
 
571
\def\printii #1&{\gdef\currii{#1}\noindent\everyii
572
   \hskip-\iindent \ignorespaces\printiiA#1//}
573
\def\printiiA #1/{\if^#1^\let\previi=\currii \else
574
   \expandafter\scanprevii\previi/&\def\tmpb{#1}\edef\tmpb{\meaning\tmpb}%
575
   \ifx\tmpa\tmpb \iiemdash \else#1 \gdef\previi{}\fi
576
   \expandafter\printiiA\fi
577
}
578
\def\iiemdash{\kern.1em---\space}
579
\def\everyii{}
580
 
581
\def\iiparparams{%
582
   \xdef\orippx{\global\rightskip=\the\rightskip
583
               \global\leftskip=\the\leftskip
584
               \global\exhyphenpenalty=\the\exhyphenpenalty}
585
   \global\rightskip=0pt plus1fil
586
   \global\exhyphenpenalty=10000
587
   \global\leftskip=\iindent
588
}
589
 
590
\def\scanprevii#1/#2&{\def\previi{#2}\def\tmpa{#1}\edef\tmpa{\meaning\tmpa}}
591
\def\previi{} % previous index item
592
 
593
 
594
%%%%%%%%%%%%%% Sorting -- sec. 3.13 in opmac-d.pdf
595
 
596
\def\sortingdata{%
597
  /,{ },-,&,@,%
598
  aA\"a\"A\'a\'A,%
599
  bB,%
600
  cC,%
601
  \v c\v C,%
602
  dD\v d\v D,%
603
  eE\'e\'E\v e\v E,%
604
  fF,%
605
  gG,%
606
  h^^HH,%
607
  ^^T^^U^^V,%
608
  iI\'i\'I,%
609
  jJ,%
610
  kK,%
611
  lL\'l\'L\v l\v L,%
612
  mM,%
613
  nN\v n\v N,%
614
  oO\"o\"O\'o\'O\^o\^O,%
615
  pP,%
616
  qQ,%
617
  rR\'r\'R,%
618
  \v r\v R,%
619
  sS,%
620
  \v s\v S,%
621
  tT\v t\v T,%
622
  uU\"u\"U\'u\'U\r u\r U,%
623
  vV,%
624
  wW,%
625
  xX,%
626
  yY,\'y\'Y,%
627
  zZ,%
628
  \v z\v Z,%
629
  0,1,2,3,4,5,6,7,8,9,'.%
630
}
631
\def\setprimarysorting {\csname sort:\csname lan:\the\language\endcsname \endcsname
632
  \def\act##1{\ifx##1.\else
633
     \ifx##1,\advance\tmpnum by1
634
     \else \lccode`##1=\tmpnum \fi
635
     \expandafter \act \fi}%
636
  \ifx\r\undefined 
637
     \opwarning{\noexpand\csaccents is unused, falling back to ASCII sorting}%
638
     \gdef\sortingdata{.}\global\let\chsorting=n%
639
  \else
640
     \xdef\sortingdata{\sortingdata}% expand sorting data now
641
  \fi 
642
  \tmpnum=133 \expandafter \act\sortingdata \setignoredchars
643
}
644
\sdef{sort:en}{\global\let\chsorting=n} % skipping ch processing in English language
645
 
646
\def\setsecondarysorting {\def\act##1{\ifx##1.\else
647
     \ifx##1,\else \advance\tmpnum by1 \lccode`##1=\tmpnum \fi
648
     \expandafter \act \fi}%
649
  \tmpnum=133 \expandafter \act\sortingdata \setignoredchars
650
}
651
\bgroup
652
\lccode`4=`c \lccode`5=`h \lccode`6=`C \lccode`7=`H
653
\lowercase{
654
\gdef\iiscanch #145#2\relax{#1\if$#2$\else^^T\iiscanch #2\relax\fi}
655
\gdef\iiscanCh #165#2\relax{#1\if$#2$\else^^U\iiscanCh #2\relax\fi}
656
\gdef\iiscanCH #167#2\relax{#1\if$#2$\else^^V\iiscanCH #2\relax\fi}
657
\gdef\preparesorting#1{\expandafter\preparesortingA\string#1&}
658
\gdef\preparesortingA#1#2#3&{\xdef\tmpb{#3}%
659
  \ifx\chsorting\undefined 
660
    \xdef\tmpb{\expandafter\iiscanch\tmpb 45\relax}%
661
    \xdef\tmpb{\expandafter\iiscanCh\tmpb 65\relax}%
662
    \xdef\tmpb{\expandafter\iiscanCH\tmpb 67\relax}\fi
663
  \lowercase\expandafter{\expandafter\gdef\expandafter\tmpb\expandafter{\tmpb}}%
664
  \xdef\tmpb{\expandafter\removedot\tmpb.\relax}%
665
}}
666
\egroup
667
 
668
\def\removedot #1.#2\relax{#1\if$#2$\else\removedot #2\relax\fi}
669
\def\setignoredchars{\setlccodes ,.;.?.!.:.'.".|.(.).[.].<.>.=.+.{}{}}
670
 
671
\newif \ifAleB
672
 
673
\def\isAleB #1#2{%
674
  \edef\tmp{\firstdata#1\empty\relax\firstdata#2\empty\relax%
675
            \noexpand#1\noexpand#2}%
676
  \expandafter \testAleB \tmp
677
}
678
\def\testAleB #1#2\relax #3#4\relax #5#6{%
679
  \if #1#3\if #1&\testAleBsecondary #5#6%
680
          \else \testAleB #2\relax #4\relax #5#6%
681
          \fi
682
  \else \ifnum `#1<`#3 \AleBtrue \else \AleBfalse \fi
683
  \fi
684
}
685
\def\testAleBsecondary#1#2{%
686
  \bgroup
687
     \setsecondarysorting
688
     \preparesorting#1\let\tmpa=\tmpb \preparesorting#2%
689
     \edef\tmp{\tmpa0\relax\tmpb1\relax}%
690
     \expandafter\testAleBsecondaryX \tmp
691
  \egroup
692
}
693
\def\testAleBsecondaryX #1#2\relax #3#4\relax {%
694
  \if #1#3\testAleBsecondaryX #2\relax #4\relax
695
  \else \ifnum `#1<`#3 \global\AleBtrue \else \global \AleBfalse \fi
696
  \fi
697
}
698
\def\dosorting{%
699
   \message{Opmac: Sorting index...}
700
   \def\act##1{\ifx##1\relax\else \global\addto\iilist{##1,}%
701
             \expandafter\act\fi}
702
   \expandafter\removeiilist \expandafter\act \iilist\relax
703
   \expandafter\removeiilist \expandafter\mergesort \iilist \end,\end
704
}
705
\def\removeiilist{\gdef\iilist{}}
706
 
707
\def\mergesort #1#2,#3{% by Miroslav Olsak
708
   \ifx,#1                       % prazdna-skupina,neco,  (#2=neco #3=pokracovani)
709
      \addto\iilist{#2,}         % dvojice skupin vyresena
710
      \return{\fif\mergesort#3}%    % \mergesort pokracovani
711
   \fi
712
   \ifx,#3                       % neco,prazna-skupina,  (#1#2=neco #3=,)
713
      \addto\iilist{#1#2,}%      % dvojice skupin vyresena
714
      \return{\fif\mergesort}%      % \mergesort dalsi
715
   \fi
716
   \ifx\end#3                    % neco,konec (#1#2=neco)
717
      \ifx\empty\iilist                % neco=kompletni setrideny seznam
718
         \def\iilist{#1#2}%
719
         \return{\fif\fif\gobbletoend}%   % koncim
720
      \else                      % neco=posledni skupina nebo \end
721
         \return{\fif\fif \expandafter\removeiilist    % spojim \indexbuffer+necoa cele znova
722
                \expandafter\mergesort\iilist#1#2,#3}%
723
   \fi\fi                      % zatriduji: p1+neco1,p2+neco2, (#1#2=p1+neco1 #3=p2)
724
   \isAleB #1#3\ifAleB         % p1<p2
725
      \addto\iilist{#1}%       % p1 do bufferu
726
      \return{\fif\mergesort#2,#3}%         % \mergesort neco1,p2+neco2,
727
   \else                       % p1>p2
728
      \addto\iilist{#3}%       % p2 do bufferu
729
      \return{\fif\mergesort#1#2,}%         % \mergesort p1+neco1,neco2,
730
   \fi
731
   \relax % zarazka, na ktere se zastavi \return
732
}
733
\def\return#1#2\fi\relax{#1} \def\fif{\fi}
734
\def\gobbletoend #1\end{}
735
 
736
 
737
%%%%%%%%%%%%%% \begmulti ... \endmulti TBN p. 244, 245 -- sec. 3.14 in opmac-d.pdf
738
 
739
\def\corrsize #1{%% #1 := #1 + \splittopskip - \topskip
740
   \advance #1 by \splittopskip \advance #1 by-\topskip}
741
 
742
\def\begmulti #1 {\par\wipeepar\multiskip\penalty0 \def\Ncols{#1}
743
   \splittopskip=\baselineskip
744
   \setbox6=\vbox\bgroup\penalty0
745
   %% \hsize := Sirka sloupce = (\hsize+\colsep) / n - \colsep
746
   \advance\hsize by\colsep
747
   \divide\hsize by\Ncols  \advance\hsize by-\colsep
748
   \dimen0=0pt
749
   \def\par{\endgraf\advance\dimen0 by\the\prevgraf\baselineskip
750
            \ifdim\dimen0>.9\maxdimen \message{flushcolumns:}%
751
               \global\let\balancecolumns=\flushcolumns \expandafter \endmulti
752
            \fi}%
753
}
754
\def\endmulti{\vskip-\prevdepth\vfil\egroup \setbox1=\vsplit6 to0pt
755
   %% \dimen1 := the free space on the page
756
   \ifdim\pagegoal=\maxdimen \dimen1=\vsize \corrsize{\dimen1}
757
   \else \dimen1=\pagegoal \advance\dimen1 by-\pagetotal \fi
758
   \ifdim \dimen1<2\baselineskip
759
     \vfil\break \dimen1=\vsize \corrsize{\dimen1} \fi
760
   \dimen0=\ht6 \divide\dimen0 by\Ncols \relax
761
   %% split the material to more pages?
762
   \ifdim \dimen0>\dimen1 \splitpart
763
   \else \balancecolumns \fi  % only balancing
764
   \multiskip\relax}
765
\def\makecolumns{\bgroup % full page, destination height: \dimen1
766
   \vbadness=20000 \setbox1=\hbox{}\tmpnum=0
767
   \loop \ifnum\Ncols>\tmpnum
768
      \advance\tmpnum by1
769
      \setbox1=\hbox{\unhbox1 \vsplit6 to\dimen1 \hss}
770
   \repeat
771
   \hbox{}\nobreak\vskip-\splittopskip \nointerlineskip
772
   \line{\unhbox1\unskip}
773
   \egroup}
774
\def\splitpart{%
775
   \makecolumns % full page
776
   \vskip 0pt plus 1fil minus\baselineskip \break
777
   \dimen0=\ht6 \divide\dimen0 by\Ncols \relax
778
   \dimen1=\vsize \corrsize{\dimen1}\dimen2=\dimen1
779
   \advance\dimen2 by-\Ncols\baselineskip
780
   %% split the material to more pages?
781
   \ifvoid6 \else
782
      \ifdim \dimen0>\dimen2 \expandafter\expandafter\expandafter \splitpart
783
      \else \balancecolumns % last balancing
784
   \fi \fi
785
}
786
 
787
\def\balancecolumns{\bgroup \setbox7=\copy6 % destination height: \dimen0
788
   \ifdim\dimen0>\baselineskip \else \dimen0=\baselineskip \fi
789
   \vbadness=20000
790
   \def\tmp{%
791
      \setbox1=\hbox{}\tmpnum=0
792
      \loop \ifnum\Ncols>\tmpnum
793
         \advance\tmpnum by1
794
         \setbox1=\hbox{\unhbox1
795
              \ifvoid6 \hbox to\wd6{\hss}\else \vsplit6 to\dimen0 \fi\hss}
796
      \repeat
797
   \ifvoid6 \else
798
      \advance \dimen0 by.2\baselineskip
799
      \setbox6=\copy7
800
      \expandafter \tmp \fi}\tmp
801
   \hbox{}\nobreak\vskip-\splittopskip \nointerlineskip
802
   \hbox to\hsize{\unhbox1\unskip}%
803
   \egroup
804
}
805
\def\flushcolumns#1\relax{\fi\fi\fi
806
   \setbox6=\vbox\bgroup\penalty0
807
   \global\let\balancecolumns=\ibalancecolumns
808
   \dimen0=\ht6 \unvbox6 \unskip\unskip
809
   \advance\hsize by\colsep
810
   \divide\hsize by\Ncols  \advance\hsize by-\colsep
811
   \def\par{\endgraf\advance\dimen0 by\the\prevgraf\baselineskip
812
            \ifdim\dimen0>.9\maxdimen \message{flush-columns:}%
813
               \global\let\balancecolumns=\flushcolumns \expandafter \endmulti
814
            \fi}%
815
}
816
\let\ibalancecolumns=\balancecolumns
817
 
818
%%%%%%%%%%%%%% Colors -- sec. 3.15 in opmac-d.pdf
819
 
820
\newif\ifwritecolor \writecolortrue
821
\newcount\lastpage  \lastpage=0  % the last page of the document
822
 
823
\def\Blue{\setcmykcolor{1 1 0 0}}
824
\def\Red{\setcmykcolor{0 1 1 0}}
825
\def\Brown{\setcmykcolor{0 0.67 0.67 0.5}}
826
\def\Green{\setcmykcolor{1 0 1 0}}
827
\def\Yellow{\setcmykcolor{0 0 1 0}}
828
\def\Cyan{\setcmykcolor{1 0 0 0}}
829
\def\Magenta{\setcmykcolor{0 1 0 0}}
830
\def\White{\setcmykcolor{0 0 0 0}}
831
\def\Grey{\setcmykcolor{0 0 0 0.5}}
832
\def\LightGrey{\setcmykcolor{0 0 0 0.2}}
833
\def\Black{\setcmykcolor{0 0 0 1}}
834
 
835
\def\setcmykcolor#1{{%
836
   \def\tmp{#1}\expandafter \ifx\csname currcolor\pdfK\endcsname \tmp \else
837
      \pdfliteral{#1 \pdfK}%
838
      \expandafter\xdef\csname currcolor\pdfK\endcsname{#1}%
839
      \writecolor\pdfK
840
   \fi}%
841
}
842
\def\writecolor#1{\ifwritecolor
843
      \openref 
844
      \edef\act{\noexpand\wref\noexpand\Xpdfcolor{#1{\csname currcolor#1\endcsname}}}\act
845
   \fi
846
}
847
\def\pdfK{k}
848
\def\linecolor#1{{\def\pdfK{K}#1}}
849
 
850
\def\pdfblackcolor{0 0 0 1}
851
\xdef\currcolork{\pdfblackcolor} \xdef\currcolorK{\pdfblackcolor}
852
 
853
\xdef\savedcolors{}
854
 
855
\def\localcolor{\aftergroup\restorecolor \writecolorfalse 
856
   \xdef\savedcolors{0{\currcolork}{\currcolorK}\savedcolors}}
857
\def\longlocalcolor{\aftergroup\restorecolor 
858
   \ifwritecolor\else \opwarning{\noexpand\longlocalcolor inside
859
      \string\localcolor. Something wrong}\fi
860
   \writecolortrue
861
   \xdef\savedcolors{1{\currcolork}{\currcolorK}\savedcolors}}
862
\let\locpgcolor=\relax  % for backward compatibility
863
 
864
\def\restorecolor{{\def\tmp##1##2##3##4\end{\xdef\savedcolors{##4}%
865
   \def\tmpa{##2}\def\tmpb{##3}\writecolortrue
866
      \ifx\tmpa\empty\else \ifx\tmpa\currcolork\else \pdfliteral{##2 k}\xdef\currcolork{##2}%
867
         \ifnum##1=1 \writecolor k\fi\fi\fi
868
      \ifx\tmpb\empty\else \ifx\tmpb\currcolorK\else \pdfliteral{##3 K}\xdef\currcolorK{##3}%
869
         \ifnum##1=1 \writecolor K\fi\fi\fi}%
870
   \expandafter\tmp\savedcolors\end}}
871
 
872
\addprotect\setcmykcolor  \addprotect\localcolor  \addprotect\longlocalcolor
873
 
874
\def\begoutput{\writecolorfalse  \let\longlocalcolor=\localcolor
875
   \edef\restoreoutputcolor{%
876
      \xdef\noexpand\currcolork{\currcolork}\xdef\noexpand\currcolorK{\currcolorK}}%
877
   \xdef\currcolork{\pdfblackcolor}\xdef\currcolorK{\pdfblackcolor}%
878
   \immediate\wref\Xpage{{\the\pageno}}%
879
}
880
\def\endoutput{\restoreoutputcolor}
881
 
882
\def\Xpdfcolork#1{\def\pdflastcolork{#1}}
883
\def\XpdfcolorK#1{\def\pdflastcolorK{#1}}
884
\let\pdflastcolork=\pdfblackcolor \let\pdflastcolorK=\pdfblackcolor
885
 
886
\def\Xpage#1{\ifnum\lastpage=#1 \else \lastpage=#1 \fnotenumlocal=0
887
   \ifx\pdflastcolork\pdfblackcolor\else
888
      \isdefined{pgc:#1}\iftrue \else \sxdef{pgc:#1}{}\fi
889
      {\let\setpgcolor=\relax \sxdef{pgc:#1}%
890
            {\csname pgc:#1\endcsname\setpgcolor k{\pdflastcolork}}}\fi
891
   \ifx\pdflastcolorK\pdfblackcolor\else
892
      \isdefined{pgc:#1}\iftrue \else \sxdef{pgc:#1}{}\fi
893
      {\let\setpgcolor=\relax \sxdef{pgc:#1}%
894
            {\csname pgc:#1\endcsname\setpgcolor K{\pdflastcolorK}}}\fi\fi
895
}
896
\def\setpgcolor#1#2{\pdfliteral{#2 #1}}
897
 
898
\def\preboxcclv{\csname pgc:\the\pageno\endcsname}
899
\def\postboxcclv{{%
900
   \def\setpgcolor##1##2{\expandafter\xdef\csname currcolor##1\endcsname{##2}}%
901
   \ifnum\pageno<\lastpage 
902
         \globaldefs=-1 \advancepageno \globaldefs=0 \csname pgc:\the\pageno\endcsname
903
   \else \xdef\currcolork{\pdflastcolork}\xdef\currcolorK{\pdflastcolorK}\fi
904
   \let\longlocalcolor=\relax \let\localcolor=\relax \Black \linecolor\Black
905
}}
906
 
907
\ifpdftex\else
908
  \def\setcmykcolor#1{}      \def\pdfliteral#1{}
909
  \let\localcolor=\relax     \let\longlocalcolor=\relax
910
\fi
911
 
912
\def\draft{\edef\tmp{\headline={\noexpand\draftbox{\tenbf DRAFT}\the\headline}}\tmp}
913
 
914
\def\draftbox#1{\vbox to0pt{\setbox0=\hbox{\typosize[10/]#1}%
915
   \kern.5\vsize \kern4\wd0 \hbox to0pt{\kern.5\hsize \kern-2.5\wd0
916
   \pdfsave \pdfrotate{55}\pdfscale{10}{10}%
917
   \hbox to0pt{\localcolor\LightGrey \box0\hss}%
918
   \pdfrestore
919
\hss}\vss}\hss}
920
 
921
\ifpdftex\else
922
   \def\draft{\opwarning{\string\draft: Grey color is possible in pdfTeX only}}
923
\fi
924
 
925
 
926
%%%%%%%%%%%%%% Hyperrefs -- sec. 3.16 in opmac-d.pdf
927
 
928
\def\destheight{1.4em}
929
\def\destactive[#1:#2]{\if$#2$\else\ifvmode
930
      \tmpdim=\prevdepth \prevdepth=-1000pt
931
      \destbox[#1:#2]\prevdepth=\tmpdim
932
   \else \destbox[#1:#2]%
933
   \fi\fi
934
}
935
\def\destbox[#1]{\vbox to0pt{\kern-\destheight \pdfdest name{#1} xyz\vss}}
936
\def\dest[#1]{}
937
 
938
\def\link[#1:#2]#3#4{\leavevmode\pdfstartlink height.9em depth.3em
939
      \pdfborder{#1} goto name{#1:#2}\relax {#3#4}\pdfendlink
940
}
941
\def\urllink[#1:#2]#3{{\let~=\relax \let\\=\relax \let\{=\relax \let\}=\relax
942
   \leavevmode\pdfstartlink height.9em depth.3em
943
   \pdfborder{#1}user{/Subtype/Link/A <</Type/Action/S/URI/URI(#2)>>}\relax
944
   {\def~{\nobreak\space}\urlcolor#3}\pdfendlink}%
945
}
946
\def\toclink#1{\toclinkA{#1}}
947
\def\pglink#1{#1}
948
\def\citelink#1#2{#2}
949
\def\reflink[#1]#2{#2}
950
\def\ulink[#1]#2{{#2}}
951
\def\urlcolor{}
952
 
953
\def\hyperlinks#1#2{%
954
   \let\dest=\destactive
955
   \def\toclink##1{\link[toc:##1]{\localcolor#1}{\toclinkA{##1}}}%
956
   \def\pglink##1{\link[pg:##1]{\localcolor#1}{##1}}%
957
   \def\citelink##1##2{\link[cite:##1]{\localcolor#1}{##2}}%
958
   \def\reflink[##1]##2{\link[ref:##1]{\localcolor#1}{##2}}%
959
   \def\ulink[##1]##2{\urllink[url:##1]{##2}}%
960
   \def\urlcolor{\longlocalcolor#2}%
961
}
962
 
963
\def\pdfborder#1{\if^#1^\else \isdefined{#1border}\iftrue
964
   \if^\csname#1border\endcsname^\else attr{/C[\csname#1border\endcsname] /Border[0 0 .6]}%
965
   \fi\fi\fi
966
}
967
 
968
\ifpdftex \else
969
  \def\link[#1]#2#3{#3}
970
  \def\urllink[#1]#2{#2}
971
  \def\hyperlinks#1#2{}
972
\fi
973
 
974
\def\url#1{{\def\tmpb{#1}%
975
   \replacestrings{//}{{\urlskip\urlslashslash\urlbskip}}%
976
   \replacestrings{/}{{\urlskip/\urlbskip}}%
977
   \replacestrings{.}{{\urlskip.\urlbskip}}%
978
   \replacestrings{?}{{\urlskip?\urlbskip}}%
979
   \replacestrings{=}{{\urlskip=\urlbskip}}%
980
   \replacestrings{~}{{\char`\~}}%
981
   \replacestrings{_}{{\char`\_}}%
982
   \replacestrings{^}{{\char`\^}}%
983
   \replacestrings{\\}{\bslash}%
984
   \replacestrings{\{}{{\char`\{}}%
985
   \replacestrings{\}}{{\char`\}}}%
986
   \replacestrings{&}{{\urlbskip\char`\& \urlskip}}%
987
   \def\|{}\ulink[#1]{\urlfont\tmpb}%
988
}}
989
\def\urlfont{\tt \hyphenchar\the\font=-1 \let\|=\urlspecchar}
990
\def\urlspecchar{\penalty10 }
991
\def\urlskip{\null\nobreak\hskip0pt plus0.05em\relax}
992
\def\urlbskip{\penalty100 \hskip0pt plus0.05em\relax}
993
\def\urlslashslash{/\urlskip/}
994
\addprotect\url
995
 
996
\def\replacestrings#1#2{%
997
   \def\tmp##1#1##2\relax{\if$##2$\addto\tmpb{##1}\else\addto\tmpb{##1#2}\tmp##2\relax\fi}%
998
   \expandafter\def\expandafter\tmpb\expandafter{\expandafter}%
999
   \expandafter\tmp\tmpb\/#1\relax
1000
   \def\tmp##1\/{\def\tmpb{##1}}\expandafter\tmp\tmpb
1001
}
1002
 
1003
 
1004
%%%%%%%%%%%%%% Outlines -- sec. 3.17 in opmac-d.pdf
1005
 
1006
\def\outlines#1{\pdfcatalog{/PageMode/UseOutlines}\openref\ifx\toclist\empty
1007
     \opwarning{\noexpand\outlines -- data unavailable. TeX me again}%
1008
   \else
1009
     {\let\tocline=\outlinesA
1010
      \count0=0 \count1=0 \toclist % calculate numbers o childs
1011
      \def\outlinelevel{#1}\let\tocline=\outlinesB
1012
      \count0=0 \count1=0 \toclist}% create outlines
1013
   \fi
1014
}
1015
\def\outlinesA#1#2#3#4#5{%
1016
   \advance\count#1 by1
1017
   \ifcase#1\or
1018
     \addoneol{ol:\the\count0}\or
1019
     \addoneol{ol:\the\count0:\the\count1}\fi
1020
}
1021
\def\addoneol#1{\isdefined{#1}%
1022
   \iftrue \tmpnum=\csname#1\endcsname\relax
1023
           \advance\tmpnum by1 \sxdef{#1}{\the\tmpnum}%
1024
   \else \sxdef{#1}{1}%
1025
   \fi
1026
}
1027
\def\outlinesB#1#2#3#4#5{%
1028
   \advance\count#1 by1
1029
   \ifcase#1\tmpnum=\isdefined{ol:\the\count0}%
1030
               \iftrue\csname ol:\the\count0\endcsname\else0\fi \or
1031
            \tmpnum=\isdefined{ol:\the\count0:\the\count1}%
1032
               \iftrue\csname ol:\the\count0:\the\count1\endcsname\else0\fi \or
1033
            \tmpnum = 0 \fi
1034
  \protectlist \def~{ }\setcnvcodesA 
1035
  \expandafter \setlccodes \toasciidata{}{}%
1036
  \cnvhook \lowercase{\gdef\tmp{#4}}%
1037
  \pdfoutline goto name{toc:#3} count
1038
     \ifnum#1<\outlinelevel\space\else-\fi\tmpnum {\tmp}\relax
1039
}
1040
\def\setcnvcodesA{\global\let\setcnvcodesA=\relax % I am working only once
1041
  \ifx\r\undefined
1042
     \gdef\toasciidata{}
1043
     \opwarning{\noexpand\csaccents unused, CZ/SK outline-conversion is off}%
1044
  \else
1045
     \xdef\toasciidata{\toasciidata}%
1046
  \fi
1047
}
1048
\def\toasciidata{%  Removes Czech+Slovak accents
1049
       AA\'AA\"AA\'aa\"aaBBCC\v CC\v ccDD\v DD\v ddEE\'EE\v EE\'ee\v ee%
1050
       FFGGHHII\'II\'iiJJKKLL\'LL\v LL\'ll\v llMMNN\v NN\v nnOO\'OO\"OO\^OO%
1051
       \'oo\"oo\^ooPPQQRR\v RR\v rrSS\v SS\v ssTT\v TT\v ttUU\'UU\"UU\r UU%
1052
       \'uu\"uu\r  uuVVWWXXYY\'YY\'yyZZ\v ZZ\v zz%
1053
}
1054
\def\setlccodes#1#2{\if\relax#2\relax \else \lccode`#1=`#2 \expandafter \setlccodes \fi}
1055
 
1056
\newcount\oulnum
1057
\def\insertoutline#1{\global\advance\oulnum by1
1058
   \pdfdest name{oul:\the\oulnum} xyz\relax
1059
   \pdfoutline goto name{oul:\the\oulnum} count0 {#1}\relax
1060
}
1061
 
1062
\ifpdftex \else
1063
  \def\outlines#1{\opwarning{DVI output has no outlines}\gdef\outlines##1{}}
1064
  \let\insertoutline=\outlines
1065
\fi
1066
 
1067
 
1068
%%%%%%%%%%%%%% Verbatim, \begtt, \endtt -- sec. 3.18 in opmac-d.pdf
1069
 
1070
\newcount\ttline    \ttline=-1
1071
\newcount\viline
1072
\newread\vifile
1073
 
1074
\def\setverb{\frenchspacing\def\do##1{\catcode`##1=12}\dospecials \catcode`\*=12 }
1075
\def\begtt{\par\ttskip\bgroup \wipeepar
1076
   \setverb \adef{ }{ }%
1077
   \ifx\savedttchar\undefined \else \catcode\savedttchar=12 \fi
1078
   \parindent=\ttindent
1079
   \tthook\relax
1080
   \ifnum\ttline<0 \else
1081
     \tenrm \thefontscale[700]\let\sevenrm=\thefont
1082
     \everypar={\global\advance\ttline by1
1083
                \llap{\sevenrm\the\ttline\kern.9em}}\fi
1084
   \def\par##1{\endgraf\ifx##1\egroup\else\penalty\ttpenalty\leavevmode\fi ##1}
1085
   \obeylines \startverb}
1086
{\catcode`\|=0 \catcode`\\=12
1087
|gdef|startverb#1\endtt{|tt#1|egroup|par|ttskip|testparA}}
1088
\def\testparA{\afterassignment\testparB\let\tmpa= }
1089
\def\testparB{\futurelet\tmpa\testparC}
1090
\def\testparC{\ifx\tmpa\par\else\afternoindent\fi}
1091
 
1092
\def\activettchar#1{%
1093
   \ifx\savedttchar\undefined\else \catcode\savedttchar=\savedttcharc \fi
1094
   \chardef\savedttchar=`#1%
1095
   \chardef\savedttcharc=\catcode`#1%
1096
   \bgroup\lccode`\~=`#1%
1097
   \lowercase {\egroup\def~}{\leavevmode\hbox\bgroup\setverb\adef{ }{ }%
1098
                      \intthook\tt\readverb}%
1099
   \bgroup\lccode`\~=`#1\lowercase{\egroup\def\readverb ##1~}{##1\egroup}%
1100
   \catcode`#1=13
1101
}
1102
 
1103
\def\verbinput (#1) #2 {\par \def\tmpa{#2}%
1104
   \ifx\vifilename\tmpa \else
1105
      \openin\vifile=#2
1106
      \global\viline=0 \global\let\vifilename=\tmpa
1107
      \ifeof\vifile
1108
         \opwarning{\noexpand\verbinput - file "#2" is unable to reading}
1109
         \expandafter\expandafter\expandafter\skiptorelax
1110
      \fi
1111
   \fi
1112
   \viscanparameter #1+\relax
1113
}
1114
\def\skiptorelax#1\relax{}
1115
 
1116
\def \viscanparameter #1+#2\relax{%
1117
   \if$#2$\viscanminus(#1)\else \viscanplus(#1+#2)\fi
1118
}
1119
\def\viscanplus(#1+#2+){%
1120
   \if$#1$\tmpnum=\viline
1121
   \else \ifnum#1<0 \tmpnum=\viline \advance\tmpnum by-#1
1122
       \else \tmpnum=#1
1123
             \advance\tmpnum by-1
1124
             \ifnum\tmpnum<0 \tmpnum=0 \fi % (0+13) = (1+13)
1125
   \fi \fi
1126
   \edef\vinolines{\the\tmpnum}%
1127
   \if$#2$\def\vidolines{0}\else\edef\vidolines{#2}\fi
1128
   \doverbinput
1129
}
1130
\def\viscanminus(#1-#2){%
1131
   \if$#1$\tmpnum=0
1132
      \else \tmpnum=#1 \advance\tmpnum by-1 \fi
1133
   \ifnum\tmpnum<0 \tmpnum=0 \fi  % (0-13) = (1-13)
1134
   \edef\vinolines{\the\tmpnum}%
1135
   \if$#2$\tmpnum=0
1136
      \else \tmpnum=#2 \advance\tmpnum by-\vinolines \fi
1137
   \edef\vidolines{\the\tmpnum}%
1138
   \doverbinput
1139
}
1140
\def\doverbinput{%
1141
   \tmpnum=\vinolines
1142
   \advance\tmpnum by-\viline
1143
   \ifnum\tmpnum<0
1144
      \openin\vifile=\vifilename\space
1145
      \global\viline=0
1146
   \else
1147
      \edef\vinolines{\the\tmpnum}%
1148
   \fi
1149
   \par\ttskip\bgroup \wipeepar
1150
   \setverb \adef{ }{ }%
1151
   \ifx\savedttchar\undefined \else \catcode\savedttchar=12 \fi
1152
   \parindent=\ttindent
1153
   \tthook\relax
1154
   \ifnum\ttline<-1 \else
1155
      \tenrm \thefontscale[700]\let\sevenrm=\thefont \fi
1156
   \tmpnum=0 \tt
1157
   \loop \ifeof\vifile \tmpnum=\vinolines\space \fi
1158
         \ifnum\tmpnum<\vinolines\space
1159
         \vireadline \advance\tmpnum by1 \repeat      %% skip line
1160
   \tmpnum=0 \ifnum\vidolines=0 \tmpnum=-1 \fi
1161
   \ifeof\vifile \tmpnum=\vidolines\space \fi
1162
   \loop \ifnum\tmpnum<\vidolines\space
1163
            \vireadline 
1164
            \ifeof\vifile \tmpnum=\vidolines\space \else
1165
               \penalty\ttpenalty \viprintline \fi  %% print line
1166
            \ifnum\vidolines=0 \else\advance\tmpnum by1 \fi 
1167
            \repeat
1168
   \egroup\par\ttskip\testparB
1169
}
1170
\def\vireadline{\read\vifile to \tmp \global\advance\viline by1 }
1171
\def\viprintline{\indent
1172
   \ifnum \ttline<-1 \else
1173
      \llap{\sevenrm\ifnum\ttline<0 \the\viline \else
1174
               \global\advance\ttline by1 \the\ttline \fi \kern.9em}%
1175
   \fi
1176
   \tmp\par % print the line from \tmp
1177
}
1178
 
1179
 
1180
%%%%%%%%%%%%%% \table -- sec. 3.19 in opmac-d.pdf
1181
 
1182
\newtoks\tabdata
1183
\def\tabstrutA{\tabstrut}
1184
\newcount\colnum  \colnum=0
1185
\def\ddlinedata{}
1186
\def\vvleft{}
1187
 
1188
\def\table{\vbox\bgroup \catcode`\|=12 \tableA}
1189
\def\tableA#1#2{\offinterlineskip \def\tmpa{}\tabdata={}\scantabdata#1\relax
1190
   \halign\expandafter{\the\tabdata\tabstrutA\cr#2\crcr}\egroup}
1191
 
1192
\def\scantabdata#1{\let\next=\scantabdata
1193
   \ifx\relax#1\let\next=\relax
1194
   \else\ifx|#1\addtabvrule
1195
   \else\expandafter\ifx\csname tabdeclare#1\endcsname \relax
1196
     \opwarning{tab-declare letter #1 unknown, ignored}%
1197
        \else\expandafter \addtabitem\expandafter{\csname tabdeclare#1\endcsname}%
1198
   \fi\fi\fi \next
1199
}
1200
\def\tabdeclarec{\tabiteml\hfil##\unsskip\hfil\tabitemr}
1201
\def\tabdeclarel{\tabiteml##\unsskip\hfil\tabitemr}
1202
\def\tabdeclarer{\tabiteml\hfil##\unsskip\tabitemr}
1203
 
1204
\def\unsskip{\ifdim\lastskip>0pt \unskip\fi}
1205
\def\addtabitem#1{\ifnum\colnum>0 \addtabdata{&}\addto\ddlinedata{&\dditem}\fi
1206
    \advance\colnum by1 \let\tmpa=\relax \expandafter\addtabdata\expandafter{#1}}
1207
\def\addtabdata#1{\expandafter\tabdata\expandafter{\the\tabdata#1}}
1208
\def\addtabvrule{\ifx\tmpa\vrule \addtabdata{\kern\vvkern}%
1209
    \ifnum\colnum=0\def\vvleft{\vvitem}\else\addto\ddlinedata{\vvitem}\fi\fi
1210
    \let\tmpa=\vrule \addtabdata{\vrule}}
1211
 
1212
\def\crl{\crcr\noalign{\hrule}}
1213
\def\crll{\crcr\noalign{\hrule\kern\hhkern\hrule}}
1214
 
1215
\def\crli{\crcr \omit \gdef\dditem{\omit\tablinefil}\gdef\vvitem{\tabvvline}%
1216
   \vvleft\tablinefil\ddlinedata\cr}
1217
\def\crlli{\crli\noalign{\kern\hhkern}\crli}
1218
\def\tablinefil{\leaders\hrule\hfil}
1219
\def\tabvvline{\vrule\kern\vvkern\vrule}
1220
 
1221
\def\tskip{\afterassignment\tskipA \tmpdim}
1222
\def\tskipA{\gdef\dditem{}\gdef\vvitem{}\gdef\tabstrutA{}%
1223
    \vrule height\tmpdim width0pt \ddlinedata\cr
1224
    \gdef\tabstrutA{\tabstrut}}
1225
 
1226
\let\orihrule=\hrule  \let\orivrule=\vrule
1227
\def\rulewidth{\afterassignment\rulewidthA \tmpdim}
1228
\def\rulewidthA{\edef\hrule{\orihrule height\the\tmpdim}%
1229
                \edef\vrule{\orivrule width\the\tmpdim}}
1230
 
1231
\long\def\frame#1{\setbox0=\hbox{{#1}}\setbox1=\vbox{\hrule}%
1232
   \tmpdim=\dp0 \advance\tmpdim by\ht1 \advance\tmpdim by\hhkern
1233
   \vbox{\hrule\hbox{\vrule\kern\vvkern
1234
         \vbox{\kern\hhkern\box0\kern\hhkern}\kern\vvkern\vrule}%
1235
         \hrule\kern-\tmpdim\hbox{\vrule depth\tmpdim width0pt}}}
1236
 
1237
 
1238
%%%%%%%%%%%%%% \inspic -- sec. 3.20 in opmac-d.pdf
1239
 
1240
\newdimen\picwidth    \picwidth=0pt   \let\picw=\picwidth
1241
\newdimen\picheight   \picheight=0pt
1242
 
1243
\ifpdftex
1244
  \def\inspic #1 {\hbox{%
1245
      \pdfximage \ifdim\picwidth=0pt \else width\picwidth\fi 
1246
                 \ifdim\picheight=0pt \else height\picheight\fi {\picdir#1}%
1247
      \pdfrefximage\pdflastximage}}
1248
\else
1249
  \def\inspic #1 {\opwarning
1250
     {The \noexpand\inspic is supported for PDF output only}}
1251
\fi
1252
 
1253
%%%%%%%%%%%%%%% transformation matrix -- sec. 3.21 in opmac-d.pdf
1254
 
1255
\def\pdfscale#1#2{\pdfsetmatrix{#1 0 0 #2}}
1256
 
1257
\def\pdfrotate#1{\tmpdim=#1pt
1258
   \ifdim\tmpdim=0pt
1259
   \else \ifdim\tmpdim=90pt \pdfsetmatrix{0 1 -1 0}%
1260
         \else \edef\tmp{#1}\expandafter\pdfrotateA\tmp..\relax
1261
   \fi   \fi
1262
}
1263
\def\pdfrotateA #1.#2.#3\relax{%
1264
   \def\tmp##1.##2\relax {##1}%
1265
   \tmpnum=\expandafter \tmp \the\tmpdim \relax % round
1266
   \ifdim\tmpdim>0pt \def\tmpa{}\else\def\tmpa{-}\fi % save -
1267
   \loop \ifnum\tmpnum<0 \advance\tmpnum by360 \repeat
1268
   \loop \ifnum\tmpnum>360 \advance\tmpnum by-360 \repeat
1269
   \loop \ifnum\tmpnum>90 \pdfrotate{90}\advance\tmpnum by-90 \repeat
1270
   \ifnum\tmpnum=90 \pdfrotate{90}\else
1271
      \ifnum\tmpnum>44 \pdfsetmatrix{.7071 .7071 -.7071 .7071}%
1272
                       \advance\tmpnum by-45 \fi
1273
      \ifnum\tmpnum>22 \pdfsetmatrix{.9272 .3746 -.3746 .9272}%
1274
                       \advance\tmpnum by-22 \fi
1275
      \ifnum\tmpnum>0
1276
         \pdfsetmatrix{\smallcos \smallsin -\smallsin \smallcos}%
1277
   \fi\fi
1278
   \if$#2$\else % fraction part
1279
      \tmpdim=.01745329pt % \pi/180
1280
      \tmpdim=.#2\tmpdim  %
1281
      \edef\tmp{\expandafter\ignorept\the\tmpdim\space}%
1282
      \ifx\tmpa\empty \pdfsetmatrix{1 \tmp -\tmp 1}%
1283
      \else           \pdfsetmatrix{1 -\tmp \tmp 1}%
1284
   \fi\fi
1285
}
1286
\def\smallcos{.\ifcase\tmpnum \or9998\or9994\or9986\or9976\or9962\or9945\or
1287
  9925\or9903\or9877\or9848\or9816\or9781\or9744\or9703\or9659\or9613\or
1288
  9563\or9511\or9455\or9397\or9336\or9272\fi\space}
1289
\def\smallsin{.\ifcase\tmpnum 0\or0175\or0359\or0523\or0698\or0872\or1045\or
1290
  1219\or1391\or1564\or1736\or1908\or2079\or2250\or2419\or2588\or2756\or
1291
  2924\or309\or3256\or342\or3584\or3746\fi\space}
1292
 
1293
\ifpdftex \else
1294
  \def\pdfsetmatrix#1{} \def\pdfsave{} \def\pdfrestore{}
1295
\fi
1296
 
1297
 
1298
%%%%%%%%%%%%%% \fnote, \mnote -- sec 3.22 in opmac-d.pdf
1299
 
1300
\newcount\fnotenum \fnotenum=0
1301
\newcount\fnotenumlocal
1302
\newif\iflocfnum \locfnumtrue
1303
 
1304
\def\fnote#1{\global\advance \fnotenum by1
1305
   \iflocfnum \leavevmode\openref\wref\Xfnote{}%
1306
      \isdefined{fn:\the\fnotenum}\iftrue
1307
      \else\opwarning{unknown \noexpand\fnote mark. TeX me again}\fi\fi
1308
   \fnmarkx{\fnotehook\typobase\typoscale[800/800]\vfootnote\fnmarkx{#1}}%
1309
}
1310
\def\fnotemark#1{{\advance\fnotenum by#1\relax
1311
   \isdefined{fn:\the\fnotenum}\iftrue\thefnote
1312
   \else$^?$\opwarning{unknown \string\fnotemark. TeX me again}\fi}%
1313
}
1314
\def\fnotetext#1{\global\advance \fnotenum by1 \openref\wref\Xfnote{}%
1315
   {\typoscale[800/800]\vfootnote\fnmarkx{#1}}%
1316
}
1317
\def\fnmarkx{\isdefined{fn:\the\fnotenum}\iftrue\thefnote\else$^?$\fi}
1318
\def\thefnote{$^{\locfnum}$)}
1319
\def\locfnum{\csname fn:\the\fnotenum\endcsname}
1320
 
1321
\def\Xfnote{\advance\fnotenumlocal by1 \advance\fnotenum by1
1322
   \sxdef{fn:\the\fnotenum}{\the\fnotenumlocal}}
1323
 
1324
\def\runningfnotes{\locfnumfalse\def\locfnum{\the\fnotenum}\def\fnmarkx{\thefnote}}
1325
 
1326
\newcount\mnotenum    \mnotenum=0       % global counter of mnotes
1327
\newdimen\mnoteskip   \mnoteskip=0pt
1328
 
1329
\def\mnote#1{\ifvmode \mnoteA{#1}\nobreak\vskip-\baselineskip
1330
   \else \strut\vadjust{\kern-\dp\strutbox \mnoteA{#1}\kern\dp\strutbox}%
1331
   \fi
1332
}
1333
\def\mnoteA#1{\global\advance \mnotenum by1
1334
   \ifx\mnotesfixed\undefined
1335
      \isdefined{mn:\the\mnotenum}\iftrue
1336
      \else\opwarning{unknown \noexpand\mnote side. TeX me again}\fi
1337
      \edef\tmp{\csname mn:\the\mnotenum\endcsname}%
1338
      \openref\wref\Xmnote{}%
1339
   \else \let\tmp=\mnotesfixed \fi
1340
   \expandafter\ifx\tmp \left
1341
      \hbox to0pt{\pdfsave\mnoteC\kern-\mnotesize \kern-\mnoteindent
1342
         \vbox to0pt{\vss \setbox0=\vtop{\hsize=\mnotesize 
1343
            \leftskip=0pt plus 1fill \rightskip=0pt {\mnotehook\noindent#1\endgraf}}%
1344
         \dp0=0pt \box0 \kern\mnoteskip \global\mnoteskip=0pt}\hss\mnoteD\pdfrestore}%
1345
   \else
1346
      \hbox to0pt{\pdfsave\mnoteC\kern\hsize \kern\mnoteindent
1347
         \vbox to0pt{\vss \setbox0=\vtop{\hsize=\mnotesize 
1348
             \rightskip=0pt plus 1fil \leftskip=0pt {\mnotehook\noindent#1\endgraf}}%
1349
          \dp0=0pt \box0 \kern\mnoteskip \global\mnoteskip=0pt}\hss\mnoteD\pdfrestore}%
1350
   \fi
1351
}
1352
\def\mnoteC{\writecolorfalse \let\longlocalcolor=\localcolor
1353
   \edef\mnoteD{\xdef\noexpand\currcolork{\currcolork}\xdef\noexpand\currcolorK{\currcolorK}}%
1354
   \def\currcolork{}\def\currcolorK{}%
1355
}
1356
\def\Xmnote{\advance\mnotenum by1
1357
   \sxdef{mn:\the\mnotenum}{\ifodd\lastpage \right \else \left \fi}}
1358
 
1359
\def\fixmnotes#1{\def\mnotesfixed{#1}}
1360
 
1361
 
1362
%%%%%%%%%%%%%% \cite, \bib, \usebibtex, \usebbl -- sec. 3.23 in opmac-d.pdf
1363
 
1364
\newwrite\auxfile                      % AUX file for BibTeX
1365
\newcount\bibnum                       % the bibitem counter
1366
\newtoks\bibmark                       % the bibmark used if \nonumcitations
1367
\newcount\lastcitenum  \lastcitenum=0  % for \shortcitations
1368
 
1369
\def\cite[#1]{{\citeA#1,,,[\printsavedcites]}}
1370
\def\nocite[#1]{{\citeA#1,,,}}
1371
\def\rcite[#1]{{\citeA#1,,,\printsavedcites}}
1372
\def\savedcites{}
1373
 
1374
\def\citeA #1#2,{\if#1,\else 
1375
   \if *#1\addcitelist{*}\expandafter \skiptorelax \fi
1376
   \isdefined{bib:#1#2}\iftrue \else
1377
      \addcitelist{#1#2}%
1378
      \opwarning{The cite [#1#2] unknown. Try to TeX me again}\openref
1379
      \addto\savedcites{?,}\def\sortcitesA{}\lastcitenum=0
1380
      \expandafter\gdef\csname bib:#1#2\endcsname {}%
1381
      \expandafter \skiptorelax \fi
1382
   \expandafter \ifx \csname bib:#1#2\endcsname \empty
1383
      \addto\savedcites{?,}\def\sortcitesA{}\lastcitenum=0
1384
      \expandafter \skiptorelax \fi
1385
   \def\bibnn##1{}%
1386
   \if &\csname bib:#1#2\endcsname
1387
      \addcitelist{#1#2}%
1388
      \def\bibnn##1##2{##1}%
1389
      \sxdef{bib:#1#2}{\csname bib:#1#2\endcsname}%
1390
   \fi
1391
   \edef\savedcites{\savedcites \csname bib:#1#2\endcsname,}%
1392
   \relax
1393
   \expandafter\citeA\fi
1394
}
1395
\def\printsavedcites{\sortcitesA 
1396
   \chardef\tmpb=0 \expandafter\citeB\savedcites,%
1397
   \ifnum\tmpb>0 \printdashcite{\the\tmpb}\fi
1398
}
1399
\def\sortcitesA{}
1400
\def\sortcitations{%
1401
  \def\sortcitesA{\edef\savedcites{300000,\expandafter}\expandafter\sortcitesB\savedcites,%
1402
                  \def\tmpa####1300000,{\def\savedcites{####1}}\expandafter\tmpa\savedcites}%
1403
}
1404
\def\sortcitesB #1,{\if $#1$%
1405
  \else
1406
     \mathchardef\tmpa=#1
1407
     \edef\savedcites{\expandafter}\expandafter\sortcitesC \savedcites\end
1408
     \expandafter\sortcitesB 
1409
  \fi
1410
}
1411
\def\sortcitesC#1,{\ifnum\tmpa<#1\edef\tmpa{\the\tmpa,#1}\expandafter\sortcitesD 
1412
                   \else\edef\savedcites{\savedcites#1,}\expandafter\sortcitesC\fi}
1413
\def\sortcitesD#1\end{\edef\savedcites{\savedcites\tmpa,#1}}
1414
 
1415
\def\citeB#1,{\if$#1$\else
1416
   \if?#1\relax??%
1417
      \else
1418
      \ifnum\lastcitenum=0   % only comma separated list
1419
         \printcite{#1}%
1420
      \else
1421
         \ifx\citesep\empty  % first cite item
1422
            \lastcitenum=#1\relax
1423
            \printcite{#1}%
1424
         \else               % next cite item
1425
            \advance\lastcitenum by1
1426
            \ifnum\lastcitenum=#1\relax % cosecutive cite item
1427
               \mathchardef\tmpb=\lastcitenum
1428
            \else  % there is a gap between cite items
1429
               \lastcitenum=#1\relax
1430
               \ifnum\tmpb=0 % previous items were printed
1431
                  \printcite{#1}%
1432
               \else
1433
                  \printdashcite{\the\tmpb}\printcite{#1}\chardef\tmpb=0
1434
   \fi\fi\fi\fi\fi
1435
   \expandafter\citeB\fi
1436
}
1437
\def\shortcitations{\lastcitenum=1 }
1438
 
1439
\def\printcite#1{\citesep\citelink{#1}{\citelinkA{#1}}\def\citesep{,\hskip.2em\relax}}
1440
\def\printdashcite#1{\ifmmode-\else\hbox{--}\fi\citelink{#1}{\citelinkA{#1}}}
1441
\def\citesep{}
1442
 
1443
\def\nonumcitations{\lastcitenum=0\def\sortcitesA{}\def\etalchar##1{$^{##1}$}%
1444
   \def\citelinkA##1{\isdefined{bim:##1}\iftrue \csname bim:##1\endcsname
1445
      \else ##1\opwarning{\noexpand\nonumcitations + empty bibmark. Maybe bad BibTeX style}\fi}
1446
}
1447
\def\citelinkA{}
1448
 
1449
\def\ecite[#1]{\bgroup\citeA#1,,,\expandafter\eciteB\savedcites;}
1450
\def\eciteB#1,#2;#3{\if?#1\relax #3\else \citelink{#1}{#3}\fi\egroup}
1451
 
1452
\def\bib[#1] {\isnextchar={\bibA[#1]}{\bibmark={}\bibB[#1]}}
1453
\def\bibA[#1]=#2{\bibmark={#2}\bibB[#1]}
1454
\def\bibB[#1]{\par \ifnum\bibnum>0 \bibskip \fi
1455
   \advance\bibnum by1
1456
   \noindent \def\tmpb{#1}\wbib{#1}{\the\bibnum}{\the\bibmark}%
1457
   \printbib \ignorespaces
1458
}
1459
\def\wbib#1#2#3{\dest[cite:\the\bibnum]%
1460
   \ifx\wref\wrefrelax\else \immediate\wref\Xbib{{#1}{#2}{#3}}\fi}
1461
 
1462
\def\Xbib#1#2#3{\sdef{bib:#1}{\bibnn{#2}&}\if^#3^\else\sdef{bim:#2}{#3}\fi\def\lastbibnum{#2}}
1463
 
1464
\def\printbib{\hangindent=\iindent
1465
   \ifx\citelinkA\empty \noindent\hskip\iindent \llap{[\the\bibnum] }%
1466
   \else \noindent \fi
1467
}
1468
 
1469
\def\addcitelist#1{\global\addto\citelist{\citeI[#1]}}
1470
\def\writeaux#1{\immediate\write\auxfile{\string\citation{#1}}}
1471
\def\writeXcite#1{\openref\immediate\wref\Xcite{{#1}}}
1472
\def\citelist{} \def\citelistB{}
1473
 
1474
\def\usebibtex#1#2{%
1475
   \openref \openauxfile{#1}{#2}%
1476
   \def\citeI[##1]{\writeaux{##1}}\citelist
1477
   \global\let\addcitelist=\writeaux
1478
   \bgroup \readbblfile{\jobname}\egroup
1479
}
1480
\def\openauxfile#1#2{%
1481
   \immediate\openout\auxfile=\jobname.aux
1482
   \immediate\write\auxfile
1483
      {\percent\percent\space Opmac: AUX file reserved for bibtex only}%
1484
   \immediate\write\auxfile{\string\bibdata{#1}}%
1485
   \immediate\write\auxfile{\string\bibstyle{#2}}%
1486
}
1487
\def\readbblfile #1{%
1488
  \openin\testin=#1.bbl
1489
  \ifeof\testin
1490
    \opwarning{.bbl file doesn't exist. Use the ``bibtex #1'' command}%
1491
  \else
1492
    \closein\testin
1493
    \bibnum=0
1494
    \long\def\begin##1\bibitem{\bibitem}\def\end##1{}% LaTeX environment
1495
    \def\httpAddr##1{\url{http:##1}}\def\\{\hfill\break}%
1496
    \def\newblock{\hskip .11em plus.33em minus.07em}%
1497
    \def\mbox{\leavevmode\hbox}\def\emph##1{{\it##1}}%
1498
    \parindent=\iindent \bibtexhook\relax
1499
    \input #1.bbl
1500
    \par
1501
  \fi
1502
}
1503
\def\bibitem{\isnextchar[{\bibitemB}{\bibmark={}\bibitemC}}
1504
\def\bibitemB[#1]{\bibmark={#1}\bibitemC}
1505
\def\bibitemC#1{\bibitemD{#1}}
1506
\def\bibitemD#1{\par\ifnum\bibnum>0 \bibskip \fi
1507
   \advance\bibnum by1
1508
   \noindent \def\tmpb{#1}\wbib{#1}{\the\bibnum}{\the\bibmark}% 
1509
   \printbib \ignorespaces
1510
}
1511
\def\genbbl#1#2{\openauxfile{#1}{#2}%
1512
   \immediate\write\auxfile{\string\citation{*}}%
1513
   \bgroup
1514
     \iindent=4em
1515
     \def\bibitemC##1{\par\ifnum\bibnum>0 \bibskip \fi
1516
        \advance\bibnum by1
1517
        \noindent \hangindent=\parindent 
1518
        \indent \llap{[##1]\enspace}\ignorespaces
1519
     }%
1520
     \readbblfile{\jobname}%
1521
   \egroup
1522
}
1523
\def\usebbl/#1 #2 {\isdefined{bbl:#1}%
1524
   \iftrue \csname bbl:#1\endcsname {#2}\else
1525
      \opwarning{\string\usebbl/#1 #2 ... the `#1' type undefined}%
1526
   \fi
1527
}
1528
\sdef{bbl:a}#1{\bgroup \readbblfile{#1}\egroup}
1529
 
1530
\sdef{bbl:b}#1{\bgroup
1531
     \let\citeI=\relax \xdef\citelist{\citelist\citelistB}%
1532
     \def\bibitemC##1 ##2\par{%
1533
        \isinlist\citelist{[##1]}\iftrue \bibitemD{##1}##2\par\fi}%
1534
     \readbblfile{#1}%
1535
     \global\let\addcitelist=\writeXcite
1536
  \egroup
1537
}
1538
\sdef{bbl:c}#1{\bgroup
1539
     \ifx\citelinkA\empty \else 
1540
         \opwarning{\string\nonumcitations: don't use \string\usebbl/c}\fi
1541
     \let\citeI=\relax \xdef\citelist{\citelist\citelistB}%
1542
     \def\bibitemC##1 ##2\par{%
1543
        \isinlist\citelist{[##1]}\iftrue
1544
           \if^\the\bibmark^\sdef{bb:##1}{\bibitemD{##1}##2\par}%
1545
           \else \toks0={##2\par}%
1546
                 \edef\tmpa{\noexpand\sdef{bb:##1}{% \the\bibmark have to expand
1547
                      \noexpand\bibitemB[\the\bibmark]{##1}\the\toks0}}\tmpa
1548
        \fi\fi}%
1549
     \readbblfile{#1}%
1550
     \def\bibitemC##1{\bibitemD{##1}}%
1551
     \def\citeI[##1]{\csname bb:##1\endcsname}\citelist
1552
     \global\let\addcitelist=\writeXcite
1553
  \egroup
1554
}
1555
\def\Xcite#1{\addto\citelistB{\citeI[#1]}}
1556
 
1557
 
1558
%%%%%%%%%%%%%% output -- sec. 3.24 in opmac-d.pdf
1559
 
1560
\output={\begoutput \opmacoutput \endoutput}
1561
 
1562
\def\opmacoutput{%
1563
  \setbox0=\vbox{\makeheadline\pagebody\makefootline}%
1564
  \pghook \protectlist
1565
  \shipout\box0 \advancepageno
1566
  \ifnum\outputpenalty>-20000 \else\dosupereject\fi
1567
}
1568
\def\doprotect#1{\let#1=\relax}
1569
\addto\begoutput{\def\nl{ }\def\fnote##1{}\def\fnotemark##1{}}
1570
\def\prepage{\def\destheight{25pt}\dest[pg:\the\pageno]}
1571
 
1572
{\catcode`\@=11
1573
\gdef\pagecontents{\prepage % dest of pageno
1574
  \ifvoid\topins\else\unvbox\topins\fi
1575
  \preboxcclv  % colors setting
1576
  \dimen@=\dp\@cclv \unvbox\@cclv % open up \box255
1577
  \postboxcclv % colors restoring
1578
  \ifvoid\footins\else % footnote info is present
1579
    \vskip\skip\footins
1580
    \footnoterule
1581
    \unvbox\footins\fi
1582
  \ifr@ggedbottom \kern-\dimen@ \vfil \fi
1583
}}
1584
 
1585
\footline={\hss\tenrm\thefontsize[10]\the\pageno\hss}
1586
 
1587
 
1588
%%%%%%%%%%%%%% margins -- sec. 3.25 in opmac-d.pdf
1589
 
1590
\newdimen\pgwidth  \newdimen\pgheight  \pgwidth=0pt
1591
\newdimen\shiftoffset
1592
\newif\ifmarginshook  \marginshookfalse
1593
 
1594
\def\margins/#1 #2 (#3,#4,#5,#6)#7 {\def\tmp{#7}%
1595
   \ifx\tmp\empty
1596
      \opwarning{\string\margins: missing unit, mm inserted}\def\tmp{mm}\fi
1597
   \addto\tmp{\relax}%
1598
   \setpagedimens #2 % setting \pgwidth, \pgheight
1599
   \ifdim\pgwidth=0pt \else
1600
      \hoffset=-1\trueunit in \voffset=-1\trueunit in
1601
      \if$#3$\if$#4$\tmpdim=\pgwidth \advance\tmpdim -\hsize
1602
                    \divide\tmpdim by2 \advance\hoffset \tmpdim % left=right
1603
             \else  \rbmargin\hoffset\hsize{#4\tmp}% only right margin
1604
             \fi
1605
      \else  \if$#4$\advance\hoffset #3\tmp   % only left margin
1606
             \else  \hsize=\pgwidth           % left+right margin
1607
                    \advance\hsize -#3\tmp \advance\hsize -#4\tmp
1608
                    \advance\hoffset #3\tmp
1609
      \fi\fi
1610
      \if$#5$\if$#6$\tmpdim=\pgheight \advance\tmpdim -\vsize
1611
                    \divide\tmpdim by2 \advance\voffset \tmpdim % top=bottom
1612
             \else  \rbmargin\voffset\vsize{#6\tmp}% only bottom margin
1613
             \fi
1614
      \else  \if$#6$\advance\voffset #5\tmp   % only top margin
1615
             \else  \vsize=\pgheight          % top+bottom margin
1616
                    \advance\vsize -#5\tmp \advance\vsize -#6\tmp
1617
                    \advance\voffset #5\tmp
1618
      \fi\fi
1619
      \if 1#1\shiftoffset=0pt \else \if 2#1% double-page layout
1620
         \shiftoffset=\pgwidth \advance\shiftoffset -\hsize
1621
         \advance\shiftoffset -2\hoffset \advance\shiftoffset -2in
1622
         \ifmarginshook \else \marginshooktrue
1623
            \addto\pghook{\ifodd\pageno \else \advance\hoffset \shiftoffset \fi}\fi
1624
      \else \opwarning{use \string\margins/1 or \string\margins/2}%
1625
   \fi\fi\fi
1626
}
1627
\def\rbmargin#1#2#3{\advance#1\pgwidth \advance#1-#2 \advance#1-#3}
1628
 
1629
\def\setpagedimens#1 {\isdefined{pgs:#1}\iftrue
1630
   \expandafter\expandafter\expandafter \setpagedimensA \csname pgs:#1\endcsname&%
1631
   \else \opwarning{page specification "#1" is undefined}\fi}
1632
\def\setpagedimensA (#1,#2)#3&{\pgwidth=#1\trueunit#3 \pgheight=#2\trueunit#3\relax
1633
    \ifx\pdfpagewidth\undefined \else
1634
        \pdfpagewidth=\pgwidth \pdfpageheight=\pgheight \fi}
1635
 
1636
\sdef{pgs:a3}{(297,420)mm}  \sdef{pgs:a4}{(210,297)mm}  \sdef{pgs:a5}{(148,210)mm}
1637
\sdef{pgs:a3l}{(420,297)mm} \sdef{pgs:a4l}{(297,210)mm} \sdef{pgs:a5l}{(210,148)mm}
1638
\sdef{pgs:b5}{(176,250)mm}  \sdef{pgs:letter}{(8.5,11)in}
1639
 
1640
\def\trueunit{}
1641
\def\magscale[#1]{\mag=#1\def\trueunit{true}%
1642
   \ifdim\pgwidth=0pt \else \truedimen\pgwidth \truedimen\pgheight \fi
1643
   \ifx\pdfpagewidth\undefined \else 
1644
       \truedimen\pdfpagewidth \truedimen\pdfpageheight 
1645
       \pdfhorigin=1truein \pdfvorigin=1truein % Origin is independent off \mag 
1646
   \fi}
1647
\def\truedimen#1{#1=\expandafter\ignorept\the#1truept }
1648
 
1649
%%%%%%%%%%%%%% XeTeX specific + REF file is read now -- sec 3.26 in opmac-d.pdf
1650
 
1651
\ifx\XeTeXversion\undefined \else \pdftexfalse \input opmac-xetex \fi
1652
\inputref
1653
\endinput
1654
 
1655
%%%%%%%%%%%%%% History of versions:
1656
 
1657
beta (a) Nov. 2012 ... first released version.
1658
Dec. 2012  first stable version
1659
Jan. 2013  \parfillskip in \caption corrected.
1660
           \athetnum, \captionhook introduced.
1661
           \nobreak in \tocline corrected, \tocdotfill corrected.
1662
           New \url, \urlcolor implicitly defined as \empty.
1663
           \bibitem by \hangindent, \afteritcorr in \em
1664
           \bslash introduced
1665
           \toclinehook \mnotehook, \mnoteskip introduced.
1666
           \global\advance in \caption corrected.
1667
           \thechapnum is without the dot.
1668
Feb. 2013  \urllink: works with \\, \%, \#, \$, \{, \}.
1669
           \localcolor, \longlocalcolor introduced
1670
           \global\advance for chap./sec. nums corrected
1671
           \printcaption introduced
1672
Apr. 2013  \table in \table allowed, \catcode`\|=12 set in \table.
1673
           \printsec(c): \ifnum\lastpenalty added.
1674
           \urlink: ``~ removing'' corrected
1675
           {\em text}\macro error  corrected.
1676
May  2013  \margins (2pages laylout) can be redefined by new \margins
1677
           \outlines use \pdfcatalog{/PageMode/UseOutlines}
1678
Jul. 2013  \fnotetext unwanted space - corrected
1679
           \picw=0pt prints picture in natural size, \picheight introduced
1680
           \isinlist corrected,
1681
           \othe\secnum in \secc removed
1682
           \dotocnum, \remskip, \reminsert introduced
1683
           \nonum, \notoc implemented
1684
           \destheight introduced as macro
1685
           \runningfnotes introduced
1686
           \addto defined as \long
1687
           \iiskip, \ttskip, \bibskip precedes by \par
1688
Aug. 2013  \dgsize corrected
1689
           \ifx\tmpa\tmpb in \printiiA is realized via \meaning
1690
           \ignorespaces included to \iis
1691
           \url hidden in group, in order to handle & in tables
1692
           \destheight rewritten as a dimen register
1693
           \rightskip, \leftskip corrected in \mnote
1694
           space corrected in \prepii
1695
           \input ams-math only if \normalmath is \undefined (released)
1696
Sep. 2013  \label: the ``duplicated label'' test added
1697
           \afternoindent: \box0 -> \box7
1698
           \scantabdata: \if#1| -> \ifx|#1
1699
           \fixmnotes recoded
1700
           \, uses \thinspace and it is \addprotected
1701
           \pdfliteral instead \special{PDF:...} used
1702
           XeTeX specific added
1703
           \draft, \insertoulines recoded
1704
           \endinsert redefined (\par added)
1705
           \addprotect\exfont (for exchars.tex cooperating)
1706
           \ulink improved and added to opmac-u
1707
           \postboxcclv: {\advancepageno} corrected
1708
Oct. 2013  /Border .6
1709
           better \adef
1710
           \typobase introduced
1711
           \typoscale[20000/] ``too large dimension'' ... solved 
1712
           \activettchar reimplemented
1713
Nov. 2013  \Xpage: \ifnum\lastpage=#1 \else inserted
1714
           \frame is defined as \long
1715
           multilanuage: cz -> cs changed (by ISO 639-1)
1716
           \cr -> \crcr in \crl, \crll and \crli
1717
           \doverbinput: \ifeof\vifile added (bug ``empty line at EOF'' corrected)
1718
           eTeX support for multilang added.
1719
Feb. 2014  \sortcitations introduced, internal macros of \cite rewritten
1720
Mar. 2014  \frame: \setbox0=\hbox{{#1}} in order to \aftergroup in #1
1721
           \mnote: \pdfsave,\pdfrestore inserted, \mnote colors rewritten
1722
Apr. 2014  \nonumcitations, \ecite, \printbib, \lastbibnum introduced
1723
           \wbib, \citelink rewritten (more parameters now)
1724
           \destheight rewritten as macro, sorry
1725
           \fnotehook introduced
1726
Apr. 2014b \nocite[*] bug removed, \insertmark corrected
1727
Apr. 2014c nowarn about old csplain if csplain isn't used
1728
May  2014  \hyphenchar\urlfont=-1, \urlspecchar introduced
1729
 
1730
%%%%%%%%%%%%%% End of opmac.tex