%% This is file `xindex.sty',
%%
%% Copyright (C) 2019-
%% Herbert Voss
%%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%
% $Id: xindex.sty 836 2018-11-11 20:22:56Z herbert $
%
% -------------------------------------
\ProvidesPackage{xindex}[2018/11/11 v. 0.02 write into an idx file (hv)]
%
\RequirePackage{xkeyval}

\newif\if@@imakeidx \@@imakeidxfalse

\DeclareOptionX{imakeidx}{\@@imakeidxtrue}
\DeclareOptionX*{\PassOptionsToPackage\CurrentOption{imakeidx}}
\ProcessOptionsX\relax

\@ifpackageloaded{imakeidx}{}{%   imakeidx already loaded?? if not then define ...
  \newif\ifimki@startedidx
  \newif\ifimki@splitindex
}

\if@@imakeidx
  \typeout{xindex: Using package imakeidx}%
  \RequirePackage{imakeidx}
  \def\imki@progdefault{xindex}
  \def\imki@program{xindex}
%
  \def\imki@@startidxsplit#1{%
    \if@filesw
      \def\index{\@bsphack
        \@ifnextchar [{\@index}{\@index[\imki@jobname]}}
      \expandafter\newwrite\csname #1@idxfile\endcsname
      \immediate\openout \csname #1@idxfile\endcsname #1.idx\relax
      \def\writeidx##1{\write\expandafter\csname #1@idxfile\endcsname{\noexpand##1}}%
      \typeout{Writing index file #1.idx}%
    \fi
  }
  \global\imki@startedidxfalse
  \def\imki@@startidxunique#1{%
    \if@filesw
      \ifimki@startedidx\else
        \newwrite\@indexfile
        \immediate\openout\@indexfile\imki@jobname.idx%
        \def\writeidx##1{\write\@indexfile{\noexpand##1}}%
        \global\imki@startedidxtrue
      \fi
      \def\index{\@bsphack
        \@ifnextchar [{\@index}{\@index[\imki@jobname]}}
      \expandafter\let\csname #1@idxfile\endcsname\@empty
      \typeout{Started index file #1}%
   \fi
  }
%
  \ifimki@splitindex
    \let\imki@startidx\imki@@startidxunique
  \else
    \let\imki@startidx\imki@@startidxsplit
  \fi
\else
  \typeout{xindex: Using package makeidx}%
  \RequirePackage{makeidx}
  \def\writeidx#1{\write\@indexfile{\noexpand#1}}
\fi

\endinput

