\documentclass{article}
\usepackage{makeidx}
\makeindex
\begin{document}
 \title{The CorrIdx Package}
 \author{ J. K. Fink\\ Uni Leoben}
 \maketitle

\begin{abstract}

The CorrIdx package can be used to sort an index with chemical
names containing leading numbers, etc. into a proper alphabetical
order. It is intended as a preprocessor to the MakeIndex program.

\end{abstract}

\tableofcontents

\begin{center}
  {\em The author is not liable for whatever will happen by the use of the material presented
  here.}\vskip2ex

  NOTE: In the examples below, the INDEX comes always on a new page
\end{center}

\section{Introduction}

In a text containing chemical names like N,N'-diallyl p-phenyl
diamine , 1,2-ethanediol, o-chlorobisphenol~A,
endo-methylenetetrahydrophthalic acid anhydride, tert-butanol, you
may want to include these compounds into the index. If you use the
index command \verb"\index{...}", \LaTeX\space will produce from
the entries
\begin{verbatim}
    \index{1,2-ethanediol}
    \index{o-chlorobisphenol~A}
    \index{endo-methylenetetrahydrophthalic acid anhydride}
    \index{tert-butanol}
    \index{N,N'-diallyl p-phenyl diamine}
\end{verbatim}
with the \LaTeX\space command \verb"\MakeIndex" a \verb"*.idx"
file looking like
\begin{verbatim}
    \indexentry{1,2-ethanediol}{1} \indexentry{o-chlorobisphenol~A}{1}
    \indexentry{endo-methylenetetrahydrophthalic acid anhydride}{1}
    \indexentry{tert-butanol}{1} \indexentry{N,N'-diallyl p-phenyl
    diamine}{1}
\end{verbatim}
and the program MakeIndex produces
\begin{theindex}
  \item 1,2-ethanediol, 1

  \indexspace

  \item endo-methylenetetrahydrophthalic acid anhydride, 1

  \indexspace

  \item N,N'-diallyl p-phenyl diamine, 1

  \indexspace

  \item o-chlorobisphenol~A, 1

  \indexspace

  \item tert-butanol, 1
\end{theindex}
Note that we differentiate in between the \LaTeX\space command
\verb"\MakeIndex"  and the MakeIndex program. We are using
\verb"\usepackage{makeidx}".

Now, you may find that the sort order in the example above is not
satisfactory. Therefore you must use the \verb"@" in the index
command to force a certain sort order. Try now the following index
entries
\begin{verbatim}
    \index{ethanediol@1,2-ethanediol}
    \index{chlorobisphenol@o-chlorobisphenol~A}
    \index{methylenetetrahydrophthalic@endo-methylenetetrahydrophthalic acid anhydride}
    \index{butanol@tert-butanol}
    \index{diallyl@N,N'-diallyl-p-phenyl diamine}
\end{verbatim}
and the MakeIndex program will produce now a more satisfactory
result. This is shown now:
\begin{theindex}

  \item tert-butanol, 3

  \indexspace

  \item o-chlorobisphenol~A, 3

  \indexspace

  \item N,N'-diallyl-p-phenyl diamine, 3

  \indexspace

  \item 1,2-ethanediol, 3

  \indexspace

  \item endo-methylenetetrahydrophthalic acid anhydride, 3

\end{theindex}
The MakeIndex program uses the \verb"*.idx" file and produces a
*.ind file. We try now another type of index entries like this
\begin{verbatim}
 \index{chem @1,2-ethanediol}
 \index{chem @o-chlorobisphenol~A}
 \index{chem @endo-methylenetetrahydrophthalic acid anhydride}
 \index{chem @tert-butanol}
 \index{chem @N,N'-diallyl p-phenyl diamine}
 \index{chem @curing}
 \index{chem @synthesis}
\end{verbatim}
A single run with the \LaTeX\space command \verb"\MakeIndex" in
the text produces
\begin{verbatim}
  \indexentry{chem @1,2-ethanediol}{5}
  \indexentry{chem @o-chlorobisphenol~A}{5}
  \indexentry{chem @endo-methylenetetrahydrophthalic acid anhydride}{5}
  \indexentry{chem @tert-butanol}{5}
  \indexentry{chem @N,N'-diallyl p-phenyl diamine}{5}
  \indexentry{chem @curing}{5}
  \indexentry{chem @synthesis}{5}
\end{verbatim}
Now we run the corridx program as preprocessor and get a modified
preprocessed file \verb"*.idx" looking like
\begin{verbatim}
 \indexentry{chem ethanediol@1,2-Ethanediol}{5}
 \indexentry{chem chlorobisphenol~a@o-Chlorobisphenol~A}{5}
 \indexentry{chem methylenetetrahydrophthalicacidanhydride@endo-Methylenetetrahydrophthalic acid anhydride}{5}
 \indexentry{chem butanol@tert-Butanol}{5}
 \indexentry{chem diallylphenyldiamine@N,N'-Diallyl p-phenyl diamine}{5}
 \indexentry{chem curing@Curing}{5}
 \indexentry{chem synthesis@Synthesis}{5}
\end{verbatim}
Further, the MakeIndex program produces from this file an *.ind
file that is printed out as
\begin{theindex}
  \item tert-Butanol, 5
  \item o-Chlorobisphenol~A, 5
  \item Curing, 5
  \item N,N'-Diallyl p-phenyl diamine, 5
  \item 1,2-Ethanediol, 5
  \item endo-Methylenetetrahydrophthalic acid anhydride, 5
  \item Synthesis, 5
\end{theindex}
This is probably what you want.
\section{The Corridx Program}

The source code of the program is in Pascal compiled with Free
Pascal \newline (\verb"http://www.freepascal.org/")

\subsection{Using the Program}

Corridx stands for correct the \verb"*.idx" file. The simplest
call is to run \verb"corridx.exe". Then a file \verb"in.txt" must
be in the same directory as \verb"corridx.exe" and the output
comes in a file \verb"out.txt". Therefore you may copy your
\verb"*.idx" file into the \verb"in.txt", run \verb"corridx.exe"
and collect the output from \verb"out.txt". This output copy back
in your \verb"*.idx" file and run immediately the \verb"MakeIndex"
program.

If a command line parameter just one meaning a valid file name is
there, then the \verb"corridx.exe" takes this as input file and
copies the output back to this file. If more than one command line
is there, or if the filename is not correct, I did not check what
will happen.

I am running from Winedt both programs, as I have changed the
index menu into
\begin{verbatim}
  Run("c:\fullpathtocorridx\corridx.exe %P\%N.idx","%P",0,0,"CorrIdx",1,1);
  Prompt('Finished CorrIdx');
  Exe('%B\Exec\MiKTeX\MakeIndex.edt');
\end{verbatim}
The prompt is necessary to retard the program execution. Or else
you may use instead of the \verb"Run" command the \verb"WinExe"
command with the synchronize option. I did not check out this.

\subsection{Program Description}

Note that every index entry you create must contain a \verb"@",
otherwise an error will be created. For example create the entry
\verb"\index{chem @1,4-butanediol}". The program scans each line
in the \verb"*.idx" file. When it finds \verb"chem" just behind
the opening bracket \verb"{", it ignores what is after \verb"chem"
until it finds the \verb"@". Then it reads the name string until
the closing bracket comes. There should be no \verb"\}" in
between. Finally it reads the string with the page number. The
name string is copied to a sort string which is now processed:

\begin{enumerate}
    \item Every text in between dollar signs is replaced by a
    blank.
    \item Every non letter besides the tilde \verb"~" is replaced by a blank.
    So you may protect \verb"bisphenol~A".
    \item Every single letter in between blanks is replaced by a blank.
    \item Special sequences like exo, endo, tert, sec, cis,
    trans, syn, anti, cyclo, spiro are replaced by blanks.
    \item what is left over is made lower case.
\end{enumerate}

The program is looking now in the sort string for the first
appearance of a letter and makes in the name string this position
as uppercase. Then in the sort string all spaces are eliminated.
Finally, the index entry is rebuilt to result in
\verb"\indexentry{chem butanediol@1,4-Butanediol}{8}"%

\subsection{Further Options}

Four types of index are allowed:
\begin{enumerate}
    \item Index of chemicals \verb"\index{chem @1,3-Butadiene}"
    \item General Index \verb"\index{gen @Synthesis}"
    \item Index of acronyms \verb"\index{acr LCD@LCD!Liquid crystal display}"
    \item Index of other items \verb"\index{whatever you want@abc}"
\end{enumerate}
In an index entry of acronyms, a \verb"!" is compulsory. The
example above produces the index:

\begin{theindex}

  \item LCD
    \subitem Liquid crystal display, 8

  \indexspace

  \item 1,3-Butadiene, 8

  \indexspace

  \item Synthesis, 8

  \indexspace

  \item abc, 8

\end{theindex}

\section{User Defined Commands}

To get a better performance, it is a good idea to define the
following commands:

\begin{verbatim}
\newcommand{\ia}[2]{#1 {\nobreak(#2)}\index{acr #2@#2!#1}}
% is is an acronym index. Example: \ia{Polyalkylene oxide}{PAO} %
\newcommand{\ic}[1]{#1\index{chem #1@#1}}
% ic is a chemical index
\newcommand{\ib}[2]{#1 {\nobreak(#2)}\index{acr #2@#2!#1}\index{chem #1@#1}}
% ib is both acronym and chemical index
\newcommand{\ig}[2][]{#2\index{gen #2@#2#1}}
% ig is a general index
\end{verbatim}

\newcommand{\ia}[2]{#1 {\nobreak(#2)}\index{acr #2@#2!#1}}
% Example: \ia{Polyalkylene oxide}{PAO} %
\newcommand{\ic}[1]{#1\index{chem #1@#1}}
\newcommand{\ib}[2]{#1 {\nobreak(#2)}\index{acr #2@#2!#1}\index{chem #1@#1}}
% ib is both acronym and chemical
\newcommand{\ig}[2][]{#2\index{gen #2@#2#1}}

We show now the use of these commands in the following sample
text. You should look in the original \LaTeX\space file.

Note that we have in the text also the commands
\begin{verbatim}
    \newcommand\swallow[1]{\relax}
    \index{acr   @\section*{Acronyms}\swallow|swallow}%
    \index{chem  @\section*{Chemicals}\swallow|swallow}%
    \index{gen  @\section*{General}\swallow|swallow}%
\end{verbatim}

\section{Sample Text}

There are various types of novolak resins with different \ig[
resins]{ortho} to para ratios of the methylene linkages, \ia{high
ortho novolak resins}{HON}, \ia{general-purpose novolak
resins}{GPN} and \ia{high para novolak resins}{HPN}.

The liquid-phase oxidation of cumene to \ib{cumene
hydroperoxide}{CHP} results in \ic{acetone} and \ic{phenol}. This
is used for \ic{bisphenol~A}, \ic{bisphenol~B}, \ic{resorcinol},
\ic{cresol}s, and \ic{xylenol}s. \ic{2-Cyclohexyl-5-methylphenol}
is used for \ig[!positive]{photoresist}s. \ic{m-Methoxyphenol},
\ic{2-naphthol}, \ic{cardanol}, and \ic{cardol}, are other
suitable \ig[!other]{phenols}.


\section{The Sample Text Verbatim}

\begin{verbatim}
There are various types of novolak resins with different \ig[
resins]{ortho} to para ratios of the methylene linkages, \ia{high
ortho novolak resins}{HON}, \ia{general-purpose novolak
resins}{GPN} and \ia{high para novolak resins}{HPN}.

The liquid-phase oxidation of cumene to \ib{cumene
hydroperoxide}{CHP} results in \ic{acetone} and \ic{phenol}. This
is used for \ic{bisphenol~A}, \ic{bisphenol~B}, \ic{resorcinol},
\ic{cresol}s, and \ic{xylenol}s. \ic{2-Cyclohexyl-5-methylphenol}
is used for \ig[!positive]{photoresist}s. \ic{m-Methoxyphenol},
\ic{2-naphthol}, \ic{cardanol}, and \ic{cardol}, are other
suitable \ig[!other]{phenols}.
\end{verbatim}


    \newcommand\swallow[1]{\relax}
    \index{acr   @\section*{Acronyms}\swallow|swallow}%
    \index{chem  @\section*{Chemicals}\swallow|swallow}%
    \index{gen  @\section*{General}\swallow|swallow}%

\printindex

\end{document}
%
