%=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%			
%				Index tagging macros
%
%	All of these macros write index entires out the file <jobname>.ils,
%	which should be openned before they are used.
%
%	The first field of each macro is the actual text that will be included
%	in the final index entry. Will the final index file is produced, the
%	entries will normally be sorted based on the contents of the text
%	entires. When used for sorting purposes, the text is stripped of TeX 
%	control sequences, braces, and redundant white space. If this is
%	still unlikely to yield correct sorting behaviour, the second field
%	(nominally left blank) can be used to provide an explicit character
%	sequence for a sort key.
%
%=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%
\catcode`\@=11	% (-- watch this --)
\def\writeindexfile#1#2#3#4{\ifundefined{if#1list} \n@ewswitch{#1list} \fi
            \csname if#1list\endcsname
            {\let\folio=\relax  % do not expand \folio
            \nextsptoks\settoks{#4}\edef
	    \next{\write\csname #1@file\endcsname
            {#2 {#3}{\noexpand\the\noexpand\toks\sptoksnum}{\folio}}}\next}\fi
	    \nobreak}
%	
\def\index#1#2{\writeindexfile
	        {ils}{\string\index}{#1}{#2}\ignorespaces}
%
\def\indexIt#1#2{\writeindexfile
		{ils}{\string\indexIt}{#1}{#2}\ignorespaces}
%
\def\indexStart#1#2{\writeindexfile
	 	{ils}{\string\indexStart}{#1}{#2}\ignorespaces}
%
\def\indexItStart#1#2{\writeindexfile
		{ils}{\string\indexItStart}{#1}{#2}\ignorespaces}
%
\def\indexStop#1#2{\writeindexfile
		{ils}{\string\indexStop}{#1}{#2}\ignorespaces}
%
%=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%
%				Index output macros
%
%=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

\catcode`@= 11 % need to use some plain macros

\def\putindex#1#2{\par
	\noindent \hangindent=2\parindent\hangafter=1{#1}{#2}}
\newtoks\inputidxfiles
\inputidxfiles = {\inputwithcheck{\jobname.idx}}
\def\makeidxlist{\the\inputidxfiles}
\catcode`\@=12 % puts at back to a non letter (-- watch this --)
