% -*-LaTeX-*-
% myindex.sty
%
% Indexing macro usage (producing a file for TeXidx to sort):
%	\INDEX{sortkey}{primary}
%	\SUBINDEX{sortkey}{primary}{secondary}
%
% For \SUBINDEX, the {secondary} field is automatically appended
% to the sort key, but separated from it by CTL-A (so that
% \SUBINDEX{foo}{foo}{bar} sorts before
% \SUBINDEX{foo}{foo}{baz} and
% \INDEX{foo bar}{foo bar}{bar} [the keys will be "foo<CTL-A>{bar}",
% "foo<CTL-A>{baz}", and "foo bar", respectively]
% TeX does not allow a control character in the input, so we
% actually output a "!" instead; it can be filtered back to
% a CTL-A using "sed -e 's/!/\001/' <infile >outfile", or we
% can make a special version of TeXidx that makes the change
% internally.
%
\makeatletter	% in case it wasn't
\def\initial#1{\section*{#1}}%
\def\entry#1#2{\item {#1}, #2}%
\def\primary#1{\item {#1}}%
\def\secondary#1#2{\subitem {#1}, #2}%
%
 \def\INDEX{\@bsphack\begingroup\@sanitize\@WRINDEX\@indexfile}%
%
 \def\@WRINDEX#1#2#3{\let\thepage\relax
     \xdef\@gtempa{\write#1{\string
      \entry{#2}{\thepage}{#3}}}\endgroup\@gtempa
     \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}%
%
  \def\SUBINDEX{\@bsphack\begingroup\@sanitize\@WRSUBINDEX\@indexfile}%
%
  \def\@WRSUBINDEX#1#2#3#4{\let\thepage\relax
     \xdef\@gtempa{\write#1{\string
      \entry{#3!{#4}}{\thepage}{#3}{#4}}}\endgroup\@gtempa
     \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}%
%
\newcommand{\X}[1]{{#1}\INDEX{#1}{#1}}%
%
\makeatletter
\def\@xobeysp{\leavevmode\penalty10000\ } % prevent verbatim mode line breaks
\makeatother

