%\iffalse
% testidx.dtx generated using makedtx version 1.1 (c) Nicola Talbot
% Command line args:
%   -src "testidx.sty\Z=>testidx.sty"
%   -doc "testidx-codedoc.tex"
%   -author "Nicola Talbot"
%   -codetitle "Main Package Code"
%   testidx
% Created on 2016/10/17 12:32
%\fi
%\iffalse
%<*package>
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%</package>
%\fi
% \iffalse
% Doc-Source file to use with LaTeX2e
% Copyright (C) 2016 Nicola Talbot, all rights reserved.
% \fi
% \iffalse
%<*driver>
\documentclass{nlctdoc}

\iffalse
testidx-codedoc.tex is a stub file used by makedtx to create
testidx.dtx
\fi

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[colorlinks,
            bookmarks,
            hyperindex=false,
            pdfauthor={Nicola L.C. Talbot},
            pdftitle={testidx.sty: Documented code}]{hyperref}

\RecordChanges

\renewcommand*{\main}[1]{\hyperpage{#1}}

\setcounter{IndexColumns}{2}

\CheckSum{4724}

\begin{document}
\DocInput{testidx.dtx}
\end{document}
%</driver>
%\fi
%\MakeShortVerb{"}
%\DeleteShortVerb{\|}
%
% \title{Documented Code For testidx v1.0}
% \author{Nicola L.C. Talbot\\[10pt]
%Dickimaw Books\\
%\url{http://www.dickimaw-books.com/}}
%
% \date{2016-10-17}
% \maketitle
%
%\tableofcontents
%
%\section{Introduction}
%
%This is the documented code for the \styfmt{testidx} package.
%See \texttt{testidx-manual.pdf} for the main user guide.
%
%
%\StopEventually{%
%  \phantomsection
%  \addcontentsline{toc}{section}{Change History}%
%  \raggedright
%  \PrintChanges
%  \PrintIndex
%}
%
%
%
%\section{Main Package Code}
%\iffalse
%    \begin{macrocode}
%<*testidx.sty>
%    \end{macrocode}
%\fi
%\section{Initialisation}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{testidx}[2016/10/17 v1.0 (NLCT)]
%    \end{macrocode}
%To avoid as much conflict as possible, this package loads the
%bare minimum, so I'm not using useful packages like \styfmt{etoolbox} or
%\styfmt{pgffor}. Just load a few necessities:
%    \begin{macrocode}
\RequirePackage{color}
%    \end{macrocode}
%Need to know if we have UTF-8 support:
%    \begin{macrocode}
\RequirePackage{ifxetex}
\RequirePackage{ifluatex}
%    \end{macrocode}
%\begin{macro}{\@tstidx@ifutfviii}
%    \begin{macrocode}
\newcommand*{\@tstidx@ifutfviii}[2]{%
  \ifxetex
   #1%
  \else
   \ifluatex
     #1%
   \else
     \@ifundefined{inputencodingname}{#2}%
     {\ifx\inputencodingname\@tstidx@utfviii#1\else#2\fi}%
   \fi
  \fi
}
\newcommand*{\@tstidx@utfviii}{utf8}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxprocessasciisort}
%The first argument is a control sequence in which to store the
%processed sort string.
%    \begin{macrocode}
\newcommand*{\tstidxprocessasciisort}{\tstidxprocessasciisortstrip}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\testidxStripAccents}
%    \begin{macrocode}
\newcommand*{\testidxStripAccents}{%
  \renewcommand*{\tstidxprocessasciisort}{\tstidxprocessasciisortstrip}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\testidxNoStripAccents}
%    \begin{macrocode}
\newcommand*{\testidxNoStripAccents}{%
  \renewcommand*{\tstidxprocessasciisort}{\tstidxprocessasciisortnostrip}%
}
%    \end{macrocode}
%\end{macro}
%
%Option to strip accents from sort key (non-UTF-8).
%    \begin{macrocode}
\DeclareOption{stripaccents}{\testidxStripAccents}
%    \end{macrocode}
%
%Leave the accent commands in the sort key (non-UTF-8).
%    \begin{macrocode}
\DeclareOption{nostripaccents}{\testidxNoStripAccents}
%    \end{macrocode}
%
%\begin{macro}{\tstidxquote}
%Quote character.
%    \begin{macrocode}
\newcommand{\tstidxquote}{\string"}
%    \end{macrocode}
%\end{macro}
%This is going to cause a problem for the umlauts if we're not using
%UTF-8, so provide a command to protect the double-quote:
%\begin{macro}{\tstidxumlaut}
%    \begin{macrocode}
\newcommand*{\tstidxumlaut}{%
  \expandafter\@gobble\string\\\tstidxquote\string"}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxsortumlaut}
%    \begin{macrocode}
\newcommand*{\tstidxsortumlaut}{%
  \expandafter\@gobble\string\\\tstidxquote\string"}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxsortumlautstrip}
%    \begin{macrocode}
\newcommand*{\tstidxsortumlautstrip}{\@firstofone}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\testidxGermanOn}
%Switch German option on.
%    \begin{macrocode}
\newcommand*{\testidxGermanOn}{%
  \let\@tstidx@ifgerman\@firstoftwo
  \renewcommand{\tstidxquote}{+}%
  \renewcommand*{\tstidxumlaut}{\string"}%
  \renewcommand*{\tstidxsortumlautstrip}{\string"}%
  \renewcommand*{\tstidxsortumlaut}{\string"}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\testidxGermanOff}
%Switch German option off.
%    \begin{macrocode}
\newcommand*{\testidxGermanOff}{%
  \let\@tstidx@ifgerman\@secondoftwo
  \renewcommand{\tstidxquote}{\string"}%
  \renewcommand*{\tstidxumlaut}{%
  \expandafter\@gobble\string\\\tstidxquote\string"}%
  \renewcommand*{\tstidxsortumlautstrip}{\@firstofone}%
  \renewcommand*{\tstidxsortumlaut}{%
    \expandafter\@gobble\string\\\tstidxquote\string"}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\@tstidx@ifgerman}
%    \begin{macrocode}
\newcommand*{\@tstidx@ifgerman}[2]{#2}
%    \end{macrocode}
%\end{macro}
%User may want to run \app{makeindex} with the \texttt{-g} switch,
%so provide \pkgopt{german} option that will accommodate this.
%    \begin{macrocode}
\DeclareOption{german}{\testidxGermanOn}
%    \end{macrocode}
%Also allow \pkgopt{ngerman} to do the same:
%    \begin{macrocode}
\DeclareOption{ngerman}{\testidxGermanOn}
%    \end{macrocode}
%Provide an option to counter-act this:
%    \begin{macrocode}
\DeclareOption{nogerman}{\testidxGermanOff}
%    \end{macrocode}
%
%
%\begin{macro}{\tstidxprocessutf}
%How to deal with UTF-8 words.
%    \begin{macrocode}
\ifxetex
  \newcommand*{\tstidxprocessutf}{%
    \tstidxprocessutfnosanitize
  }
\else
 \ifluatex
   \newcommand*{\tstidxprocessutf}{%
     \tstidxprocessutfnosanitize
   }
 \else
   \newcommand*{\tstidxprocessutf}{%
     \tstidxprocessutfsanitize
   }
 \fi
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\@tstidx@ifsanitize}
%    \begin{macrocode}
\newcommand*{\@tstidx@ifsanitize}[2]{#1}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\testidxSanitizeOn}
%Switch the \pkgopt{sanitize} option on.
%    \begin{macrocode}
\newcommand*{\testidxSanitizeOn}{%
   \let\@tstidx@ifsanitize\@firstoftwo
   \renewcommand*{\tstidxprocessutf}{%
     \tstidxprocessutfsanitize
   }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\testidxSanitizeOff}
%Switch the \pkgopt{sanitize} option off.
%    \begin{macrocode}
\newcommand*{\testidxSanitizeOff}{%
   \let\@tstidx@ifsanitize\@secondoftwo
   \renewcommand*{\tstidxprocessutf}{%
     \tstidxprocessutfnosanitize
   }%
}
%    \end{macrocode}
%\end{macro}
%
%Option to switch on the UTF-8 sanitization (irrespective of engine):
%    \begin{macrocode}
\DeclareOption{sanitize}{\testidxSanitizeOn}
%    \end{macrocode}
%
%Option to switch off the UTF-8 sanitization (irrespective of engine):
%    \begin{macrocode}
\DeclareOption{nosanitize}{\testidxSanitizeOff}
%    \end{macrocode}
%
%Option to show the actual indexing argument.
%\begin{macro}{\iftestidxverbose}
%    \begin{macrocode}
\newif\iftestidxverbose
\testidxverbosefalse
\DeclareOption{verbose}{\testidxverbosetrue}
\DeclareOption{noverbose}{\testidxverbosefalse}
%    \end{macrocode}
%\end{macro}
%
%Option to hide the markers.
%\begin{macro}{\iftestidxshowmarks}
%    \begin{macrocode}
\newif\iftestidxshowmarks
\testidxshowmarkstrue
\DeclareOption{showmarks}{\testidxshowmarkstrue}
\DeclareOption{noshowmarks}{\testidxshowmarksfalse}
\DeclareOption{hidemarks}{\testidxshowmarksfalse}
%    \end{macrocode}
%\end{macro}
%
%Option to skip the test encaps.
%\begin{macro}{\if@tstidx@use@encaps}
%    \begin{macrocode}
\newif\if@tstidx@use@encaps
\@tstidx@use@encapstrue
\DeclareOption{testencaps}{\@tstidx@use@encapstrue}
\DeclareOption{notestencaps}{\@tstidx@use@encapsfalse}
%    \end{macrocode}
%\end{macro}
%
%Process options:
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%Find out if various packages have been loaded.
%\begin{macro}{\@tstidx@ifamsmath}
%    \begin{macrocode}
\AtBeginDocument{%
  \@ifpackageloaded{amsmath}%
  {\let\@tstidx@ifamsmath\@firstoftwo}%
  {\let\@tstidx@ifamsmath\@secondoftwo}%
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\@tstidx@ifinputenc}
%    \begin{macrocode}
  \@ifpackageloaded{inputenc}
  {
    \let\@tstidx@if@inputenc\@firstoftwo
  }%
  {%
    \ifxetex
      \let\@tstidx@if@inputenc\@firstoftwo
    \else
      \ifluatex
        \let\@tstidx@if@inputenc\@firstoftwo
      \else
        \let\@tstidx@if@inputenc\@secondoftwo
      \fi
    \fi
  }%
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\@tstidx@if@notOT@ne}
% Some of the accent commands don't work with the default OT1
% encoding, so provide a convenient test.
%    \begin{macrocode}
  \ifxetex
    \let\@tstidx@if@notOT@ne\@firstoftwo
  \else
    \ifluatex
      \let\@tstidx@if@notOT@ne\@firstoftwo
    \else
      \newcommand*{\@tstidx@OT@ne}{OT1}%
      \edef\@tstidx@enc{\encodingdefault}%
      \ifx\@tstidx@OT@ne\@tstidx@enc
        \let\@tstidx@if@notOT@ne\@secondoftwo
      \else
        \let\@tstidx@if@notOT@ne\@firstoftwo
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%\section{Markup Commands}
% String is used in case any of these characters have been made
% active.
%\begin{macro}{\tstidxactual}
%Actual character.
%    \begin{macrocode}
\newcommand{\tstidxactual}{\string @}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxlevel}
%Level character.
%    \begin{macrocode}
\newcommand{\tstidxlevel}{\string!}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxencap}
%Encap character.
%    \begin{macrocode}
\newcommand{\tstidxencap}{\string|}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxopenrange}
%Start range character.
%    \begin{macrocode}
\newcommand{\tstidxopenrange}{\string(}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxcloserange}
%End range character.
%    \begin{macrocode}
\newcommand{\tstidxcloserange}{\string)}
%    \end{macrocode}
%\end{macro}
%Some of the examples use words with extended Latin characters.
%Provide a way of simulating the user explicitly writing, for
%example, \verb|\index{\""Angelholm}|.
%\begin{macro}{\tstidxprocessascii}
%The first argument is a control sequence in which to store the
%processed string.
%    \begin{macrocode}
\newcommand*{\tstidxprocessascii}[2]{%
  {%
    \let\"\tstidxumlaut
    \def\'{\string\'}%
    \def\`{\string\`}%
    \def\.{\string\.}%
    \def\={\string\=}%
    \def\^{\string\^}%
    \def\~{\string\~}%
    \def\c{\string\c}%
    \def\r{\string\r}%
    \def\b{\string\b}%
    \def\d{\string\d}%
    \def\H{\string\H}%
    \def\k{\string\k}%
    \def\u{\string\u}%
    \def\v{\string\v}%
    \def\O{\string\O\space}%
    \def\o{\string\o\space}%
    \def\l{\string\l\space}%
    \def\L{\string\L\space}%
    \def\i{\string\i\space}%
    \def\AA{\string\AA\space}%
    \def\aa{\string\aa\space}%
    \def\ae{\string\ae\space}%
    \def\AE{\string\AE\space}%
    \def\oe{\string\oe\space}%
    \def\OE{\string\OE\space}%
    \def\ss{\string\ss\space}%
    \def\SS{\string\SS\space}%
    \def\th{\string\th\space}%
    \def\TH{\string\TH\space}%
    \def\dh{\string\dh\space}%
    \def\DH{\string\DH\space}%
    \def\dj{\string\dj\space}%
    \def\DJ{\string\DJ\space}%
    \def\ng{\string\ng\space}%
    \def\NG{\string\NG\space}%
    \protected@xdef#1{#2}%
  }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxprocessasciisortnostrip}
%    \begin{macrocode}
\newcommand*{\tstidxprocessasciisortnostrip}[2]{%
  {%
    \let\"\tstidxsortumlaut
    \protected@xdef#1{#2}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxprocessasciisortstrip}
%    \begin{macrocode}
\newcommand*{\tstidxprocessasciisortstrip}[2]{%
  {%
    \let\"\tstidxsortumlautstrip
    \let\'\@firstofone
    \let\`\@firstofone
    \let\.\@firstofone
    \let\=\@firstofone
    \let\^\@firstofone
    \let\~\@firstofone
    \let\c\@firstofone
    \let\r\@firstofone
    \let\b\@firstofone
    \let\d\@firstofone
    \let\H\@firstofone
    \let\k\@firstofone
    \let\u\@firstofone
    \let\v\@firstofone
    \def\O{O}%
    \def\o{o}%
    \def\l{l}%
    \def\L{L}%
    \def\i{i}%
    \def\AA{A}%
    \def\aa{a}%
    \def\ae{ae}%
    \def\AE{AE}%
    \def\oe{oe}%
    \def\OE{OE}%
    \def\ss{ss}%
    \def\SS{SS}%
    \def\th{th}%
    \def\TH{TH}%
    \def\dh{dh}%
    \def\DH{DH}%
    \def\dj{dj}%
    \def\DJ{DJ}%
    \def\ng{ng}%
    \def\NG{NG}%
    \protected@xdef#1{#2}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxprocessutfsanitize}
%Sanitize UTF-8 strings.
%    \begin{macrocode}
\newcommand*{\tstidxprocessutfsanitize}[2]{%
  \def#1{#2}%
  \@onelevel@sanitize#1%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxprocessutfnosanitize}
%Don't sanitize UTF-8 strings.
%    \begin{macrocode}
\newcommand*{\tstidxprocessutfnosanitize}[2]{%
  \def#1{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%
%\begin{macro}{\tstidxencaptext}
% Wrap text in the command corresponding to the given encap.
%    \begin{macrocode}
\newcommand*{\tstidxencaptext}[2]{%
  \@ifundefined{#1}%
  {%
    \PackageError{testidx}{Encap value `#1' doesn't correspond
    to a known command}{}%
  }%
  {%
    \csname#1\endcsname{#2}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxtext}
%Identify text next to the index command. This will also be wrapped
%around the encap value if supplied.
%    \begin{macrocode}
\newcommand*{\tstidxtext}[1]{\textcolor[gray]{0.3}{#1}}
%    \end{macrocode}
%\end{macro}
%
%Provide three different encap values for testing:
%\begin{macro}{\tstidxencapi}
%    \begin{macrocode}
\newcommand*{\tstidxencapi}[1]{\textcolor{blue}{#1}}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxencapii}
%    \begin{macrocode}
\newcommand*{\tstidxencapii}[1]{\textcolor{cyan}{#1}}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxencapiii}
%    \begin{macrocode}
\newcommand*{\tstidxencapiii}[1]{\textcolor{magenta}{#1}}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxensuretext}
%Ensure in text mode.
%    \begin{macrocode}
\newcommand*{\tstidxensuretext}[1]{%
 \ifmmode
  \@tstidx@ifamsmath{\text{#1}}{\mbox{#1}}%
 \else
  #1%
 \fi
}
%    \end{macrocode}
%\end{macro}
%Markers to show where the \cs{index} commands are used.
%Preferable to have markers that adjust to font size, and only use
%commands provided by \LaTeX\ kernel to reduce package requirements.
%\begin{macro}{\tstidxmarker}
%No range or cross-reference. I initially used
%\cs{textperiodcentered} for the marker, but some fonts make it a
%bit too spacey for this purpose.
%    \begin{macrocode}
\newcommand*{\tstidxmarker}{%
 \tstidxensuretext{\raisebox{.65ex}{.}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxsubmarker}
%Sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxsubmarker}{%
 \tstidxensuretext{\strut\smash{\raisebox{-1.5ex}{\v{}}}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxsubsubmarker}
%Sub-sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxsubsubmarker}{%
 \tstidxensuretext{\strut\makebox[0pt][l]{\smash{\raisebox{-1ex}{\v{}}}}%
 \smash{\raisebox{-1.5ex}{\v{}}}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxopenmarker}
%Start of a range.
%    \begin{macrocode}
\newcommand*{\tstidxopenmarker}{%
  \tstidxensuretext
  {%
   \setlength{\unitlength}{1ex}%
   \begin{picture}(.5,2)
   \put(\@halfwidth\@gobble,0){\line(0,1){2}}
   \put(0,2){\line(1,0){.5}}
   \end{picture}%
   \hspace{\@halfwidth}%
 }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxclosemarker}
%End of a range.
%    \begin{macrocode}
\newcommand*{\tstidxclosemarker}{%
  \tstidxensuretext
  {%
   \setlength{\unitlength}{1ex}%
   \begin{picture}(.5,2)
   \put(\@halfwidth\@gobble,0){\line(1,0){.5}}
   \put(.5,0){\line(0,1){2}}
   \end{picture}%
   \hspace{\@halfwidth}%
 }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxopensubmarker}
%Start of a range for sub-entries.
%    \begin{macrocode}
\newcommand*{\tstidxopensubmarker}{%
 \tstidxensuretext
 {%
   \setlength{\unitlength}{1ex}%
   \begin{picture}(.4,1.6)
   \put(\@halfwidth\@gobble,0){\line(0,1){1.6}}
   \put(0,1.6){\line(1,0){.4}}
   \end{picture}%
   \hspace{\@halfwidth}%
 }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxclosesubmarker}
%End of a range for sub-entries.
%    \begin{macrocode}
\newcommand*{\tstidxclosesubmarker}{%
 \tstidxensuretext
 {%
   \setlength{\unitlength}{1ex}%
   \begin{picture}(.4,1.6)
   \put(\@halfwidth\@gobble,0){\line(1,0){.4}}
   \put(.4,0){\line(0,1){1.6}}
   \end{picture}%
   \hspace{\@halfwidth}%
 }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxopensubsubmarker}
%Start of a range for sub-sub-entries.
%    \begin{macrocode}
\newcommand*{\tstidxopensubsubmarker}{%
 \tstidxensuretext
 {%
   \setlength{\unitlength}{1ex}%
   \begin{picture}(.3,1.2)
   \put(\@halfwidth\@gobble,0){\line(0,1){1.2}}
   \put(0,1.2){\line(1,0){.3}}
   \end{picture}%
   \hspace{\@halfwidth}%
 }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxclosesubsubmarker}
%End of a range for sub-sub-entries.
%    \begin{macrocode}
\newcommand*{\tstidxclosesubsubmarker}{%
 \tstidxensuretext
 {%
   \setlength{\unitlength}{1ex}%
   \begin{picture}(.3,1.2)
   \put(\@halfwidth\@gobble,0){\line(1,0){.3}}
   \put(.3,0){\line(0,1){1.2}}
   \end{picture}%
   \hspace{\@halfwidth}%
 }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxseemarker}
%Cross-reference.
%    \begin{macrocode}
\newcommand*{\tstidxseemarker}{\^{}}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxseeref}
%Cross-references are identified with the marker and with a marginal
%note with the term being indexed and the argument of the \qt{see} encap.
%    \begin{macrocode}
\newcommand*{\tstidxseeref}[3]{\tstidxseemarker
 \marginpar{\strut\raggedright\footnotesize
   \normalcolor\tstidxseemarker#1, \csname#2\endcsname{#3}{}}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxsubseemarker}
%Cross-reference.
%    \begin{macrocode}
\newcommand*{\tstidxsubseemarker}{%
 \tstidxensuretext{\makebox[0pt][l]{\tstidxsubmarker}%
 \tstidxseemarker}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxsubseeref}
%Cross-references are identified with the marker and with a marginal
%note with the term being indexed and the argument of the \qt{see} encap.
%    \begin{macrocode}
\newcommand*{\tstidxsubseeref}[4]{\tstidxsubseemarker
 \marginpar{\strut\raggedright\footnotesize
   \normalcolor\tstidxsubseemarker#1\tstidxsubseesep#2, \csname#3\endcsname{#4}{}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxsubseesep}
%Separator used in the above.
%    \begin{macrocode}
\newcommand*{\tstidxsubseesep}{\,$\triangleright$\,}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindex}
% Allow user to change \cs{index} to something else. For example,
% add an optional argument if multiple indexes are present.
%    \begin{macrocode}
\newcommand*{\tstindex}{\index}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\@tstindex}
%    \begin{macrocode}
\newcommand*{\@tstindex}[1]{%
  \iftestidxverbose
   \def\@tstindex@arg{#1}%
   \@onelevel@sanitize\@tstindex@arg
   \testidxverbosefmt{\@tstindex@arg}%
  \fi
  \tstindex{#1}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\testidxverbosefmt}
%    \begin{macrocode}
\newcommand*{\testidxverbosefmt}[1]{%
  \expandafter\def\expandafter\@tstidx@tmp\expandafter{\tstindex}%
  \@onelevel@sanitize\@tstidx@tmp
  \tstidxensuretext{%
    \discretionary{}{}{}%
    {\footnotesize\texttt{\@tstidx@tmp
     \expandafter\@gobble\string\{#1\expandafter\@gobble\string\}}}%
    \discretionary{}{}{}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxqt}
%Nothing to do with indexing, but just provides semantic markup for
%quotes.
%    \begin{macrocode}
\newcommand*{\tstidxqt}[1]{``#1''}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxdash}
%    \begin{macrocode}
\newcommand*{\tstidxdash}{\,---\,}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxfootnote}
%    \begin{macrocode}
\newcommand*{\tstidxfootnote}{\footnote}
%    \end{macrocode}
%\end{macro}
%
%\section{Convenience Commands}
%These commands are provided for conveniently marking various
%aspects of the dummy text.
%\begin{macro}{\tstidxfmtpost}
%\begin{definition}
%\cs{tstidxfmtpost}\marg{text}\marg{fmt cs}\marg{encap}
%\end{definition}
%Index an entry that needs a formatting command.
%    \begin{macrocode}
\newcommand*{\tstidxfmtpost}[3]{%
  \tstindexpost[#1]{\protect#2{#1}}{#3}{#2{#1}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxfmtopenpost}
%\begin{definition}
%\cs{tstidxfmtopenpost}\marg{text}\marg{fmt cs}\marg{encap}
%\end{definition}
%Index an entry that needs a formatting command.
%    \begin{macrocode}
\newcommand*{\tstidxfmtopenpost}[3]{%
  \tstindexopenpost[#1]{\protect#2{#1}}{#3}{#2{#1}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxfmtclosepost}
%\begin{definition}
%\cs{tstidxfmtclosepost}\marg{text}\marg{fmt cs}\marg{encap}
%\end{definition}
%Index an entry that needs a formatting command.
%    \begin{macrocode}
\newcommand*{\tstidxfmtclosepost}[3]{%
  \tstindexclosepost[#1]{\protect#2{#1}}{#3}{#2{#1}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxfmtpre}
%\begin{definition}
%\cs{tstidxfmtpre}\marg{text}\marg{fmt cs}\marg{encap}
%\end{definition}
%Index an entry that needs a formatting command.
%    \begin{macrocode}
\newcommand*{\tstidxfmtpre}[3]{%
  \tstindexpre[#1]{\protect#2{#1}}{#3}{#2{#1}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxfmtopenpre}
%\begin{definition}
%\cs{tstidxfmtopenpre}\marg{text}\marg{fmt cs}\marg{encap}
%\end{definition}
%Index an entry that needs a formatting command.
%    \begin{macrocode}
\newcommand*{\tstidxfmtopenpre}[3]{%
  \tstindexopenpre[#1]{\protect#2{#1}}{#3}{#2{#1}}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxfmtclosepre}
%\begin{definition}
%\cs{tstidxfmtclosepre}\marg{text}\marg{fmt cs}\marg{encap}
%\end{definition}
%Index an entry that needs a formatting command.
%    \begin{macrocode}
\newcommand*{\tstidxfmtclosepre}[3]{%
  \tstindexclosepre[#1]{\protect#2{#1}}{#3}{#2{#1}}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutf}
%\begin{definition}
%\cs{tstidxutf}\marg{display}\marg{ascii}\marg{utf8}\marg{encap}\marg{idx cs}
%\end{definition}
%Index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutf}[5]{%
  \def\@tstidx@text{#1}%
  \@tstidx@ifutfviii
  {%
    \ifx\@tstidx@text\@empty
      \def\@tstidx@text{#3}%
    \fi
    \tstidxprocessutf{\@tstidx@utf}{#3}%
    \protected@edef\@tstidx@doidx{%
      \noexpand#5{\unexpanded\expandafter{\@tstidx@utf}}{#4}%
        {\@tstidx@text}%
    }%
  }%
  {%
    \ifx\@tstidx@text\@empty
      \def\@tstidx@text{#2}%
    \fi
    \tstidxprocessascii{\@tstidx@ascii}{#2}%
    \tstidxprocessasciisort{\@tstidx@asciisort}{#2}%
    \protected@edef\@tstidx@doidx{%
      \noexpand#5[\unexpanded\expandafter{\@tstidx@asciisort}]%
        {\unexpanded\expandafter{\@tstidx@ascii}}{#4}%
        {\@tstidx@text}%
    }%
  }%
  \@tstidx@doidx
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxsubutf}
%\begin{definition}
%\cs{tstidxsubutf}\marg{display}\marg{ascii}\marg{utf8}\marg{sub-ascii}\marg{sub-utf8}\marg{encap}\marg{idx cs}
%\end{definition}
%First level sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxsubutf}[7]{%
  \def\@tstidx@text{#1}%
  \@tstidx@ifutfviii
  {%
    \ifx\@tstidx@text\@empty
      \def\@tstidx@text{#3}%
    \fi
    \tstidxprocessutf{\@tstidx@utf}{#3}%
    \tstidxprocessutf{\@tstidx@subutf}{#5}%
    \protected@edef\@tstidx@doidx{%
      \noexpand#7{\unexpanded\expandafter{\@tstidx@utf}}%
        {\unexpanded\expandafter{\@tstidx@subutf}}%
        {#6}%
        {\@tstidx@text}%
    }%
  }%
  {%
    \ifx\@tstidx@text\@empty
      \def\@tstidx@text{#2}%
    \fi
    \tstidxprocessascii{\@tstidx@ascii}{#2}%
    \tstidxprocessasciisort{\@tstidx@asciisort}{#2}%
    \tstidxprocessascii{\@tstidx@subascii}{#4}%
    \tstidxprocessasciisort{\@tstidx@subasciisort}{#4}%
    \protected@edef\@tstidx@doidx{%
      \noexpand#7[\unexpanded\expandafter{\@tstidx@asciisort}]%
        {\unexpanded\expandafter{\@tstidx@ascii}}%
        [\unexpanded\expandafter{\@tstidx@subasciisort}]%
        {\unexpanded\expandafter{\@tstidx@subascii}}%
        {#6}%
        {\@tstidx@text}%
    }%
  }%
  \@tstidx@doidx
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfpost}
%\begin{definition}
%\cs{tstidxutfpost}\oarg{display}\marg{ascii}\marg{utf8}\marg{encap}
%\end{definition}
%Index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfpost}[4][]{%
  \tstidxutf{#1}{#2}{#3}{#4}{\tstindexpost}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfopenpost}
%\begin{definition}
%\cs{tstidxutfopenpost}\oarg{display}\marg{ascii}\marg{utf8}\marg{encap}
%\end{definition}
%Index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfopenpost}[4][]{%
  \tstidxutf{#1}{#2}{#3}{#4}{\tstindexopenpost}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfclosepost}
%\begin{definition}
%\cs{tstidxutfclosepost}\oarg{display}\marg{ascii}\marg{utf8}\marg{encap}
%\end{definition}
%Index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfclosepost}[4][]{%
  \tstidxutf{#1}{#2}{#3}{#4}{\tstindexclosepost}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfpre}
%\begin{definition}
%\cs{tstidxutfpre}\oarg{display}\marg{ascii}\marg{utf8}\marg{encap}
%\end{definition}
%Index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfpre}[4][]{%
  \tstidxutf{#1}{#2}{#3}{#4}{\tstindexpre}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfopenpre}
%\begin{definition}
%\cs{tstidxutfopenpre}\oarg{display}\marg{ascii}\marg{utf8}\marg{encap}
%\end{definition}
%Index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfopenpre}[4][]{%
  \tstidxutf{#1}{#2}{#3}{#4}{\tstindexopenpre}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfclosepre}
%\begin{definition}
%\cs{tstidxutfclosepre}\oarg{display}\marg{ascii}\marg{utf8}\marg{encap}
%\end{definition}
%Index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfclosepre}[4][]{%
  \tstidxutf{#1}{#2}{#3}{#4}{\tstindexclosepre}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfsubpost}
%\begin{definition}
%\cs{tstidxutfsubpost}\oarg{display}\marg{ascii}\marg{utf8}\marg{sub-ascii}\marg{sub-utf8}\marg{encap}
%\end{definition}
%Sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxutfsubpost}[6][]{%
  \tstidxsubutf{#1}{#2}{#3}{#4}{#5}{#6}{\tstsubindexpost}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfsubopenpost}
%\begin{definition}
%\cs{tstidxutfsubopenpost}\oarg{display}\marg{ascii}\marg{utf8}\marg{sub-ascii}\marg{sub-utf8}\marg{encap}
%\end{definition}
%Sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxutfsubopenpost}[6][]{%
  \tstidxsubutf{#1}{#2}{#3}{#4}{#5}{#6}{\tstsubindexopenpost}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfsubclosepost}
%\begin{definition}
%\cs{tstidxutfsubclosepost}\oarg{display}\marg{ascii}\marg{utf8}\marg{sub-ascii}\marg{sub-utf8}\marg{encap}
%\end{definition}
%Sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxutfsubclosepost}[6][]{%
  \tstidxsubutf{#1}{#2}{#3}{#4}{#5}{#6}{\tstsubindexclosepost}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfsubpre}
%\begin{definition}
%\cs{tstidxutfsubpre}\oarg{display}\marg{ascii}\marg{utf8}\marg{sub-ascii}\marg{sub-utf8}\marg{encap}
%\end{definition}
%Sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxutfsubpre}[6][]{%
  \tstidxsubutf{#1}{#2}{#3}{#4}{#5}{#6}{\tstsubindexpre}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfsubopenpre}
%\begin{definition}
%\cs{tstidxutfsubopenpre}\oarg{display}\marg{ascii}\marg{utf8}\marg{sub-ascii}\marg{sub-utf8}\marg{encap}
%\end{definition}
%Sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxutfsubopenpre}[6][]{%
  \tstidxsubutf{#1}{#2}{#3}{#4}{#5}{#6}{\tstsubindexopenpre}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfsubclosepre}
%\begin{definition}
%\cs{tstidxutfsubclosepre}\oarg{display}\marg{ascii}\marg{utf8}\marg{sub-ascii}\marg{sub-utf8}\marg{encap}
%\end{definition}
%Sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxutfsubclosepre}[6][]{%
  \tstidxsubutf{#1}{#2}{#3}{#4}{#5}{#6}{\tstsubindexclosepre}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcsfmt}
% Display a control sequence.
%    \begin{macrocode}
\newcommand*{\tstidxcsfmt}[1]{\texttt{\char`\\#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcs}
% Display and index a control sequence. The optional argument is the encap
%    \begin{macrocode}
\if@tstidx@use@encaps
 \newcommand*{\tstidxcs}[2][tstidxencapi]{%
   \tstidxfmtpost{#2}{\tstidxcsfmt}{#1}%
 }
\else
 \newcommand*{\tstidxcs}[2][]{%
   \tstidxfmtpost{#2}{\tstidxcsfmt}{#1}%
 }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopencs}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopencs}[2][tstidxencapi]{%
    \tstidxfmtopenpost{#2}{\tstidxcsfmt}{#1}%
  }
\else
  \newcommand*{\tstidxopencs}[2][]{%
    \tstidxfmtopenpost{#2}{\tstidxcsfmt}{#1}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosecs}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxclosecs}[2][tstidxencapi]{%
    \tstidxfmtclosepost{#2}{\tstidxcsfmt}{#1}%
  }
\else
  \newcommand*{\tstidxclosecs}[2][]{%
    \tstidxfmtclosepost{#2}{\tstidxcsfmt}{#1}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxencapcsn}
% Display and index a control sequence name (without the initial
% backslash). The optional argument is the encap
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxencapcsn}[2][tstidxencapi]{%
    \tstindexpost[#2 (#2)]%
    {\texttt{#2} (\protect\tstidxcsfmt{#2})}{#1}{\texttt{#2}}%
    \tstsubindexpost{encap}[#2]{\texttt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxencapcsn}[2][]{%
    \tstindexpost[#2 (#2)]%
    {\texttt{#2} (\protect\tstidxcsfmt{#2})}{#1}{\texttt{#2}}%
    \tstsubindexpost{encap}[#2]{\texttt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopencsn}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopencsn}[2][tstidxencapi]{%
    \tstindexopenpost[#2 (#2)]%
    {\texttt{#2} (\protect\tstidxcsfmt{#2})}{#1}{\texttt{#2}}%
  }
\else
  \newcommand*{\tstidxopencsn}[2][]{%
    \tstindexopenpost[#2 (#2)]%
    {\texttt{#2} (\protect\tstidxcsfmt{#2})}{#1}{\texttt{#2}}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosecsn}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxclosecsn}[2][tstidxencapi]{%
    \tstindexclosepost[#2 (#2)]%
    {\texttt{#2} (\protect\tstidxcsfmt{#2})}{#1}{\texttt{#2}}%
  }
\else
  \newcommand*{\tstidxclosecsn}[2][]{%
    \tstindexclosepost[#2 (#2)]%
    {\texttt{#2} (\protect\tstidxcsfmt{#2})}{#1}{\texttt{#2}}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxenvfmt}
% Display an environment name.
%    \begin{macrocode}
\newcommand*{\tstidxenvfmt}[1]{\texttt{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxenv}
% Display and index an environment name.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxenv}[2][tstidxencapi]{%
    \tstindexpost[#2 environment]%
    {\protect\tstidxenvfmt{#2} environment}{#1}%
    {\tstidxenvfmt{#2}}%
  }
\else
  \newcommand*{\tstidxenv}[2][]{%
    \tstindexpost[#2 environment]%
    {\protect\tstidxenvfmt{#2} environment}{#1}%
    {\tstidxenvfmt{#2}}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenenv}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopenenv}[2][tstidxencapi]{%
    \tstindexopenpost[#2 environment]%
    {\protect\tstidxenvfmt{#2} environment}{#1}%
    {\tstidxenvfmt{#2}}%
  }
\else
  \newcommand*{\tstidxopenenv}[2][]{%
    \tstindexopenpost[#2 environment]%
    {\protect\tstidxenvfmt{#2} environment}{#1}%
    {\tstidxenvfmt{#2}}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseenv}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxcloseenv}[2][tstidxencapi]{%
    \tstindexclosepost[#2 environment]%
    {\protect\tstidxenvfmt{#2} environment}{#1}%
    {\tstidxenvfmt{#2}}%
  }
\else
  \newcommand*{\tstidxcloseenv}[2][]{%
    \tstindexclosepost[#2 environment]%
    {\protect\tstidxenvfmt{#2} environment}{#1}%
    {\tstidxenvfmt{#2}}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxappfmt}
% Display an application name.
%    \begin{macrocode}
\newcommand*{\tstidxappfmt}[1]{\texttt{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxapp}
% Display and index an application name.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxapp}[2][tstidxencapi]{%
    \tstidxfmtpost{#2}{\tstidxappfmt}{#1}%
    \tstsubindexpost{applications}[#2]{\protect\tstidxappfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxapp}[2][]{%
    \tstidxfmtpost{#2}{\tstidxappfmt}{#1}%
    \tstsubindexpost{applications}[#2]{\protect\tstidxappfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenapp}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopenapp}[2][tstidxencapi]{%
    \tstidxfmtopenpost{#2}{\tstidxappfmt}{#1}%
    \tstsubindexopenpost{applications}[#2]{\protect\tstidxappfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxopenapp}[2][]{%
    \tstidxfmtopenpost{#2}{\tstidxappfmt}{#1}%
    \tstsubindexopenpost{applications}[#2]{\protect\tstidxappfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseapp}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxcloseapp}[2][tstidxencapi]{%
    \tstidxfmtclosepost{#2}{\tstidxappfmt}{#1}%
    \tstsubindexclosepost{applications}[#2]{\protect\tstidxappfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxcloseapp}[2][]{%
    \tstidxfmtclosepost{#2}{\tstidxappfmt}{#1}%
    \tstsubindexclosepost{applications}[#2]{\protect\tstidxappfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxappoptfmt}
% Display an application option.
%    \begin{macrocode}
\newcommand*{\tstidxappoptfmt}[1]{\texttt{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxappopt}
% Display and index an application option.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxappopt}[3][tstidxencapiii]{%
    \tstsubindexpost[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{\tstidxappoptfmt{#3}}%
    \tstsubsubindexpost{applications}[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{}%
  }
\else
  \newcommand*{\tstidxappopt}[3][]{%
    \tstsubindexpost[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{\tstidxappoptfmt{#3}}%
    \tstsubsubindexpost{applications}[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenappopt}
% As above but start a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopenappopt}[3][tstidxencapiii]{%
    \tstsubindexopenpost[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{\tstidxappoptfmt{#3}}%
    \tstsubsubindexopenpost{applications}[#2]%
      {\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{}%
  }
\else
  \newcommand*{\tstidxopenappopt}[3][]{%
    \tstsubindexopenpost[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{\tstidxappoptfmt{#3}}%
    \tstsubsubindexopenpost{applications}[#2]%
      {\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseappopt}
% As above but end a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxcloseappopt}[3][tstidxencapiii]{%
    \tstsubindexclosepost[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{\tstidxappoptfmt{#3}}%
    \tstsubsubindexclosepost{applications}[#2]%
      {\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{}%
  }
\else
  \newcommand*{\tstidxcloseappopt}[3][]{%
    \tstsubindexclosepost[#2]{\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{\tstidxappoptfmt{#3}}%
    \tstsubsubindexclosepost{applications}[#2]%
      {\protect\tstidxappfmt{#2}}%
      [#3]{\protect\tstidxappoptfmt{#3}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxstyfmt}
% Display a package name.
%    \begin{macrocode}
\newcommand*{\tstidxstyfmt}[1]{\texttt{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxsty}
% Display and index a package name.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxsty}[2][tstidxencapiii]{%
    \tstindexpost[#2 package]%
     {\protect\tstidxstyfmt{#2} package}{#1}{\tstidxstyfmt{#2}}%
    \tstsubindexpost{packages}[#2 package]%
     {\protect\tstidxstyfmt{#2} package}{#1}{}%
  }
\else
  \newcommand*{\tstidxsty}[2][]{%
    \tstindexpost[#2 package]%
     {\protect\tstidxstyfmt{#2} package}{#1}{\tstidxstyfmt{#2}}%
    \tstsubindexpost{packages}[#2 package]%
     {\protect\tstidxstyfmt{#2} package}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopensty}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopensty}[2][tstidxencapiii]{%
    \tstindexopenpost[#2 package]{\protect\tstidxstyfmt{#2} package}{#1}%
      {\tstidxstyfmt{#2}}%
    \tstsubindexopenpost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}{#1}{}%
  }
\else
  \newcommand*{\tstidxopensty}[2][]{%
    \tstindexopenpost[#2 package]{\protect\tstidxstyfmt{#2} package}{#1}%
      {\tstidxstyfmt{#2}}%
    \tstsubindexopenpost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosesty}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxclosesty}[2][tstidxencapiii]{%
    \tstindexclosepost[#2 package]{\protect\tstidxstyfmt{#2} package}{#1}%
     {\tstidxstyfmt{#2}}%
    \tstsubindexclosepost{packages}[#2 package]%
     {\protect\tstidxstyfmt{#2} package}{#1}{}%
  }
\else
  \newcommand*{\tstidxclosesty}[2][]{%
    \tstindexclosepost[#2 package]{\protect\tstidxstyfmt{#2} package}{#1}%
     {\tstidxstyfmt{#2}}%
    \tstsubindexclosepost{packages}[#2 package]%
     {\protect\tstidxstyfmt{#2} package}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxstyoptfmt}
% Display a package option.
%    \begin{macrocode}
\newcommand*{\tstidxstyoptfmt}[1]{\texttt{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxstyopt}
% Display and index a package option.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxstyopt}[3][tstidxencapiii]{%
    \tstsubindexpost[#2 package]{\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{\tstidxstyoptfmt{#3}}%
    \tstsubsubindexpost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{}%
  }
\else
  \newcommand*{\tstidxstyopt}[3][]{%
    \tstsubindexpost[#2 package]{\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{\tstidxstyoptfmt{#3}}%
    \tstsubsubindexpost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenstyopt}
% As above but start a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopenstyopt}[3][tstidxencapiii]{%
    \tstsubindexopenpost[#2 package]{\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{\tstidxstyoptfmt{#3}}%
    \tstsubsubindexopenpost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{}%
  }
\else
  \newcommand*{\tstidxopenstyopt}[3][]{%
    \tstsubindexopenpost[#2 package]{\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{\tstidxstyoptfmt{#3}}%
    \tstsubsubindexopenpost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosestyopt}
% As above but end a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxclosestyopt}[3][tstidxencapiii]{%
    \tstsubindexclosepost[#2 package]{\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{\tstidxstyoptfmt{#3}}%
    \tstsubsubindexclosepost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{}%
  }
\else
  \newcommand*{\tstidxclosestyopt}[3][]{%
    \tstsubindexclosepost[#2 package]{\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{\tstidxstyoptfmt{#3}}%
    \tstsubsubindexclosepost{packages}[#2 package]%
      {\protect\tstidxstyfmt{#2} package}%
      [#3]{\protect\tstidxstyoptfmt{#3}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxword}
% Display and index a word.
%    \begin{macrocode}
\newcommand*{\tstidxword}[2][]{%
  \tstindexpost{#2}{#1}{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenword}
% As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxopenword}[2][]{%
  \tstindexopenpost{#2}{#1}{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseword}
% As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxcloseword}[2][]{%
  \tstindexclosepost{#2}{#1}{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxsubword}
%\begin{definition}
%\cs{tstidxsubword}\oarg{encap}\marg{main-entry}\marg{word}
%\end{definition}
% Display and index a word as a sub-entry.
%    \begin{macrocode}
\newcommand*{\tstidxsubword}[3][]{%
  \tstsubindexpost{#2}{#3}{#1}{#3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxnumber}
% Display and index a word.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxnumber}[2][tstidxencapiii]{%
    \tstindexpost{#2}{#1}{#2}%
  }
\else
  \newcommand*{\tstidxnumber}[2][]{%
    \tstindexpost{#2}{#1}{#2}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxphrase}
% Display and index a phrase.
%    \begin{macrocode}
\newcommand*{\tstidxphrase}[2][]{%
  \tstindexpre{#2}{#1}{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenphrase}
% As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxopenphrase}[2][]{%
  \tstindexopenpre{#2}{#1}{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosephrase}
% As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxclosephrase}[2][]{%
  \tstindexclosepre{#2}{#1}{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxartphrase}
%\begin{definition}
%\cs{tstidxartphrase}\oarg{encap}\marg{article}\marg{remainder}
%\end{definition}
% Display and index a phrase that starts with (in)definite
% article.
%    \begin{macrocode}
\newcommand*{\tstidxartphrase}[3][]{%
  \tstindexpost{#3, #2}{#1}{#2 #3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenartphrase}
%As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxopenartphrase}[3][]{%
  \tstindexopenpost{#3, #2}{#1}{#2 #3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseartphrase}
%As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxcloseartphrase}[3][]{%
  \tstindexclosepost{#3, #2}{#1}{#2 #3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxperson}
% Display and index a person's name.
%    \begin{macrocode}
\newcommand*{\tstidxperson}[3][]{%
  \tstidxutfperson[#1]{#2}{#3}{#2}{#3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenperson}
% As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxopenperson}[3][]{%
  \tstidxutfopenperson[#1]{#2}{#3}{#2}{#3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseperson}
% As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxcloseperson}[3][]{%
  \tstidxutfcloseperson[#1]{#2}{#3}{#2}{#3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfperson}
%\begin{definition}
%\cs{tstidxutfperson}\oarg{encap}\marg{ascii forename}\marg{ascii surname}\marg{utf8 forname}{utf8 surname}
%\end{definition}
% Display and index a person's name with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfperson}[5][]{%
  \@tstidx@ifutfviii
  {%
    \tstidxutfpost[#4 #5]{#3, #2}{#5, #4}{#1}%
  }%
  {%
    \tstidxutfpost[#2 #3]{#3, #2}{#5, #4}{#1}%
  }%
  \tstidxutfsubpost[\relax]{people}{people}{#3, #2}{#5, #4}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenutfperson}
% As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxutfopenperson}[5][]{%
  \@tstidx@ifutfviii
  {%
    \tstidxutfopenpost[#4 #5]{#3, #2}{#5, #4}{#1}%
  }%
  {%
    \tstidxutfopenpost[#2 #3]{#3, #2}{#5, #4}{#1}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseutfperson}
% As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxutfcloseperson}[7][]{%
  \@tstidx@ifutfviii
  {%
    \tstidxutfclosepost[#4 #5]{#3, #2}{#5, #4}{#1}%
  }%
  {%
    \tstidxutfclosepost[#2 #3]{#3, #2}{#5, #4}{#1}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxsym}
%\begin{definition}
%\cs{tstidxsym}\oarg{encap}\marg{sort}\marg{indexed symbol}
%\end{definition}
% Display and index a symbol.
%    \begin{macrocode}
\newcommand*{\tstidxsym}[3][]{%
  \tstindexpost[#2]{\protect#3}{#1}{#3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopensym}
%\begin{definition}
%\cs{tstidxopensym}\oarg{encap}\marg{sort}\marg{indexed symbol}
%\end{definition}
% As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxopensym}[3][]{%
  \tstindexopenpost[#2]{\protect#3}{#1}{#3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosesym}
%\begin{definition}
%\cs{tstidxclosesym}\oarg{encap}\marg{sort}\marg{indexed symbol}
%\end{definition}
% As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxclosesym}[3][]{%
  \tstindexopenpost[#2]{\protect#3}{#1}{#3}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxindexmarker}
%    \begin{macrocode}
\newcommand{\tstidxindexmarker}[1]{%
 \tstidxsym{\tstidxindexmarkerprefix#1}{\csname#1\endcsname
   \protect\space (\protect\tstidxcsfmt{#1})}% 
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxindexmarkerprefix}
%    \begin{macrocode}
\newcommand*{\tstidxindexmarkerprefix}{<}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxmath}
%\begin{definition}
%\cs{tstidxmath}\oarg{encap}\marg{sort}\marg{entry}
%\end{definition}
% Display and index something in maths-mode.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxmath}[3][tstidxencapii]{%
    \tstindexpre[#2]{$#3$}{#1}{#3}%
  }
\else
  \newcommand*{\tstidxmath}[3][]{%
    \tstindexpre[#2]{$#3$}{#1}{#3}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxmathsym}
%\begin{definition}
%\cs{tstidxmathsym}\oarg{encap}\marg{sort}\marg{entry}
%\end{definition}
%Inserts a prefix before \meta{sort}.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxmathsym}[3][tstidxencapii]{%
    \tstidxmath[#1]{\tstidxmathsymprefix#2}{#3}%
  }
\else
  \newcommand*{\tstidxmathsym}[3][]{%
    \tstidxmath[#1]{\tstidxmathsymprefix#2}{#3}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tstidxmathsymprefix}
%    \begin{macrocode}
\newcommand*{\tstidxmathsymprefix}{>}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfword}
%\begin{definition}
%\cs{tstidxutfword}\oarg{encap}\marg{ascii}\marg{utf8}
%\end{definition}
% Display and index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfword}[3][]{%
  \tstidxutfpost{#2}{#3}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenutf}
%\begin{definition}
%\cs{tstidxopenutf}\oarg{encap}\marg{sort}\marg{ascii}\marg{utf8}
%\end{definition}
% As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxopenutf}[4][]{%
  \tstidxutfopenpost{#2}{#3}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseutf}
%\begin{definition}
%\cs{tstidxcloseutf}\oarg{encap}\marg{sort}\marg{ascii}\marg{utf8}
%\end{definition}
% As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxcloseutf}[4][]{%
  \tstidxutfclosepost{#2}{#3}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfphrase}
%\begin{definition}
%\cs{tstidxutfphrase}\oarg{encap}\marg{ascii}\marg{utf8}
%\end{definition}
% Display and index a phrase with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfphrase}[3][]{%
  \tstidxutfpre{#2}{#3}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenutfphrase}
%\begin{definition}
%\cs{tstidxopenutfphrase}\oarg{encap}\marg{ascii}\marg{utf8}
%\end{definition}
% As above but starts a range.
%    \begin{macrocode}
\newcommand*{\tstidxopenutfphrase}[3][]{%
  \tstidxutfopenpre{#2}{#3}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseutfphrase}
%\begin{definition}
%\cs{tstidxcloseutf}\oarg{encap}\marg{ascii}\marg{utf8}
%\end{definition}
% As above but ends a range.
%    \begin{macrocode}
\newcommand*{\tstidxcloseutfphrase}[3][]{%
  \tstidxutfclosepre{#2}{#3}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxplace}
% Display and index a place name.
%    \begin{macrocode}
\newcommand*{\tstidxplace}[2][]{%
  \tstidxutfplace[#1]{#2}{#2}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxutfplace}
%\begin{definition}
%\cs{tstidxutfplace}\oarg{encap}\marg{ascii}\marg{utf8}
%\end{definition}
% Display and index a word with UTF-8 characters.
%    \begin{macrocode}
\newcommand*{\tstidxutfplace}[3][]{%
  \tstidxutfpost{#2}{#3}{#1}%
  \tstidxutfsubpost[\relax]{places}{places}{#2}{#3}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxartplace}
% Display and index a place name that starts with an article.
%    \begin{macrocode}
\newcommand*{\tstidxartplace}[3][]{%
  \tstindexpost{#3, #2}{#1}{#2 #3}%
  \tstidxutfsubpost[\relax]{places}{places}{#3, #2}{#3, #2}{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxbookfmt}
% Display an book title.
%    \begin{macrocode}
\newcommand*{\tstidxbookfmt}[1]{\emph{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxbook}
% Display and index a book title.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxbook}[2][tstidxencapii]{%
    \tstindexpost[#2]{\protect\tstidxbookfmt{#2}}{#1}{\tstidxbookfmt{#2}}%
    \tstsubindexpost{books}[#2]{\protect\tstidxbookfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxbook}[2][]{%
    \tstindexpost[#2]{\protect\tstidxbookfmt{#2}}{#1}{\tstidxbookfmt{#2}}%
    \tstsubindexpost{books}[#2]{\protect\tstidxbookfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenbook}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopenbook}[2][tstidxencapii]{%
    \tstindexopenpost[#2]{\protect\tstidxbookfmt{#2}}{#1}{\tstidxbookfmt{#2}}%
    \tstsubindexopenpost{books}[#2]{\protect\tstidxbookfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxopenbook}[2][]{%
    \tstindexopenpost[#2]{\protect\tstidxbookfmt{#2}}{#1}{\tstidxbookfmt{#2}}%
    \tstsubindexopenpost{books}[#2]{\protect\tstidxbookfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosebook}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxclosebook}[2][tstidxencapii]{%
    \tstindexclosepost[#2]{\protect\tstidxbookfmt{#2}}{#1}{\tstidxbookfmt{#2}}%
    \tstsubindexclosepost{books}[#2]{\protect\tstidxbookfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxclosebook}[2][]{%
    \tstindexclosepost[#2]{\protect\tstidxbookfmt{#2}}{#1}{\tstidxbookfmt{#2}}%
    \tstsubindexclosepost{books}[#2]{\protect\tstidxbookfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxartbook}
%\begin{definition}
%\cs{tstidxartbook}\oarg{encap}\marg{article}\marg{remainder}
%\end{definition}
% Display and index a book title that starts with (in)definite
% article.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxartbook}[3][tstidxencapii]{%
    \tstindexpost[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{\tstidxbookfmt{#2 #3}}%
    \tstsubindexpost{books}[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxartbook}[3][]{%
    \tstindexpost[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{\tstidxbookfmt{#2 #3}}%
    \tstsubindexpost{books}[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenartbook}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopenartbook}[3][tstidxencapii]{%
    \tstindexopenpost[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}%
      {\tstidxbookfmt{#2 #3}}%
    \tstsubindexopenpost{books}[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxopenartbook}[3][]{%
    \tstindexopenpost[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}%
      {\tstidxbookfmt{#2 #3}}%
    \tstsubindexopenpost{books}[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxcloseartbook}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxcloseartbook}[3][tstidxencapii]{%
    \tstindexclosepost[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}%
      {\tstidxbookfmt{#2 #3}}%
    \tstsubindexclosepost{books}[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxcloseartbook}[3][]{%
    \tstindexclosepost[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}%
      {\tstidxbookfmt{#2 #3}}%
    \tstsubindexclosepost{books}[#3, #2]{\protect\tstidxbookfmt{#3, #2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxfilmfmt}
% Display an film title.
%    \begin{macrocode}
\newcommand*{\tstidxfilmfmt}[1]{\emph{#1}}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxfilm}
% Display and index a film title.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxfilm}[2][tstidxencapii]{%
    \tstindexpost[#2]{\protect\tstidxfilmfmt{#2}}{#1}{\tstidxfilmfmt{#2}}%
    \tstsubindexpost{films}[#2]{\protect\tstidxfilmfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxfilm}[2][]{%
    \tstindexpost[#2]{\protect\tstidxfilmfmt{#2}}{#1}{\tstidxfilmfmt{#2}}%
    \tstsubindexpost{films}[#2]{\protect\tstidxfilmfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxopenfilm}
%As above but starts a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxopenfilm}[2][tstidxencapii]{%
    \tstindexopenpost[#2]{\protect\tstidxfilmfmt{#2}}{#1}{\tstidxfilmfmt{#2}}%
    \tstsubindexopenpost{films}[#2]{\protect\tstidxfilmfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxopenfilm}[2][]{%
    \tstindexopenpost[#2]{\protect\tstidxfilmfmt{#2}}{#1}{\tstidxfilmfmt{#2}}%
    \tstsubindexopenpost{films}[#2]{\protect\tstidxfilmfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxclosefilm}
%As above but ends a range.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxclosefilm}[2][tstidxencapii]{%
    \tstindexclosepost[#2]{\protect\tstidxfilmfmt{#2}}{#1}{\tstidxfilmfmt{#2}}%
    \tstsubindexclosepost{films}[#2]{\protect\tstidxfilmfmt{#2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxclosefilm}[2][]{%
    \tstindexclosepost[#2]{\protect\tstidxfilmfmt{#2}}{#1}{\tstidxfilmfmt{#2}}%
    \tstsubindexclosepost{films}[#2]{\protect\tstidxfilmfmt{#2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxartfilm}
% As above but the title starts with an article.
%    \begin{macrocode}
\if@tstidx@use@encaps
  \newcommand*{\tstidxartfilm}[3][tstidxencapii]{%
    \tstindexpost[#3, #2]{\protect\tstidxfilmfmt{#3, #2}}{#1}%
      {\tstidxfilmfmt{#2 #3}}%
    \tstsubindexpost{films}[#3, #2]{\protect\tstidxfilmfmt{#3, #2}}{#1}{}%
  }
\else
  \newcommand*{\tstidxartfilm}[3][]{%
    \tstindexpost[#3, #2]{\protect\tstidxfilmfmt{#3, #2}}{#1}%
      {\tstidxfilmfmt{#2 #3}}%
    \tstsubindexpost{films}[#3, #2]{\protect\tstidxfilmfmt{#3, #2}}{#1}{}%
  }
\fi
%    \end{macrocode}
%\end{macro}
%
%\section{Generic Indexing Test Commands}
%\subsection{Top-Level Entries}
%The \cs{expandafter} stuff here is done to help simulate the user directly
%using \cs{index}.
% 
%\begin{macro}{\tstindexpost}
%The first argument is the sort, the second argument is the term
%being indexed and the third argument is the encap. The final
%argument is text to be displayed before the term is indexed.
%    \begin{macrocode}
\newcommand*{\tstindexpost}[4][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \ifx\@tstidx@encap\@empty
   \iftestidxshowmarks
     \tstidxtext{#4\tstidxmarker}%
   \else
     #4%
   \fi
  \else
   \iftestidxshowmarks
     \tstidxtext{\tstidxencaptext{#3}{#4\tstidxmarker}}%
   \else
     #4%
   \fi
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap#3}%
  \fi
  \expandafter\@tstindex\expandafter{\@tstidx@entry}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindexopenpost}
%As previous but starts a range.
%    \begin{macrocode}
\newcommand*{\tstindexopenpost}[4][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \ifx\@tstidx@encap\@empty
   \iftestidxshowmarks
     \tstidxtext{#4\tstidxopenmarker}%
   \else
     #4%
   \fi
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange}%
  \else
   \iftestidxshowmarks
     \tstidxtext{\tstidxencaptext{#3}{#4\tstidxopenmarker}}%
   \else
     #4%
   \fi
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange#3}%
  \fi
  \expandafter\@tstindex\expandafter{\@tstidx@entry}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindexclosepost}
%As previous but ends a range.
%    \begin{macrocode}
\newcommand*{\tstindexclosepost}[4][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \ifx\@tstidx@encap\@empty
   \iftestidxshowmarks
     \tstidxtext{#4\tstidxclosemarker}%
   \else
     #4%
   \fi
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange}%
  \else
   \iftestidxshowmarks
     \tstidxtext{\tstidxencaptext{#3}{#4\tstidxclosemarker}}%
   \else
     #4%
   \fi
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange#3}%
  \fi
  \expandafter\@tstindex\expandafter{\@tstidx@entry}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindexpre}
%The first argument is the sort, the second argument is the term
%being indexed and the third argument is the encap. The final
%argument is text to be displayed after the term is indexed.
%    \begin{macrocode}
\newcommand*{\tstindexpre}[4][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \ifx\@tstidx@encap\@empty
   \expandafter\@tstindex\expandafter{\@tstidx@entry}%
   \iftestidxshowmarks
     \tstidxtext{\tstidxmarker#4}%
   \else
     #4%
   \fi
  \else
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap#3}%
   \expandafter\@tstindex\expandafter{\@tstidx@entry}%
   \iftestidxshowmarks
     \tstidxtext{\tstidxencaptext{#3}{\tstidxmarker#4}}%
   \else
     #4%
   \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindexopenpre}
%As previous but starts a range.
%    \begin{macrocode}
\newcommand*{\tstindexopenpre}[4][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \ifx\@tstidx@encap\@empty
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange}%
   \expandafter\@tstindex\expandafter{\@tstidx@entry}%
   \iftestidxshowmarks
     \tstidxtext{\tstidxopenmarker#4}%
   \else
     #4%
   \fi
  \else
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange#3}%
   \expandafter\@tstindex\expandafter{\@tstidx@entry}%
   \iftestidxshowmarks
     \tstidxtext{\tstidxencaptext{#3}{\tstidxopenmarker#4}}%
   \else
     #4%
   \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindexclosepre}
%As previous but ends a range.
%    \begin{macrocode}
\newcommand*{\tstindexclosepre}[4][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \ifx\@tstidx@encap\@empty
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange}%
   \expandafter\@tstindex\expandafter{\@tstidx@entry}%
   \iftestidxshowmarks
     \tstidxtext{\tstidxclosemarker#4}%
   \else
     #4%
   \fi
  \else
   \expandafter\toks@\expandafter{\@tstidx@entry}%
   \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange#3}%
   \expandafter\@tstindex\expandafter{\@tstidx@entry}%
   \iftestidxshowmarks
     \tstidxtext{\tstidxencaptext{#3}{\tstidxclosemarker#4}}%
   \else
     #4%
   \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindexsee}
%The first argument is the sort, the second argument is the term
%being indexed, the third argument is the cross-referencing control
%sequence name (\qt{see} or \qt{seealso}) and the final argument is the
% cross-referenced text (the first argument of \ics{see} or
% \ics{seealso}).
%    \begin{macrocode}
\newcommand*{\tstindexsee}[4][]{%
  \def\@tstidx@sort{#1}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \expandafter\toks@\expandafter{\@tstidx@entry}%
  \edef\@tstidx@entry{\the\toks@\tstidxencap#3{#4}}%
  \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \iftestidxshowmarks
    \tstidxseeref{#2}{#3}{#4}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\subsection{Sub-Entries}
%One sub-level.
%\begin{macro}{\tstsubindexpost}
%\begin{definition}
%\cs{tstsubindexpost}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubindexpost}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subindexpost
}
\newcommand*{\@tst@subindexpost}[4][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxsubmarker}%
    \else
      #4%
    \fi
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \else
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxsubmarker}}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubindexopenpost}
%\begin{definition}
%\cs{tstsubindexopenpost}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubindexopenpost}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subindexopenpost
}
\newcommand*{\@tst@subindexopenpost}[4][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxopensubmarker}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \else
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxopensubmarker}}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubindexclosepost}
%\begin{definition}
%\cs{tstsubindexclosepost}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubindexclosepost}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subindexclosepost
}
\newcommand*{\@tst@subindexclosepost}[4][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxclosesubmarker}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \else
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxclosesubmarker}}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubindexpre}
%\begin{definition}
%\cs{tstsubindexpre}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubindexpre}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subindexpre
}
\newcommand*{\@tst@subindexpre}[4][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxsubmarker}%
    \else
      #4%
    \fi
  \else
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxsubmarker}}%
    \else
      #4%
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubindexopenpre}
%\begin{definition}
%\cs{tstsubindexopenpre}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubindexopenpre}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subindexopenpre
}
\newcommand*{\@tst@subindexopenpre}[4][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxopensubmarker}%
    \else
      #4%
    \fi
  \else
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxopensubmarker}}%
    \else
      #4%
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubindexclosepre}
%\begin{definition}
%\cs{tstsubindexclosepre}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubindexclosepre}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subindexclosepre
}
\newcommand*{\@tst@subindexclosepre}[4][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxclosesubmarker}%
    \else
      #4%
    \fi
  \else
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxclosesubmarker}}%
    \else
      #4%
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstindexsubsee}
%\begin{definition}
%\cs{tstindexsubsee}\oarg{main sort}\marg{main term}\oarg{sub sort}
%\marg{sub term}\marg{cs name}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstindexsubsee}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \ifx\@tstidx@sort\@empty
   \def\@tstidx@entry{#2}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \@tstindexsubsee
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\@tstindexsubsee}
%    \begin{macrocode}
\newcommand*{\@tstindexsubsee}[4][]{%
  \def\@tstidx@subsort{#1}%
  \ifx\@tstidx@subsort\@empty
   \toks@{#2}%
   \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}%
     \tstidxlevel\the\toks@}%
  \else
   \toks@{#1}%
   \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}%
     \tstidxlevel\the\toks@\tstidxactual}%
   \expandafter\def\expandafter\@tstidx@entry\expandafter{\@tstidx@entry#2}%
  \fi
  \expandafter\toks@\expandafter{\@tstidx@entry}%
  \edef\@tstidx@entry{\the\toks@\tstidxencap#3{#4}}%
  \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \iftestidxshowmarks
    \tstidxsubseeref{\@tstidx@term}{#2}{#3}{#4}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%
%Two sub-levels.
%\begin{macro}{\tstsubsubindexpost}
%\begin{definition}
%\cs{tstsubsubindexpost}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\oarg{sub-sub sort}\marg{sub-sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubsubindexpost}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subsubindexpost
}
\newcommand*{\@tst@subsubindexpost}[2][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \@@tst@subsubindexpost
}
\newcommand*{\@@tst@subsubindexpost}[4][]{%
  \def\@tstidx@subsubsort{#1}%
  \def\@tstidx@subsubterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@subsubsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxsubsubmarker}%
    \else
      #4%
    \fi
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \else
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxsubsubmarker}}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubsubindexopenpost}
%\begin{definition}
%\cs{tstsubsubindexopenpost}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\oarg{sub-sub sort}\marg{sub-sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubsubindexopenpost}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subsubindexopenpost
}
\newcommand*{\@tst@subsubindexopenpost}[2][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \@@tst@subsubindexopenpost
}
\newcommand*{\@@tst@subsubindexopenpost}[4][]{%
  \def\@tstidx@subsubsort{#1}%
  \def\@tstidx@subsubterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@subsubsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxopensubmarker}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \else
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxopensubmarker}}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubsubindexclosepost}
%\begin{definition}
%\cs{tstsubsubindexclosepost}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\oarg{sub-sub sort}\marg{sub-sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubsubindexclosepost}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subsubindexclosepost
}
\newcommand*{\@tst@subsubindexclosepost}[2][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \@@tst@subsubindexclosepost
}
\newcommand*{\@@tst@subsubindexclosepost}[4][]{%
  \def\@tstidx@subsubsort{#1}%
  \def\@tstidx@subsubterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@subsubsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxclosesubmarker}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \else
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxclosesubmarker}}%
    \else
      #4%
    \fi
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubsubindexpre}
%\begin{definition}
%\cs{tstsubsubindexpre}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\oarg{sub-sub sort}\marg{sub-sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubsubindexpre}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subsubindexpre
}
\newcommand*{\@tst@subsubindexpre}[2][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \@@tst@subsubindexpre
}
\newcommand*{\@@tst@subsubindexpre}[4][]{%
  \def\@tstidx@subsubsort{#1}%
  \def\@tstidx@subsubterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@subsubsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxsubsubmarker}%
    \else
      #4%
    \fi
  \else
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxsubsubmarker}}%
    \else
      #4%
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubsubindexopenpre}
%\begin{definition}
%\cs{tstsubsubindexopenpre}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\oarg{sub-sub sort}\marg{sub-sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubsubindexopenpre}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subsubindexopenpre
}
\newcommand*{\@tst@subsubindexopenpre}[2][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \@@tst@subsubindexopenpre
}
\newcommand*{\@@tst@subsubindexopenpre}[4][]{%
  \def\@tstidx@subsubsort{#1}%
  \def\@tstidx@subsubterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@subsubsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxopensubmarker}%
    \else
      #4%
    \fi
  \else
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxopenrange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxopensubmarker}}%
    \else
      #4%
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstsubsubindexclosepre}
%\begin{definition}
%\cs{tstsubsubindexclosepre}\oarg{main sort}\marg{main term}\oarg{sub
%sort}\marg{sub term}\oarg{sub-sub sort}\marg{sub-sub term}\marg{encap}\marg{text}
%\end{definition}
%    \begin{macrocode}
\newcommand*{\tstsubsubindexclosepre}[2][]{%
  \def\@tstidx@sort{#1}%
  \def\@tstidx@term{#2}%
  \@tst@subsubindexclosepre
}
\newcommand*{\@tst@subsubindexclosepre}[2][]{%
  \def\@tstidx@subsort{#1}%
  \def\@tstidx@subterm{#2}%
  \@@tst@subsubindexclosepre
}
\newcommand*{\@@tst@subsubindexclosepre}[4][]{%
  \def\@tstidx@subsubsort{#1}%
  \def\@tstidx@subsubterm{#2}%
  \def\@tstidx@encap{#3}%
  \ifx\@tstidx@sort\@empty
    \let\@tstidx@entry\@tstidx@term
  \else
     \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@sort}\tstidxactual
      \unexpanded\expandafter{\@tstidx@term}}%
  \fi
  \ifx\@tstidx@subsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subterm}}%
  \fi
  \ifx\@tstidx@subsubsort\@empty
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \else
    \edef\@tstidx@entry{\unexpanded\expandafter{\@tstidx@entry}\tstidxlevel
      \unexpanded\expandafter{\@tstidx@subsubsort}\tstidxactual
        \unexpanded\expandafter{\@tstidx@subsubterm}}%
  \fi
  \ifx\@tstidx@encap\@empty
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{#4\tstidxclosesubmarker}%
    \else
      #4%
    \fi
  \else
    \expandafter\toks@\expandafter{\@tstidx@entry}%
    \edef\@tstidx@entry{\the\toks@\tstidxencap\tstidxcloserange#3}%
    \expandafter\@tstindex\expandafter{\@tstidx@entry}%
    \iftestidxshowmarks
      \tstidxtext{\tstidxencaptext{#3}{#4\tstidxclosesubmarker}}%
    \else
      #4%
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%
%
%\section{Filler Text Generator}
%\begin{macro}{\testidx}
%Provide a command similar to \cs{lipsum} from the \sty{lipsum}
%package. May take a comma-separated list or a range of paragraph
%indices. The starred form suppresses paragraph breaks.
%    \begin{macrocode}
\newcommand*{\testidx}{%
  \@ifstar
  {%
    \def\@testidx@block@sep{\space}%
    \@testidx
  }%
  {%
    \def\@testidx@block@sep{\tstidxdefblocksep}%
    \@testidx
  }%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\@testidx}
%    \begin{macrocode}
\newcommand*{\@testidx}[1][1-\tstidxmaxblocks]{%
  \@for\@tidx@block@range:=#1\do{%
    \ifx\@tidx@block@range\@empty
    \else
     \expandafter\@test@idx\@tidx@block@range-\@nil-\@nil\@end@test@idx
    \fi
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxdefblocksep}
% The default separator between blocks is \cs{par}.
%    \begin{macrocode}
\newcommand{\tstidxdefblocksep}{\par}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxprefixblock}
%Prefix for each paragraph. Argument is the paragraph number.
%    \begin{macrocode}
\newcommand*{\tstidxprefixblock}[1]{{\scriptsize\number#1.}\ }
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\@tidx@parctr}
%    \begin{macrocode}
\newcount\@tidx@parctr
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\@test@idx}
%    \begin{macrocode}
\def\@test@idx#1-#2-#3\@end@test@idx{%
  \def\@tst@idx@arg{#1}%
  \ifx\@tst@idx@arg\@nnil
   \PackageError{testidx}{Invalid range `\@tidx@block@range'}{}%
  \else
    \def\@tst@idx@arg{#2}%
    \ifx\@tst@idx@arg\@empty
      \PackageError{testidx}{Invalid range `\@tidx@block@range'}{}%
    \else
      \ifx\@tst@idx@arg\@nnil
        \@@test@idx{#1}%
      \else
        \ifnum#2<#1\relax
          \@tidx@parctr=\numexpr#1+1\relax
          \loop
            \advance\@tidx@parctr by -\@ne
            \@@test@idx\@tidx@parctr
          \ifnum\@tidx@parctr>#2
          \repeat
        \else
          \@tidx@parctr=\numexpr#1-1\relax
          \loop
            \advance\@tidx@parctr by \@ne
            \@@test@idx\@tidx@parctr
          \ifnum\@tidx@parctr<#2
          \repeat
        \fi
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\@@test@idx}
%Do paragraph identified by argument.
%    \begin{macrocode}
\newcommand*{\@@test@idx}[1]{%
 \@ifundefined{@tidx@par@\romannumeral#1}%
 {%
   \PackageError{testidx}{No such test block `\number#1'}%
   {Blocks are numbered from 1 to \number\tstidxmaxblocks}%
 }%
 {%
    \tstidxprefixblock{#1}%
    \csname @tidx@par@\romannumeral#1\endcsname
    \@testidx@block@sep
 }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tstidxmaxblocks}
%    \begin{macrocode}
\newcount\tstidxmaxblocks
%    \end{macrocode}
%\end{macro}
%\subsection{Adding Test Paragraphs}
%
%\begin{macro}{\tstidxnewblock}
%    \begin{macrocode}
\newcommand*{\tstidxnewblock}{
  \@ifstar\s@tstidxnewblock\@tstidxnewblock
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\s@tstidxnewblock}
%\begin{definition}
%\cs{tstidxnewblock}*\marg{cs}\marg{block text}
%\end{definition}
%(Starred form.) Define a new block and assign the block's number
% to the control sequence \meta{cs} for reference in another
% block. (Can't use the normal \cs{ref}\slash\cs{label} as the
% reference is more useful to the user if the referred block is
% missing. The undefined ?? indicator isn't much use in this
% context.)
%    \begin{macrocode}
\newcommand{\s@tstidxnewblock}[2]{%
  \@tstidxnewblock{#2}%
  \edef#1{\number\tstidxmaxblocks}%
}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\@tstidxnewblock}
%\begin{definition}
%\cs{tstidxnewblock}\marg{block text}
%\end{definition}
% (Unstarred form.) Define a new block.
%    \begin{macrocode}
\newcommand{\@tstidxnewblock}[1]{%
  \advance\tstidxmaxblocks by \@ne
  \expandafter
    \newcommand\csname @tidx@par@\romannumeral\tstidxmaxblocks\endcsname{#1}%
}
%    \end{macrocode}
%\end{macro}
%
%\subsection{Test Paragraphs}
% These are all the predefined test paragraphs.
%    \begin{macrocode}
\tstidxnewblock
{%
 This is a~sample block of text designed to test
 \tstidxcs{index}, the
 \if@tstidx@use@encaps
  \tstidxword[tstidxencapii]{layout}
 \else
  \tstidxword{layout}
 \fi
  of the
 \if@tstidx@use@encaps
  \tstidxword[tstidxencapii]{index}
 \else
  \tstidxword{index}
 \fi
 (\tstidxenv{theindex} environment) and any
 \if@tstidx@use@encaps
   \tstidxphrase[tstidxencapii]{indexing application},
 \else
   \tstidxphrase{indexing application},
 \fi
 such as
 \tstidxapp{makeindex} or
 \tstidxapp{xindy}. This text is just
 \tstidxword{filler} (produced using \tstidxcs{testidx} provided
 by the \tstidxopensty{testidx} package) to 
 pad\tstindexsee{padding}{seealso}{filler} out 
 the document with instances of \tstidxcs{index} interspersed 
 throughout. You can use it, for \tstidxword{example}, to test an indexing
 package, such as \tstidxsty{makeidx} or \tstidxsty{imakeidx}, or to 
 test a \tstidxapp{makeindex} style file or \tstidxapp{xindy} module. 
 You can find out more
 information from the \tstidxsty{testidx} user manual, which
 can be accessed using the \tstidxapp{texdoc} application.
 This block starts a range that is closed in block~\@tidx@close@testidxsty.%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
 The \tstidxsty{testidx} package doesn't make any
 modifications to \tstidxcs{index} or \tstidxenv{theindex}. All 
 \tstidxphrase{visual effects} in this \tstidxphrase{dummy text} are produced 
 using markup commands provided solely for this \tstidxword{purpose} that 
 internally use \tstidxcs{index} or, more specifically, internally use
 \tstidxcs{tstindex}, which is defined to use \tstidxcs{index} (so you can 
 redefine \tstidxcs{tstindex} if you have multiple indexes). This package 
 doesn't attempt to \tstidxword{parse} or otherwise \tstidxword{interpret} the
 \tstidxword{argument} of \tstidxcs{index}, nor does it attempt to
 produce a well-designed index. Its purpose is to help you
 \tstidxword{test} your chosen \tstidxword{design}, which is easier to do with a
 relatively small test \tstidxword{document}, than with a large 
 \tstidxword{book}. The \tstidxphrase{dummy text} is intended to produce an 
 \tstidxword{index} that is at least three pages long to allow you
 to test the page headers and footers in a two-sided document.
 You can hide the visual effects with the
 \tstidxstyopt{testidx}{hidemarks} package option.
 \iftestidxshowmarks
 \else
  (It seems you already have this option set.
  Remove it or use \tstidxstyopt{testidx}{showmarks} to show them
  again.)%
 \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
 The actual place where the \tstidxcs{index} command occurs in this 
 \if@tstidx@use@encaps
   \tstidxphrase[tstidxencapiii]{dummy text}
 \else
   \tstidxphrase{dummy text}
 \fi
 is marked with the symbol 
 \tstidxindexmarker{tstidxmarker} if there is no \tstidxword{range} or
 \tstidxphrase{cross-reference}. The 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapi]{word}
 \else
   \tstidxword{word}
 \fi
 or 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapii]{phrase}
 \else
   \tstidxword{phrase}
 \fi
 adjacent to this \tstidxword{marker} is 
 the text being indexed.\tstidxfootnote{The \tstidxcs{index} command may 
 occur before or after the \tstidxword{word} or \tstidxword{phrase} being 
 indexed in this 
 \if@tstidx@use@encaps
   \tstidxphrase[tstidxencapiii]{dummy text},
 \else
   \tstidxphrase{dummy text},
 \fi
 but there's no 
 space between the \tstidxword{marker} and the term being indexed. Always 
 remember not to surround your \tstidxcs{index} usage with spaces. Keep it
 flush against the term being indexed and only have a space on one
 side. Incidentally, this \tstidxword{footnote} text was produced
 using the command \tstidxcs{tstidxfootnote}, which you can
 redefined as required. (It defaults to just \tstidxcs{footnote}.)}  
 A sub-entry is indicated with the symbol
 \tstidxindexmarker{tstidxsubmarker} and a sub-sub-entry is
 indicated with the symbol \tstidxindexmarker{tstidxsubsubmarker}.
 If an \tstidxword{encap} value is provided, both the 
 \if@tstidx@use@encaps
  \tstidxword[tstidxencapiii]{text}
 \else
  \tstidxword{text}
 \fi
 and the 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapii]{marker} 
 \else
   \tstidxword{marker} 
 \fi
 are typeset in the \tstidxword{argument} of the corresponding command. 
 (The text occurring in the document is also typeset within the argument of
 \tstidxcs{tstidxtext}. The default value is to use a dark grey, but since the
 default values for the \tstidxword{predefined} encaps used in this text all 
 change the colour, the dark grey will only apply where the encap hasn't
 been set.) There are three \tstidxword{encap} values used throughout this 
 \tstidxphrase{dummy text} (unless you've used the 
 \tstidxstyopt{testidx}{notestencaps} package option): 
 \if@tstidx@use@encaps
  \tstidxencapcsn[tstidxencapi]{tstidxencapi}, 
 \else
  \tstidxencapcsn{tstidxencapi}, 
 \fi
 \if@tstidx@use@encaps
   \tstidxencapcsn[tstidxencapii]{tstidxencapii}
 \else
   \tstidxencapcsn{tstidxencapii}
 \fi
 and 
 \if@tstidx@use@encaps
   \tstidxencapcsn[tstidxencapiii]{tstidxencapiii}.
 \else
   \tstidxencapcsn{tstidxencapiii}.
 \fi
 (The default values use \tstidxcs{textcolor}, so you might want to use the 
 \tstidxstyopt{hyperref}{hidelinks} option
 if you want to use the \tstidxsty{hyperref} package.) A cross-referenced
 entry (using \tstidxencapcsn{see} or \tstidxencapcsn{seealso}) is identified
 using the \tstidxword{marker}  \tstidxindexmarker{tstidxseemarker} 
 and the cross-referenced information is displayed as 
 a \tstidxphrase{marginal note} by default, with the term being indexed 
 followed by the \tstidxword{cross-reference}. A sub-level 
 \tstidxword{cross-reference} is identified with the \tstidxword{marker}
 \tstidxindexmarker{tstidxsubseemarker} and the marginal note
 displays the main term followed by the sub-term (separated by the
 symbol \tstidxsubseesep).  The \tstidxword{marker} used for the start of 
 a range is \tstidxindexmarker{tstidxopenmarker} and the
 \tstidxword{marker} used for the end of 
 a range is \tstidxindexmarker{tstidxclosemarker} 
 unless the entry is a sub-level, in which case the
 \tstidxword{marker} for the start of the range is 
 \tstidxindexmarker{tstidxopensubmarker} 
 and the \tstidxword{marker} used for the end of a range is 
 \tstidxindexmarker{tstidxclosesubmarker}, or for a sub-sub-level
 \tstidxindexmarker{tstidxopensubsubmarker} and 
 \tstidxindexmarker{tstidxclosesubsubmarker}. There are no tests for
 any further sub-levels. Although \tstidxapp{xindy} allows more than
 three levels (\tstidxapp{makeindex} doesn't), it's somewhat
 \tstidxword{excessive} to go below a sub-sub-level. 
 You'll have to add your own tests for anything deeper.%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock*{\@tidx@openrangepar}
{%
 Here's an \tstidxword{example} of the start of a \tstidxopenword{range} but
 remember that a range must also have an end, so make sure that 
 \tstidxword{block}~\@tidx@closerangepar\ has been included in this
 \if@tstidx@use@encaps
   \tstidxphrase[tstidxencapiii]{dummy text},
 \else
   \tstidxphrase{dummy text},
 \fi
  which closes this
 \tstidxword{example}.
 \iftestidxverbose
   I see you've used the \tstidxstyopt{testidx}{verbose} package option which 
   shows the \tstidxword{argument} being passed to \tstidxcs{tstindex}. 
   I expect it's caused some \tstidxphrase{overfull lines}.%
 \else
   If you want more detail, you can use the \tstidxstyopt{testidx}{verbose} 
   package option which will show the \tstidxword{argument} being passed to 
   \tstidxcs{tstindex} but be warned that it will
   cause \tstidxphrase{overfull lines}.%
 \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
 Now that the preliminaries have been dispensed with in the previous
 \tstidxword{paragraph}s, we can get on
 to some serious 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapii]{waffle}
 \else
   \tstidxword{waffle}
 \fi
 to act as 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapi]{filler}
 \else
   \tstidxword{filler}
 \fi
 text because this really needs 
 some \tstidxword{padding} in order to get a decent sized
 \tstidxword{index} with lots of locations. I did consider using just
 plain old \tstidxphrase{lorem ipsum} (like the \tstidxsty{lipsum}
 package), but it gets a bit boring after a while, and it's easier to 
 check the indexing has been performed successfully if you can understand 
 the text. Of course, this doesn't help those who don't know any English, but at
 least they're no worse off than they would have been with random
 \tstidxword{gibberish}\tstindexsee{gobbledegook}{see}{gibberish},
 at least, I hope not.  In other words, if I could just \tstidxword{clarify} 
 what I'm trying to say here, in a \tstidxword{confidential} and not too 
 \tstidxword{roundabout} \tstidxword{fashion}\tstidxdash
 \tstidxphrase{between you, me and the gatepost}\tstidxdash is please don't 
 consider this to be an 
 \tstidxword{illustration}\tstindexsee{illustration}{seealso}{example} of 
 my stunning \tstidxword{wit}, \tstidxword{eloquence} and 
 \tstidxphrase{way with words} because I'm shamelessly contravening the 
 \tstidxphrase{creative writing}
 \tstidxword{adage} (or possibly \tstidxword{motto}) of 
 \tstidxphrase{cut to the chase}, remove excessive
 \tstidxword{verbiage} and \tstidxphrase{get to the point}. I shall
 take care to hide this \tstidxword{drivel} from my 
 \if@tstidx@use@encaps
   \tstidxphrase[tstidxencapiii]{creative writing}
 \else
   \tstidxphrase{creative writing}
 \fi
 \tstidxword{tutor} and 
 fellow writers, so 
 \tstidxphrase{keep mum}\tstindexsee{keep mum}{seealso}{confidential} 
 and don't \tstidxword{grass} on me because that just won't be fair,
 and it might \tstidxword{distress} them to a certain extent.
 Where was I? Oh, yes, \tstidxword{padding}. I'm trying to make this
 \tstidxword{paragraph} quite long, not because I have any pretensions of being
 the next \tstidxperson{James}{Joyce} and competing with 
 \tstidxbook{Ulysses}, but because one of the things
 we need to check for is what happens with paragraphs that span a
 \tstidxphrase{page break}. (If you're feeling particularly daring,
 try out the starred version of \tstidxcs{testidx}, although
 some of the blocks, such as \tstidxword{block}~\@tidx@xdypar, have some 
 sneaky \tstidxword{paragraph} breaks that won't
 be suppressed.) \tstidxsym{TeX}{\TeX}'s asynchronous 
 \if@tstidx@use@encaps
   \tstidxphrase[tstidxencapii]{output routine}
 \else
   \tstidxphrase{output routine}
 \fi
 can cause things to go a bit 
 \if@tstidx@use@encaps
   \tstidxphrase[tstidxencapiii]{out of whack},
 \else
   \tstidxphrase{out of whack},
 \fi
 so lengthy paragraphs in this 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapii]{example}
 \else
   \tstidxword{example}
 \fi
 document increase the chances of testing for these occurrences. 
 Whether or not this particular \tstidxword{paragraph} 
 actually spans a \tstidxphrase{page break} does, of course, depend on
 various things including your document \tstidxsubword{document}{properties}, 
 such as the \tstidxphrase{page dimensions}, \tstidxphrase{font family} and
 \tstidxphrase{font size}. If it turns out that this 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapi]{paragraph} 
 \else
   \tstidxword{paragraph} 
 \fi
 has spanned a \tstidxphrase{page break}, you might want to check the terms 
 indexed here to make sure they have the correct page numbers listed.
 Something else that you might want to check, while you're at it, is
 what's happened to the \tstidxword{location list} for the word
 \if@tstidx@use@encaps
   \tstidxqt{\tstidxword[tstidxencapii]{paragraph}},
 \else
   \tstidxqt{\tstidxword{paragraph}},
 \fi
 as I've used different 
 \tstidxword{encap} values for it in various places in this
 \tstidxword{example} 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapiii]{paragraph}.
 \else
   \tstidxword{paragraph}.
 \fi
 If you are using
 \tstidxapp{makeindex}, you might notice some warnings about 
 \tstidxphrase{multiple encaps}, and the \tstidxphrase{page number}
 may be duplicated in the location list. If you are using 
 \tstidxapp{xindy}, then it will discard duplicate page numbers and
 give preference to the first defined attribute in whatever 
 \tstidxapp{xindy} module you're using. However, be careful if a 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapi]{range} 
 \else
   \tstidxword{range} 
 \fi
 overlaps a different \tstidxword{encap}.
 Remember that there's a difference between an \tstidxword{index} and a
 \tstidxword{concordance}. If you just index pertinent places, there's less
 likelihood of conflicting encaps. This is the end of a 
 \if@tstidx@use@encaps
   \tstidxword[tstidxencapiii]{paragraph}
 \else
   \tstidxword{paragraph}
 \fi
 that was written to deliberately upset \tstidxapp{makeindex}.
 Mean, aren't I?%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock*{\@tidx@xdypar}
{%
 On the subject of \tstidxapp{xindy}, if you want to use it with
 this \tstidxword{example} document, you'll need to add the 
 \tstidxword{encap} values used in this \tstidxphrase{dummy text}
 as allowed attributes. For example, you may want to create a file
 called, say, \texttt{\jobname.xdy} that contains the following:
%    \end{macrocode}
% Can't use verbatim so fudge it.
%    \begin{macrocode}
 \begin{flushleft}\ttfamily\obeylines
; list of allowed attributes
\par\medskip\par
(define-attributes ((
  \string"tstidxencapi\string"
  \string"tstidxencapii\string"
  \string"tstidxencapiii\string"
)))
\par\medskip\par
; define format to use for locations
\par\medskip\par
(markup-locref :open \string"\string\tstidxencapi\expandafter\@gobble\string\{\string"
 :close \string"\expandafter\@gobble\string\}\string"
 :attr \string"tstidxencapi\string")

(markup-locref :open \string"\string\tstidxencapii\expandafter\@gobble\string\{\string"
 :close \string"\expandafter\@gobble\string\}\string"
 :attr \string"tstidxencapii\string")

(markup-locref :open
\string"\string\tstidxencapiii\expandafter\@gobble\string\{\string"
 :close \string"\expandafter\@gobble\string\}\string"
 :attr \string"tstidxencapiii\string")
 \end{flushleft}
 This sets up allowed encap values and how they should be formatted.
 The ordering of the allowed \tstidxword{attributes} here gives the 
 \tstidxencapcsn{tstidxencapi} encap precedence in the
 event of a \tstidxphrase{multiple encaps} clash, since it's the
 first one in the list. You can then
 run \tstidxapp{xindy} using:
 \begin{flushleft}\ttfamily
xindy -L english -C utf8 -M \jobname.xdy -M texindy -t \jobname.ilg
\jobname.idx
 \end{flushleft}
 You might also want to set the location list
 \tstidxsubword{location list}{page separator}
 and the \tstidxsubword{location list}{range separator}%
 \tstindexsee{range separator}{see}{location list}
 in your \texttt{.xdy} file.  For example:
 \begin{flushleft}\ttfamily
(markup-locref-list :sep \string",\string")\par
(markup-range :sep \string"\string-\string-\string")
 \end{flushleft}
 Check out the difference between using \tstidxapp{xindy} and
 \tstidxapp{makeindex} on this document.%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
 We, the \tstidxutfword{\'elite}{élite} who discovered the 
 \tstidxutfword{\ae sthetic}{æsthetic}
 delights of \tstidxsym{TeX}{\TeX}, must not become
 \tstidxutfword{blas\'e}{blasé} about being the
 \tstidxutfword{prot\'eg\'e}{protégé}
 of the great \tstidxperson{Donald}{Knuth}.
 It may stagger the 
 \tstidxutfword{client\`ele}{clientèle} of 
 \if@tstidx@use@encaps
   \tstidxartphrase[tstidxencapii]{the}{commercial world} 
 \else
   \tstidxartphrase{the}{commercial world} 
 \fi
 to discover our 
 \tstidxutfword{r\'esum\'e}{résumé} 
 (after foraging for it in our natty 
 \tstidxutfphrase{attach\'e case}{attaché case})
 while we sample a \tstidxword{vol-au-vent} or \tstidxword{two}
 at the \tstidxutfword{soir\'ee}{soirée}
 in the \tstidxutfphrase{pied-\`a-terre}{pied-à-terre}
 with the delightful \tstidxutfword{ph\oe nix}{phœnix}-%
 themed \tstidxutfword{d\'ecor}{décor} and
 \tstidxutfword{f\ae rie}{færie}
 \tstidxutfword{fa\c{c}ade}{façade}
 that has stunned
 many an \tstidxutfword{\ae thereal}{æthereal}
 \tstidxutfword{d\'ebutante}{débutante}
 sporting a \tstidxutfphrase{berg\`ere hat}{bergère hat},
 but it would be \tstidxutfword{na\"ive}{naïve}
 to fall for such a \tstidxutfword{f\oe tid}{fœtid}
 \tstidxutfword{clich\'e}{cliché}.
 This \tstidxword{paragraph} is in a state of 
 \tstidxutfword{d\'eshabill\'e}{déshabillé}.
 Like a \tstidxword{sculpture} of \tstidxword{Venus} in a 
 \tstidxutfword{n\'eglig\'ee}{négligée}, it's transparently
 obvious that this \tstidxword{paragraph} is provided for the sole purpose of 
 \tstidxword{ogling}\tstindexsee{gawping}{see}{ogling}
 \tstidxphrase{extended Latin characters} and testing
 how \tstidxapp{xindy} and \tstidxapp{makeindex} compare.
 Time for a quick trip to the \tstidxutfword{caf\'e}{café}
 for an \tstidxutfword{an\ae mic}{anæmic} 
 \tstidxphrase{cup of tea} with
 \tstidxutfperson{Anders Jonas}{\AA ngstr\"om}%
 {Anders Jonas}{Ångström} and then off to find a \tstidxword{zoo}
 in \tstidxutfplace{\"Osterg\"otland}{Östergötland},
 so we can get to the end of the \tstidxword{alphabet}. Perhaps
 then we should go over to 
 \tstidxutfplace{\"Angelholm}{Ängelholm}
 and head off across the 
 \tstidxutfplace{\O resund}{Øresund} bridge and
 \tstidxword{resume} our search for some more examples.
 We'll go on a \tstidxphrase{whistle-stop tour} around
 \tstidxutfplace{T\r{a}rnby}{Tårnby},
 \tstidxutfplace{R\o dovre}{Rødovre},
 \tstidxutfplace{N\ae stved}{Næstved} and
 \tstidxutfplace{\O lstykke-Stenl\o se}{Ølstykke-Stenløse}.
 Afterwards, we'll \tstidxword{fly} to
 \tstidxplace{Poland} (possibly in an \tstidxword{aeroplane}\tstidxdash
 if passengers would like to look out of their \tstidxword{window}, they'll
 see we're passing over 
 \tstidxutfplace{A\ss lar}{Aßlar} and
 \tstidxutfplace{Bad Gottleuba-Berggie\ss h\"ubel}{Bad Gottleuba-Berggießhübel})
 and then we'll visit \tstidxutfplace{\L\'od\'z}{Łódź},
 \@tstidx@if@notOT@ne
 {%
   \tstidxutfplace{\'Swi\k{e}tokrzyskie}{Świętokrzyskie}%
   \ifxetex
   \else
     \ifluatex
     \else
       \space(that one will cause a problem for certain font encodings
       because of the \tstidxword{ogonek} and
       will be omitted if you use the default 
       \tstidxsubword{font encoding}{OT1}
       encoding, but not if you use the \tstidxsty{fontenc} package with, 
       for example, the \tstidxstyopt{fontenc}{T1} option)%
     \fi
   \fi,
 }%
 {%
   [a place with an \tstidxword{ogonek} has been omitted because this document
    is using the default \tstidxsubword{font encoding}{OT1} font 
   encoding\tstidxdash try loading \tstidxsty{fontenc} with the 
   \tstidxstyopt{fontenc}{T1} option],
 }%
 \tstidxutfplace{\.Zory}{Żory},
 \tstidxutfplace{\.Zelech\'ow}{Żelechów},
 \tstidxutfplace{\L obez}{Łobez},
 \tstidxutfplace{G\l og\'ow}{Głogów}
 (not to be confused with \tstidxplace{Glasgow}),
 \tstidxutfplace{\'Cmiel\'ow}{Ćmielów},
 \tstidxutfplace{\'Scinawa}{Ścinawa}
 and
 \tstidxutfplace{\'Swidnica}{Świdnica}.
 Then let's \tstidxword{sail} to \tstidxplace{Iceland} (possibly in
 a \tstidxword{ship}) and visit the lakes of
 \tstidxplace{Iceland}, such as 
 \tstidxutfplace{\"Olvesvatn}{Ölvesvatn},
 \tstidxutfplace{\'Ulfsvatn}{Úlfsvatn},
 \tstidxutfplace{\'Anavatn}{Ánavatn},
 \tstidxutfplace{M\'asvatn}{Másvatn},
 \@tstidx@if@notOT@ne
 {%
   \tstidxutfplace{\th r\'hyrningsvatn}{Þríhyrningsvatn}
   (that one starts with a \tstidxutfword{thorn (\th)}{thorn (Þ)}),
   \tstidxutfplace{Sigr\'i\dh arsta\dh avatn}{Sigríðarstaðavatn}
   (that one has an \tstidxutfword{eth \dh}{eth ð}%
   \ifxetex
    )%
   \else
     \ifluatex
      )%
     \else
       \tstidxdash those last two will also be omitted if you use the default 
       \tstidxword{OT1} \tstidxword{font encoding})%
     \fi
   \fi,
 }%
 {%
   [a couple of lakes with a \tstidxword{thorn} and an
   \tstidxword{eth} have been omitted because this document is using the
   default \tstidxword{OT1} \tstidxword{font encoding}\tstidxdash try loading 
   \tstidxsty{fontenc} with the \tstidxstyopt{fontenc}{T1} option],
 }%
 \tstidxutfplace{Gr\ae navatn}{Grænavatn},
 \tstidxutfplace{\'Arnesl\'on}{Árneslón}
 and
 \tstidxutfplace{\'Ish\'olsvatn}{Íshólsvatn}.
 If you are using this with \tstidxapp{xindy} and
 \tstidxword{UTF-8}, try this out with a different language option,
 for example \tstidxappopt{xindy}{-L swedish} or 
 \tstidxappopt{xindy}{-L danish} or \tstidxappopt{xindy}{-L german-duden} or 
 \tstidxappopt{xindy}{-L german-din5007} or \tstidxappopt{xindy}{-L polish} or 
 \tstidxappopt{xindy}{-L icelandic}.
 \@tstidx@ifgerman
 {I notice you've use the \tstidxstyopt{testidx}{german} or
  \tstidxstyopt{testidx}{ngerman} package option. This means that if you want
  to use \tstidxapp{makeindex} instead of \tstidxapp{xindy}, you can
  use \tstidxapp{makeindex}'s \tstidxappopt{makeindex}{-g} option.%
 }%
 {%
  If you want to use \tstidxapp{makeindex} instead of
  \tstidxapp{xindy}, then the package option \tstidxstyopt{testidx}{german} or
  \tstidxstyopt{testidx}{ngerman} will allow you to use 
  \tstidxapp{makeindex}'s \tstidxappopt{makeindex}{-g} option.%
 }%
 \@tstidx@ifutfviii
 {%
   \ifxetex
   \else
     \ifluatex
     \else
       \space You currently have the 
       \@tstidx@ifsanitize
       {\tstidxstyopt{testidx}{sanitize} option on.
        This means that the words containing \tstidxword{UTF-8} characters will
        first be sanitized before being passed to \tstidxcs{tstindex}, which 
        will allow you to test how well the \tstidxphrase{indexing application} 
        sorts \tstidxword{UTF-8} characters. If you'd rather test how 
        \tstidxcs{index} writes these characters to the file read by the 
        indexing application, use the \tstidxstyopt{testidx}{nosanitize}
        option instead. This may cause the \tstidxword{UTF-8} characters to be
        written in terms of \tstidxcs{IeC}.%
       }%
       {\tstidxstyopt{testidx}{nosanitize} option on.
        This means that the words containing \tstidxword{UTF-8} characters 
        may be written to the file processed by the 
        \tstidxphrase{indexing application} in terms of
        \tstidxcs{IeC}. This allows you to test how \tstidxcs{index} behaves. 
        If you'd rather test how the indexing application sorts
        \tstidxword{UTF-8} characters, use the \tstidxstyopt{testidx}{sanitize}
        option instead, which will sanitize the \tstidxword{UTF-8} characters
        before passing them to \tstidxcs{tstindex}.%
       }
     \fi
   \fi
 }%
 {}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
  Don't forget there's also a \tstidxphrase{number group}, so let's
  have some numbers. 
  \tstidxartbook{The}{Hitchhiker's Guide to the Galaxy} has
  of course propelled the number \tstidxnumber{42} to stardom, as the
  answer to \tstidxword{life}, the \tstidxword{universe} and
  everything. We usually deal in base~\tstidxnumber{10}, but sometimes
  base~\tstidxnumber{16} is useful to programmers, and computers
  prefer base~\tstidxnumber{2} (and \tstidxnumber{2} is the only
  \tstidxword{even} \tstidxword{prime number}). A \tstidxword{century} in 
  \tstidxword{cricket} means \tstidxnumber{100} runs, and in the
  \tstidxword{calendar} \tstidxnumber{100} years.
  If you're using \tstidxapp{xindy}, you can provide a numbers group 
  by adding the following to your \texttt{.xdy} module:
\begin{flushleft}\ttfamily
(define-letter-group \string"Numbers\string"\par
   \string:prefixes (\string"0\string" \string"1\string" \string"2\string"
\string"3\string" \string"4\string" \string"5\string"
\string"6\string" \string"7\string" \string"8\string"
\string"9\string")\par
   \string:before \string"A\string")
\end{flushleft}
  Whilst we're on the subject of numbers, let's try out some
  equations.
\begin{equation}
\tstidxmath{E}{E} = mc^2
\end{equation}
  \@tstidx@ifamsmath
  {%
   Since this document is using \tstidxsty{amsmath}, let's try out
the \tstidxenv{align} environment:
\begin{align}
\tstidxmath{f(x)}{f(\protect\vec{x})} &=
 \tstidxmathsym{alpha}{\protect\alpha}
 \tstidxmathsym{sum}{\protect\sum}_i^{\tstidxmath{n}{n}} x_i
+\tstidxmathsym{beta}{\protect\beta} \sum_{i}^n x_i^2
+\tstidxmathsym{gamma}{\protect\gamma}
\end{align}
   If this document hadn't loaded the \tstidxsty{amsmath} package,
we would have had to use the \tstidxenv{eqnarray} environment
instead.
  }%
  {%
   This document doesn't load the \tstidxsty{amsmath} package, so
let's try out the \tstidxenv{eqnarray} environment:
\begin{eqnarray}
\tstidxmath{f(x)}{f(\protect\vec{x})} &=& 
 \tstidxmathsym{alpha}{\protect\alpha}
 \tstidxmathsym{sum}{\protect\sum}_i^{\tstidxmath{n}{n}} x_i
+\tstidxmathsym{beta}{\protect\beta} \sum_{i}^n x_i^2
+\tstidxmathsym{gamma}{\protect\gamma}
\end{eqnarray}
   If you load the \tstidxsty{amsmath} package, we'll test the 
   \tstidxenv{align} environment instead.
  }%
  Now I've been a bit fancy here and inserted
  \texttt{\tstidxmathsymprefix} in front of
  the sort key so I can get \tstidxapp{xindy} to create a special
group for the maths symbols. Here's the code you can add to your
\texttt{.xdy} file to implement it:
\begin{flushleft}\ttfamily
(define-letter-group \string"Maths\string"
   \string:prefixes (\string"\tstidxmathsymprefix\string")
   \string:before \string"Numbers\string")
\end{flushleft}
 I've done something similar with the \tstidxword{marker}s where I've used
 \texttt{\tstidxindexmarkerprefix} as the \tstidxword{prefix}.%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock*{\@tidx@closerangepar}%
{%
 This is the end of the \tstidxcloseword{range}
 \tstidxword{example} from \tstidxword{block}~\@tidx@openrangepar.
 There's not much else to say about this \tstidxword{block} really.
 It's quite boring, isn't it? However, you'll need it if you've
 included block~\@tidx@openrangepar. Unless you're testing for 
 a mis-matched range, of course. That might be quite interesting,
 possibly, but I'm not going to \tstidxphrase{hold my breath}.%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
  Now this is going to be hard to believe\tstidxdash in fact I'm 
  totally \tstidxword{gobsmacked} and utterly \tstidxword{astounded}
  \tstidxdash but I've discovered that we're still missing some 
  \tstidxphrase{letter groups}, and I've run out of anything 
  \tstidxword{quaint} to say, so I'm going to have to
  \tstidxword{yatter} for a while longer, which will probably make
  you \tstidxword{yawn}. What shall we talk about? My \tstidxword{quirky}
  \tstidxword{badinage} is about to \tstidxword{expire}. How about a
  \tstidxword{story}? Here's one I made up for my friend
  \tstidxperson{Paulo}{Cereda} in \tstidxsym{TeX}{\TeX}.SE chat because he likes
  ducks and is the creator of \tstidxapp{arara}.
  So, are you sitting comfortably? Then let's \tstidxword{begin}. By the way,
  before I \tstidxword{forget}, it's called 
  \tstidxbook{Sir Quackalot and the Golden Arara} and is the
  first story in 
  \tstidxartbook{The}{Adventures of Sir Quackalot}.
  It's a \tstidxword{tale} of \tstidxword{adventure} and 
  \tstidxword{daring-do}. The \tstidxword{hero} of the 
  \tstidxword{story} is \tstidxperson{Sir}{Quackalot}, in case you
  can't tell from the \tstidxword{title}.
  \tstidxphrase{Once upon a time}, a long time ago in 
  \tstidxartphrase{a}{far away land}, there lived a
  \tstidxword{knight}. He was \tstidxword{handsome}, he was 
  \tstidxword{bold}, he was \tstidxword{brave}.
  He was\tstidxdash a \tstidxword{duck}. His \tstidxword{name} was 
  \tstidxperson{Sir}{Quackalot}. 
  One day \tstidxperson{the}{Fairy Goose} appeared. 
  \tstidxqt{Brave \tstidxword{knight},} she said. \tstidxqt{A terrible
  \tstidxword{plight} has fallen on 
  the \tstidxword{land}. The evil \tstidxword{OgRe} has stolen 
  \tstidxartphrase{the}{Golden Arara}. Only you can save it.} 
  (That's a \tstidxword{reference} to 
  \tstidxsym{TeX}{\TeX}'s \tstidxphrase{output routine}, if you missed it.)
  \tstidxqt{It will be a \tstidxword{perilous} \tstidxword{quest}, but find 
  \tstidxartphrase{the}{Mighty Helm of Knuth} and
  \tstidxartphrase{the}{Legendary Sword} \tstidxword{xor} to aid you.} (Ask
  \tstidxperson{David}{Carlisle} about the \tstidxword{xor}
  \tstidxword{reference}.)%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
 So \tstidxperson{Sir}{Quackalot} set out on his \tstidxword{quest}. 
 (This is the \tstidxword{continuation} from
 the previous \tstidxword{block}, for any \tstidxword{newcomers}
 who have just turned up.) He soon arrived at 
 \tstidxartphrase{the}{Bog of Eternal Glossaries} (that's a
 reference to my \tstidxsty{glossaries} package, and it's also a
 \tstidxword{nod} to \tstidxartplace{the}{Bog of Eternal Stench} in 
 \tstidxfilm{Labyrinth}), in the 
 \tstidxword{centre} (or \tstidxword{center} for those of you
 \tstidxphrase{across the pond}) of which was 
 suspended \tstidxartphrase{the}{Mighty Helm of Knuth}, but 
 \tstidxperson{Sir}{Quackalot} was learned in the \tstidxword{lore} of
 installing \tstidxapp{Perl} and was able to leap upon the 
 \tstidxword{raft} \tstidxapp{makeglossaries} and steer his way through the 
 \tstidxword{external} \tstidxphrase{indexing application}s and their many 
 arguments.  (That's supposed to be a \tstidxword{pun}, but it's 
 \tstidxphrase{bad form} to explain the \tstidxword{joke}, and it
 wasn't even particularly \tstidxword{witty}.
 Incidentally, \tstidxperson{Joseph}{Wright} makes a
 \tstidxword{cameo} at this point with the 
 \tstidxword{exclamation} \tstidxqt{fetchez la vache!}\ but you'll have to 
 ask \tstidxperson{Paulo}{Cereda} what
 that's all about. It wouldn't surprise me if it had something to
 do with \tstidxphrase{Monty Python}.)%
} 
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
 Anyway, where were we? Oh, yes.  He (that's
 \tstidxperson{Sir}{Quackalot} we're talking about, if you've only
 just joined us) snatched up \tstidxartphrase{the}{Mighty Helm of Knuth} and 
 escaped from the \tstidxword{perilous} \tstidxword{bog}. Soon he came to 
 \tstidxartphrase{the}{Dread Vale of the Editors}, guarded
 at either end by the ever-quarrelling 
 \tstidxword{leviathans} \tstidxapp{Emacs} and \tstidxapp{Vi}. 
 As he approached the \tstidxword{vale}, Emacs uttered the 
 \tstidxphrase{magic incantation} that
 sent forth \tstidxartphrase{the}{butterflies of chaos}. 
 (I know \tstidxqt{\tstidxword{doom}} is more appropriate but,
 as is \tstidxphrase{common knowledge}, \tstidxword{chaos} is a 
 \tstidxword{butterfly} \tstidxword{motif}.)%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
But \tstidxperson{Sir}{Quackalot} was protected by 
\tstidxartphrase{the}{Mighty Helm of Knuth} and
raced past into the \tstidxword{vale}, where he found 
\tstidxartphrase{the}{Legendary Sword} \tstidxword{xor} in
the centre of the great \tstidxsty{longtable}. (Ooh, I've started a 
\tstidxword{sentence} with a \tstidxword{conjunction}. 
How \tstidxword{naughty} is that?)
With a great \tstidxword{leap} and a \tstidxword{bound}, 
\tstidxperson{Sir}{Quackalot} plucked out the \tstidxword{sword} and
headed for the far end of the \tstidxword{vale}.
Up pounced \tstidxapp{Vi} and belched forth a \tstidxword{myriad}
of \tstidxword{clones} that bore down on
\tstidxperson{Sir}{Quackalot}.  But, brandishing the \tstidxword{sword} 
\tstidxword{xor}, \tstidxperson{Sir}{Quackalot} sliced them down. 
(There's some \tstidxword{repetition} there, but hopefully no one's
noticed. There's even more coming up in the next
\tstidxword{block}.)%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock*{\@tidx@close@testidxsty}%
{%
\tstidxperson{Sir}{Quackalot} escaped from 
\tstidxartphrase{the}{Dread Vale of the Editors} and set off
up the path that led to the evil \tstidxword{OgRe}'s \tstidxword{lair}. 
As \tstidxperson{Sir}{Quackalot} approached, there was a fearful 
\tstidxword{roar}, and the \tstidxword{OgRe} pounced on \tstidxperson{Sir}{Quackalot}. 
The brave \tstidxword{knight} raised his powerful \tstidxword{sword} 
\tstidxword{xor} and brought it down on the \tstidxword{OgRe}, destroying him. 
\tstidxperson{Sir}{Quackalot} rescued \tstidxartphrase{the}{Golden Arara} 
and the \tstidxword{land} was once more restored to \tstidxword{peace} and 
\tstidxword{harmony} and 
\tstidxword{paragraph}s were able to \tstidxword{span} 
\tstidxphrase{page break}s without \tstidxword{fear}. 
\tstidxartphrase{The}{End}. Don't miss the next \tstidxword{thrilling} 
\tstidxword{adventure} \tstidxbook{Sir Quackalot and the Hyper Lake of Doom}
where our \tstidxphrase{intrepid hero}%
\tstindexsubsee{hero}{intrepid}{see}{intrepid hero} meets a \tstidxword{quixotic}
\tstidxword{seal} with a \tstidxword{zither} (a \tstidxword{zealous}
\tstidxword{fan} of \tstidxartfilm{The}{Third Man}), a \tstidxword{youthful} 
\tstidxphrase{sea lion} with a \tstidxword{magic}
\tstidxword{yo-yo}, and a \tstidxword{wily} \tstidxword{wombat}
\tstidxword{warrior} with a \tstidxword{laser-guided}
\tstidxphrase{sealant gun}. Can they defeat the
\tstidxword{villainous}, \tstidxword{zany} \tstidxword{zoologist}
sailing a \tstidxword{xebec} bearing canisters of
\tstidxword{xenon}, \tstidxword{xylem} and \tstidxword{xylene}?
Oh, \tstidxword{zounds}! He's wearing a \tstidxphrase{zoot suit}
and smoking a \tstidxword{zucchini} whilst playing a \tstidxword{xylophone}. 
As one \tstidxphrase{anonymous reviewer} said, 
it's as \tstidxword{exhilarating} as watching a \tstidxword{yuppie}
eating a \tstidxphrase{yule log} soaked in \tstidxphrase{yoghurt}.
Hmm, \tstidxword{yummy}\tstidxdash or \tstidxword{yuck}, depending
on your tastes.% 
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock
{%
 Oh, did I tell you about the \tstidxphrase{vice-president} who was
 a \tstidxword{Viking} in a \tstidxword{vignette}? No? Well, I can't
 quite remember the \tstidxword{story} myself, but it had something
 to do with a \tstidxphrase{vice admiral} with a
 \tstidxphrase{Victoria plum} and a \tstidxphrase{viceroy} with
 a \tstidxphrase{Victoria sponge}, or was it 
 \tstidxphrase{vice versa}? The \tstidxphrase{vice chancellor}
 preferred \tstidxword{vichyssoise}.
 For \tstidxphrase{letter ordering} use the \tstidxappopt{makeindex}{-l} option
 with \tstidxapp{makeindex} or the \texttt{ord/letorder} module
 with \tstidxapp{xindy} (\tstidxappopt{xindy}{-M ord/letorder}). 
 If you omit this, the default
 \tstidxphrase{word ordering} is used. The ordering in the
 \tstidxbook{Compact Oxford English Dictionary} (third edition,
 revised) for these words are: vice admiral, vice chancellor, vice-president, 
 \tstidxword{viceregal}, viceroy, vice versa. Quick 
 \tstidxword{quizz}. Can you get \tstidxapp{makeindex} or
 \tstidxapp{xindy} to reproduce that order?%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\tstidxnewblock*{\@tidx@close@testidxsty}%
{%
 This is the final \tstidxword{block} of dummy text
 provided by the \tstidxclosesty{testidx} package. This block
 contains the close of a \tstidxword{range} that was started in block~1.
 Fun, wasn't it?%
}
%    \end{macrocode}
%\iffalse
%    \begin{macrocode}
%</testidx.sty>
%    \end{macrocode}
%\fi
%\Finale
\endinput
