Debian Codegraph @

texmf-dist/tex/plain/makeindex/idxmac.tex

raw
1 %
2 % idxmac.tex
3 %
4 % Most of the code in this file are excerpts from latex.tex and manmac.tex.
5 % The actual style of the index environment \beginindex ... \endindex
6 % at the end of this file is left empty.
7 %
8 %
9 \def\makeatletter{\catcode`\@=11\relax}
10 \def\makeatother{\catcode`\@=12\relax}
11 \makeatletter
12 \newif\if@filesw \@fileswtrue
13 \newif\if@nobreak \@nobreakfalse
14 \def\@makeother#1{\catcode`#112\relax}
15 \def\newwrite{\alloc@7\write\chardef\sixt@@n}
16 \newwrite\@unused
17 \def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
18
19 % ****************************************
20 % * PAGE NUMBERING *
21 % ****************************************
22 %
23 % Page numbers are produced by a page counter, used just like any other
24 % counter. The only difference is that \c@page contains the number of
25 % the next page to be output (the one currently being produced), rather
26 % than one minus it. Thus, it is normally initialized to 1 rather than
27 % 0. \c@page is defined to be \count0, rather than a count assigned by
28 % \newcount.
29 %
30 % The user sets the pagenumber style with the \pagenumbering{FOO}
31 % command, which sets the page counter to 1 and defines \thepage to be
32 % \FOO. For example, \pagenumbering{roman} causes pages to be numbered
33 % i, ii, etc.
34
35 % Numbering commands for definitions of \theCOUNTER and \list arguments.
36 % \fnsymbol produces the standard footnoting symbols: asterisk, dagger, etc.
37 % They can be used only in math mode.
38
39 \def\arabic#1{\@arabic{\@nameuse{c@#1}}}
40 \def\roman#1{\@roman{\@nameuse{c@#1}}}
41 \def\Roman#1{\@Roman{\@nameuse{c@#1}}}
42 \def\alph#1{\@alph{\@nameuse{c@#1}}}
43 \def\Alph#1{\@Alph{\@nameuse{c@#1}}}
44 \def\fnsymbol#1{\@fnsymbol{\@nameuse{c@#1}}}
45
46 \def\@arabic#1{\ifnum #1>0 \number #1\fi}
47 \def\@roman#1{\romannumeral #1}
48 \def\@Roman#1{\expandafter\uppercase\expandafter{\romannumeral #1}}
49 \def\@alph#1{\ifcase#1\or a\or b\or c\or d\else\@ialph{#1}\fi}
50 \def\@ialph#1{\ifcase#1\or \or \or \or \or e\or f\or g\or h\or i\or j\or
51 k\or l\or 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
52 z\else\@ctrerr\fi}
53 \def\@Alph#1{\ifcase#1\or A\or B\or C\or D\else\@Ialph{#1}\fi}
54 \def\@Ialph#1{\ifcase#1\or \or \or \or \or E\or F\or G\or H\or I\or J\or
55 K\or L\or 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
56 Z\else\@ctrerr\fi}
57 \def\@fnsymbol#1{\ifcase#1\or *\or \dagger\or \ddagger\or
58 \mathchar "278\or \mathchar "27B\or \|\or **\or \dagger\dagger
59 \or \ddagger\ddagger \else\@ctrerr\fi\relax}
60
61 \countdef\c@page=0 \c@page=1
62 \def\cl@page{}
63 \def\pagenumbering#1{\global\c@page \@ne \gdef\thepage{\csname @#1\endcsname
64 \c@page}}
65 \pagenumbering{arabic}
66
67 % \@bsphack ... \@esphack
68 % used by macros such as \index and \begin{@float} ... \end{@float}
69 % that want to be invisible -- i.e.,
70 % not leave any extra space when used in the middle of text. Such
71 % a macro should begin with \@bsphack and end with \@esphack
72 % The macro in question should not create any text, nor change the
73 % mode.
74 %
75 % \@bsphack ==
76 % BEGIN
77 % \dimen\@savsk := \lastskip
78 % if hmode then \@savsf := \spacefactor fi
79 % END
80 %
81 % \@esphack ==
82 % BEGIN
83 % if hmode
84 % then \spacefactor := \@savsf
85 % if \dimen\@savsk > 0pt then \ignorespaces
86 % \global\ignoretrue fi
87 % fi
88 % END
89 %
90
91 \newdimen\@savsk
92 \newcount\@savsf
93
94 \def\@bsphack{\@savsk\lastskip
95 \ifhmode\@savsf\spacefactor\fi}
96
97 \def\@esphack{\relax\ifhmode\spacefactor\@savsf
98 {}\ifdim \@savsk >\z@ \global\ignoretrue \ignorespaces
99 \fi \fi}
100
101 % The command \@sanitize changes the catcode of all special characters
102 % except for braces to 'other'. It can be used for commands like
103 % \index that want to write their arguments verbatim. Needless to
104 % say, this command should only be executed within a group, or chaos
105 % will ensue.
106
107 \def\@sanitize{\@makeother\ \@makeother\\\@makeother\$\@makeother\&%
108 \@makeother\#\@makeother\^\@makeother\^^K\@makeother\_\@makeother\^^A%
109 \@makeother\%\@makeother\~}
110
111 % ****************************************
112 % * INDEX COMMANDS *
113 % ****************************************
114 %
115 % \makeindex ==
116 % BEGIN
117 % if \@filesw = T
118 % then open file \jobname.IDX as \indexfile
119 % \index == BEGIN \@bsphack
120 % \begingroup
121 % re-\catcode special characters to 'other'
122 % \wrindex
123 % fi
124 % END
125 %
126 % \wrindex{ITEM} ==
127 % BEGIN
128 % write of {\indexentry{ITEM}{page number}}
129 % \endgroup
130 % \@esphack
131 % END
132
133 % INITIALIZATION:
134 %
135 % \index == BEGIN \@bsphack
136 % \begingroup
137 % re-\catcode special characters (in case '%' there)
138 % \index
139 % END
140 %
141 % \index{ITEM} == BEGIN \endgroup \@esphack END
142 %
143 \def\makeindex{\if@filesw \newwrite\@indexfile
144 \immediate\openout\@indexfile=\jobname.idx
145 \def\index{\@bsphack\begingroup\@sanitize\@wrindex\@indexfile}
146 \typeout{Writing index file \jobname.idx }\fi}
147
148 \def\@wrindex#1#2{\let\thepage\relax
149 \xdef\gtempa{\write#1{\string
150 \indexentry{#2}{\thepage}}}\endgroup\gtempa
151 \if@nobreak \ifvmode\@nobreak\fi\fi\@esphack}
152
153 \def\index{\@bsphack\begingroup\@sanitize\@index}
154 \def\@index#1{\endgroup\@esphack}
155
156 \def\makeglossary{\if@@filesw \newwrite\@glossaryfile
157 \immediate\openout\@glossaryfile=\jobname.glo
158 \def\glossary{\@bsphack\begingroup\@sanitize\@wrindex\@glossaryfile}\typeout
159 {Writing glossary file \jobname.glo }\fi}
160
161 \def\glossary{\@bsphack\begingroup\@sanitize\index}
162
163 \newdimen\pagewidth
164 \pagewidth=\hsize
165 \newbox\partialpage
166 \def\begindoublecolumns{\begingroup
167 \output={\global\setbox\partialpage=\vbox{\unvbox255\bigskip}}\eject
168 \output={\doublecolumnout} \hsize=14pc \vsize=89pc
169 \let\item\@idxitem}
170 \def\enddoublecolumns{\output={\balancecolumns}\eject
171 \endgroup \pagegoal=\vsize}
172 \def\doublecolumnout{\splittopskip=\topskip \splitmaxdepth=\maxdepth
173 \dimen@=44pc \advance\dimen@ by-\ht\partialpage
174 \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
175 \onepageout\pagesofar
176 \unvbox255 \penalty\outputpenalty}
177 \def\pagesofar{\unvbox\partialpage
178 \wd0=\hsize \wd2=\hsize \hbox to\pagewidth{\box0\hfil\box2}}
179 \def\balancecolumns{\setbox0=\vbox{\unvbox255} \dimen@=\ht0
180 \advance\dimen@ by\topskip \advance\dimen@ by-\baselineskip
181 \divide\dimen@ by2 \splittopskip=\topskip
182 {\vbadness=10000 \loop \global\setbox3=\copy0
183 \global\setbox1=\vsplit3 to\dimen@
184 \ifdim\ht3>\dimen@ \global\advance\dimen@ by1pt \repeat}
185 \setbox0=\vbox to\dimen@{\unvbox1}
186 \setbox2=\vbox to\dimen@{\unvbox3}
187 \pagesofar}
188
189 \def\@idxitem{\par\hangindent 40pt}
190 \def\subitem{\par\hangindent 40pt \hskip 20pt}
191 \def\subsubitem{\par\hangindent 40pt \hskip 30pt}
192 \def\indexspace{\par \vskip 10pt plus 5pt minus 3pt\relax}
193
194 \def\beginindex{\begingroup\let\item\@idxitem
195 % Output opening routines go here
196 }
197 \def\endindex{
198 % Output closing routines go here.
199 \endgroup}
200 \makeatother