%%
%% This is file `imakeidx.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% imakeidx.dtx  (with options: `package')
%%   ___________________________________________________________
%%   The imakeidx package for LaTeX
%%   Copyright (C) 2010-2013 Enrico Gregorio
%%   All rights reserved
%% 
%%   License information appended
%% 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{imakeidx}%
   [2016/05/16 v1.3c Package for typesetting indices in a synchronous mode]





\RequirePackage{xkeyval}
\DeclareOption{xindy}{\def\imki@progdefault{texindy}}
\DeclareOption{texindy}{\def\imki@progdefault{texindy}}
\DeclareOption{truexindy}{\def\imki@progdefault{truexindy}}
\DeclareOption{makeindex}{\def\imki@progdefault{makeindex}}
\newif\ifimki@disableautomatic
\DeclareOption{noautomatic}{\imki@disableautomatictrue}
\newif\ifimki@nonewpage
\DeclareOption{nonewpage}{%
  \imki@nonewpagetrue\imki@disableautomatictrue
}
\newif\ifimki@splitindex
\DeclareOption{splitindex}{\imki@splitindextrue}
\newif\ifimki@original
\DeclareOption{original}{\imki@originaltrue}
\DeclareOption{quiet}{\AtEndOfPackage{%
  \let\imki@finalmessage\@gobble
  \let\imki@splitindexmessage\relax}}
\ExecuteOptions{makeindex}
\ProcessOptions\relax

\if@twocolumn\imki@originaltrue\fi
\def\imki@exec{\immediate\write18}
\def\imki@engine{(pdf)latex}
\RequirePackage{ifxetex,ifluatex}
\ifxetex\def\imki@engine{xelatex}\fi
\ifluatex % luatex doesn't have \(pdf)shellescape
  \def\imki@engine{lualatex}
  \ifnum\luatexversion<68
    \chardef\imki@shellescape\@ne % no way to know the value
  \else
    \chardef\imki@shellescape\directlua{tex.write(os.execute())}
    \def\imki@exec#1{\directlua{os.execute("\luaescapestring{#1}")}}
  \fi
\fi
\edef\imki@splitindexoptions{-m \string"\string"}
\def\splitindexoptions#1{\g@addto@macro\imki@splitindexoptions{ #1}}
\@onlypreamble\splitindexoptions
\@namedef{ver@makeidx.sty}{3000/12/31}
\@ifpackageloaded{multind}
  {\PackageError{imakeidx}{Incompatible package `multind' loaded}
    {This package is incompatible with multind, don't load both.%
     \MessageBreak\@ehc}}
  {\@namedef{ver@multind.sty}{3000/12/31}}
\providecommand*\see[2]{\emph{\seename} #1}
\providecommand*\seealso[2]{\emph{\alsoname} #1}
\providecommand*\seename{see}
\providecommand*\alsoname{see also}
\providecommand*\makeindex{} % to use \renewcommand safely
\renewcommand{\makeindex}[1][]{\imki@makeindex{#1}}
\def\imki@makeindex#1{%
  \edef\imki@name{\jobname}%
  \edef\imki@jobname{\jobname}%
  \def\imki@title{\indexname}%
  \edef\imki@program{\imki@progdefault}%
  \let\imki@options\space
  \KV@imki@noautomaticfalse\KV@imki@intocfalse
  \setkeys{imki}{#1}%
  \ifimki@splitindex\KV@imki@noautomaticfalse\fi
  \imki@build\imki@name
  \imki@startidx\imki@name
  \imki@resetdefaults
}
\define@key{imki}{name}{\def\imki@name{#1}}
\define@key{imki}{title}{\def\imki@title{#1}}
\define@choicekey{imki}{program}[\imki@val\imki@nr]
  {makeindex,xindy,texindy,truexindy}{%
    \ifcase\imki@nr\relax
      \def\imki@program{makeindex}%
    \or
      \def\imki@program{texindy}%
    \or
      \def\imki@program{texindy}%
    \or
      \def\imki@program{xindy}%
    \fi}
\define@key{imki}{options}{\def\imki@options{ #1 }}
\define@boolkey{imki}{noautomatic}[true]{}
\define@boolkey{imki}{intoc}[true]{}
\define@key{imki}{columns}{\def\imki@columns{#1}}
\define@key{imki}{columnsep}{\def\imki@columnsep{#1}}
\define@boolkey{imki}{columnseprule}[true]{}
\def\imki@resetdefaults{%
  \def\imki@options{ }%
  \def\imki@columns{2}\def\imki@columnsep{35\p@}%
  \KV@imki@columnseprulefalse
  \KV@imki@intocfalse\KV@imki@noautomaticfalse}
\imki@resetdefaults
\def\imki@build#1{%
  \toks@{}%
  \imki@dokey\imki@title
  \imki@dokey\imki@program
  \imki@dokey\imki@options
  \imki@dokey\imki@columns
  \imki@dokey\imki@columnsep
  \ifKV@imki@noautomatic
    \addto@hook\toks@{\KV@imki@noautomatictrue}%
  \else
    \addto@hook\toks@{\KV@imki@noautomaticfalse}%
  \fi
  \ifKV@imki@intoc
    \addto@hook\toks@{\KV@imki@intoctrue}%
  \else
    \addto@hook\toks@{\KV@imki@intocfalse}%
  \fi
  \ifKV@imki@columnseprule
    \addto@hook\toks@{\KV@imki@columnsepruletrue}%
  \else
    \addto@hook\toks@{\KV@imki@columnseprulefalse}%
  \fi
  \expandafter\edef\csname imki@set@#1\endcsname{\the\toks@}%
}
\def\imki@dokey#1{%
  \expandafter\addto@hook\expandafter\toks@\expandafter{%
    \expandafter\def\expandafter#1\expandafter{#1}}}
\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
    \typeout{Writing index file #1.idx}%
  \fi}
\newif\ifimki@startedidx
\def\imki@startidxunique#1{%
  \if@filesw
    \ifimki@startedidx\else
      \newwrite\@indexfile
      \immediate\openout\@indexfile\imki@jobname.idx%
      \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}
\renewcommand{\index}[2][]{\@bsphack\@esphack}
\def\@index[#1]{%
  \@ifundefined{#1@idxfile}%
  {\PackageWarning{imakeidx}{Undefined index file `#1'}%
   \begingroup
   \@sanitize
   \imki@nowrindex}%
  {\edef\@idxfile{#1}%
   \begingroup
   \@sanitize
   \@wrindex\@idxfile}}
\def\imki@nowrindex#1{\endgroup\@esphack}
\@ifundefined{showindexmarks}{\newif\ifshowindexmark}{}
\@ifpackageloaded{showidx}{\showindexmarktrue}{\showindexmarkfalse}
\newcommand\imki@showidxentry[2]{%
  \ifshowindexmark
    \@showidx{\ifdefequal{\imki@jobname}{#1}{}{[#1]\space}#2}%
  \fi}
\newcommand\imki@wrindexentrysplit[3]{%
  \expandafter\protected@write\csname#1@idxfile\endcsname{}%
    {\string\indexentry{#2}{#3}}%
}
\newcommand\imki@wrindexentryunique[3]{%
  \protected@write\@indexfile{}%
    {\string\indexentry[#1]{#2}{#3}}%
}
\def\imki@wrindexsplit#1#2{%
\imki@wrindexentrysplit{#1}{#2}{\thepage}%
\endgroup\imki@showidxentry{#1}{#2}%
  \@esphack%
}
\def\imki@wrindexunique#1#2{%
\imki@wrindexentryunique{#1}{#2}{\thepage}%
\endgroup\imki@showidxentry{#1}{#2}%
  \@esphack%
  }
\def\imki@shellwarn{}
\ifdefined\imki@shellescape % luatex
\else
  \@ifundefined{shellescape}
    {\let\imki@shellescape\pdfshellescape} % pdftex
    {\let\imki@shellescape\shellescape} % xetex
\fi
\ifnum\imki@shellescape=\z@
  \let\KV@imki@noautomaticfalse\KV@imki@noautomatictrue
  \KV@imki@noautomatictrue
  \def\imki@shellwarn{\MessageBreak or call \imki@engine\space with
    -shell-escape}
\fi
\ifimki@disableautomatic
  \let\KV@imki@noautomaticfalse\KV@imki@noautomatictrue
  \KV@imki@noautomatictrue
\fi
\ifimki@original
 \expandafter\def\expandafter\theindex\expandafter{\expandafter
    \imki@maybeaddtotoc\theindex}
\else
  \global\let\imki@idxprologue\relax
  \RequirePackage{multicol}
  \renewenvironment{theindex}
    {\imki@maybeaddtotoc
     \imki@indexlevel{\indexname}\imki@indexheaders
     \thispagestyle{\imki@firstpagestyle}%
     \ifnum\imki@columns>\@ne
       \columnsep \imki@columnsep
       \ifx\imki@idxprologue\relax
         \begin{multicols}{\imki@columns}
       \else
         \begin{multicols}{\imki@columns}[\imki@idxprologue]
       \fi
     \else
       \imki@idxprologue
     \fi
     \global\let\imki@idxprologue\relax
     \parindent\z@
     \parskip\z@ \@plus .3\p@\relax
     \columnseprule \ifKV@imki@columnseprule.4\p@\else\z@\fi
     \raggedright
     \let\item\@idxitem
     \imki@othercode}
    {\ifnum\imki@columns>\@ne\end{multicols}\fi
}
\fi
\def\imki@indexlevel{%
  \@ifundefined{chapter}{\section}{\chapter}*}
\define@key{imkiindex}{level}{\def\imki@indexlevel{#1}}
\def\imki@toclevel{%
  \@ifundefined{chapter}{section}{chapter}}
\define@key{imkiindex}{toclevel}{\def\imki@toclevel{#1}}
\define@boolkey{imkiindex}{noclearpage}[true]{\let\imki@clearpage\relax}
\def\imki@indexheaders{%
  \@mkboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}}
\define@key{imkiindex}{headers}{\def\imki@indexheaders{\markboth#1}}
\def\imki@firstpagestyle{plain}
\define@key{imkiindex}{firstpagestyle}{\def\imki@firstpagestyle{#1}}
\let\imki@othercode\relax
\define@key{imkiindex}{othercode}{\def\imki@othercode{#1}}
\newcommand{\indexsetup}[1]{%
  \ifimki@original\else\setkeys{imkiindex}{#1}\fi}
\@onlypreamble\indexsetup
\newcommand{\indexprologue}[2][\bigskip]{%
  \long\gdef\imki@idxprologue{{#2\par}#1}}
\providecommand*{\printindex}{}
\renewcommand*{\printindex}[1][\imki@jobname]{%
  \@ifundefined{#1@idxfile}{\imki@error{#1}}{\imki@putindex{#1}}}

\def\imki@error#1{%
  \def\@tempa{#1}\def\@tempb{\imki@jobname}%
  \ifx\@tempa\@tempb
    \let\imki@optarg\@empty
  \else
    \def\imki@optarg{[#1]}%
  \fi
  \PackageError{imakeidx}
    {Misplaced \protect\printindex\imki@optarg}
    {You are not making this index, as no appropriate
     \protect\makeindex\MessageBreak
     command has been issued in the preamble.}}
\def\imki@clearpage{%
  \@ifundefined{chapter}
    {\clearpage} % article and similar classes
    {\@ifundefined{if@openright}
       {\cleardoublepage}
       {\if@openright
          \cleardoublepage
        \else
          \clearpage
       \fi}
    }}
\def\imki@check@indexname{\indexname}
\providecommand*\imki@maybeaddtotoc{}
\def\imki@finalmessage#1{%
  \expandafter\edef\csname imki@message#1\endcsname
    {\imki@program\imki@options#1.idx}
  \AtEndDocument{\PackageWarning{imakeidx}{%
    Remember to run \imki@engine\space again after calling\MessageBreak
    `\@nameuse{imki@message#1}'\imki@shellwarn\@gobble}}}
\def\imki@splitindexmessage{%
  \AtEndDocument{\PackageWarningNoLine{imakeidx}{%
    Remember to run \imki@engine\space again after calling\MessageBreak
    `splitindex' and processing the indices\imki@shellwarn}}}
\def\imki@makeindexname{makeindex}
\def\imki@decide{%
  \@tempswafalse
  \ifimki@splitindex % splitindex is not "safe"
    \ifnum\imki@shellescape=\@ne\@tempswatrue\fi
  \else
    \ifx\imki@program\imki@makeindexname % nor is texindy
      \ifnum\imki@shellescape=\tw@\@tempswatrue\fi
    \fi
    \ifnum\imki@shellescape=\@ne\@tempswatrue\fi
  \fi
  \ifKV@imki@noautomatic
    \@tempswafalse
  \fi}
\def\imki@putindexsplit#1{%
  \ifimki@nonewpage\else
    \imki@clearpage
    \ifimki@disableautomatic\else
      \immediate\closeout\csname #1@idxfile\endcsname
    \fi
  \fi
  \let\imki@indexname\indexname % keep \indexname
  \@nameuse{imki@set@#1}\imki@decide
  \if@tempswa % we can call the external program
    \imki@exec{\imki@program\imki@options#1.idx}%
  \else
    \imki@finalmessage{#1}%
  \fi
  \ifKV@imki@intoc
    \def\imki@maybeaddtotoc{\@nameuse{phantomsection}%
      \addcontentsline{toc}{\imki@toclevel}{\imki@title}}%
  \else
    \def\imki@maybeaddtotoc{}%
  \fi
  \ifx\imki@title\imki@check@indexname\else
    \def\indexname{\imki@title}%
  \fi
  \@input@{#1.ind}
  \let\indexname\imki@indexname % restore \indexname
}

\newif\ifimki@splitdone
\def\imki@putindexunique#1{%
  \ifimki@nonewpage\else
    \imki@clearpage
  \fi
  \let\imki@indexname\indexname % keep \indexname
  \@nameuse{imki@set@#1}\imki@decide
  \if@tempswa % we can call the external program
    \ifimki@splitdone\else
      \ifimki@disableautomatic\else
        \immediate\closeout\@indexfile
      \fi
      \imki@exec{splitindex \imki@splitindexoptions\space\imki@jobname.idx}%
      \global\imki@splitdonetrue
    \fi
  \else
    \ifimki@splitdone\else
      \imki@splitindexmessage\global\imki@splitdonetrue
    \fi
  \fi
  \if@tempswa % we can call the external program
    \imki@exec{\imki@program\imki@options\imki@jobname-#1.idx}%
  \fi
  \ifKV@imki@intoc
    \def\imki@maybeaddtotoc{\@nameuse{phantomsection}%
      \addcontentsline{toc}{\imki@toclevel}{\imki@title}}%
  \else
    \def\imki@maybeaddtotoc{}%
  \fi
  \ifx\imki@title\imki@check@indexname\else
    \def\indexname{\imki@title}%
  \fi
  \@input@{\imki@jobname-#1.ind}
  \let\indexname\imki@indexname % restore \indexname
}
\ifimki@splitindex
  \let\imki@startidx\imki@startidxunique
  \let\@wrindex\imki@wrindexunique
  \let\imki@putindex\imki@putindexunique
  \let\imki@wrindexentry\imki@wrindexentryunique
  \let\imki@startidxsplit\@undefined
  \let\imki@wrindexsplit\@undefined
  \let\imki@putindexsplit\@undefined
\else
  \let\imki@startidx\imki@startidxsplit
  \let\@wrindex\imki@wrindexsplit
  \let\imki@putindex\imki@putindexsplit
  \let\imki@wrindexentry\imki@wrindexentrysplit
  \let\imki@startidxunique\@undefined
  \let\imki@wrindexunique\@undefined
  \let\imki@putindexunique\@undefined
\fi
\@ifclassloaded{memoir}{\let\@wrindexm@m\@wrindex
   \AtBeginDocument{\hideindexmarks}}{}
%% 
%% Copyright 2010--2013 Enrico Gregorio <Enrico dot Gregorio at univr dot it>
%% 
%% Distributable under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is "author-maintained"
%% 
%% This work consists of this file imakeidx.dtx, a README file
%% and the derived files imakeidx.sty and imakeidx.pdf.
%% 
%%
%% End of file `imakeidx.sty'.
