% File windex.tex
% Macro for writing out index files (.idx files) for use with windex
% Author: Ronald L. Rivest
% Date:   11/20/89
% Note:   If you are using windex, then this file should be input into
%         your source file before and \index commands are given.
%         (It need not precede the \makeindex command.)
%         At the end of your file foo, you can place the commands
%               \makeatletter
%               \@input{foo.index}
%               \makeatother
%         just before the \end{document} command.
%         (These command are equivalent to
%               \input{foo.index}
%         unless foo.index doesn't yet exist, in which case \@input
%         merely prints a warning message and procedes, whereas \input
%         asks you for another file name.)

\makeatletter

%% The following causes all indexed terms to be printed in the right-hand
%% margin of the page.
%% To kill this effect, redefine \indexmargin to be a null macro

%% The following is for debugging (produces marginal index terms)
%% Comment this out for production; leave in for debugging.
%\newcommand{\indexmargin}[1]{{\tiny\marginpar{#1}}}
%% The following is for production (no marginal index terms)
%% Comment this out for debugging; leave in for production.
\newcommand{\indexmargin}[1]{}

\@mparswitchfalse               % Cause all marginal pars to go on right side

%% End of marginal notes for index terms hack

%% Make all characters ``other'' so that par box doesn't give errors
\def\@makeallother{%
\@makeother a\@makeother n\@makeother A\@makeother N%
\@makeother b\@makeother o\@makeother B\@makeother O%
\@makeother c\@makeother p\@makeother C\@makeother P%
\@makeother d\@makeother q\@makeother D\@makeother Q%
\@makeother e\@makeother r\@makeother E\@makeother R%
\@makeother f\@makeother s\@makeother F\@makeother S%
\@makeother g\@makeother t\@makeother G\@makeother T%
\@makeother h\@makeother u\@makeother H\@makeother U%
\@makeother i\@makeother v\@makeother I\@makeother V%
\@makeother j\@makeother w\@makeother J\@makeother W%
\@makeother k\@makeother x\@makeother K\@makeother X%
\@makeother l\@makeother y\@makeother L\@makeother Y%
\@makeother m\@makeother z\@makeother M\@makeother Z%
\@makeother /\@makeother !\@makeother <\@makeother >%
\@makeother \$\@makeother [\@makeother ]%
%\@makeother\
\@makeother\\\@makeother\$\@makeother\&%
\@makeother\#\@makeother\^\@makeother\^^K\@makeother\_\@makeother\^^A%
\@makeother\%\@makeother\~}

\def\index{\@bsphack\begingroup\@makeallother\@wrindex\@indexfile}

%% In the following #1 is the file,#2 is the string being indexed
\def\@wrindex#1#2{\let\thepage\relax
   \indexmargin{\fbox{\parbox[t]{1in}{#2}}}%
   \xdef\@gtempa{\write#1{#2:\thepage}}\endgroup\@gtempa
   \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}

\makeatother