% \iffalse meta-comment
%
% Copyright (C) 2011 by Charles P. Schaum <charles dot schaum at att dot net>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Charles P. Schaum.
%
% This work consists of the files nameauth.dtx and nameauth.ins
% and the derived filebase nameauth.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{nameauth.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesPackage{nameauth}
%<*package>
    [2012/04/24 v1.26 name authority macros to aid consistent display and indexing of names]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{ifxetex}
\usepackage{ifluatex}
\usepackage{ifpdf}
\ifxetex
  \usepackage{fontspec}
  \defaultfontfeatures{Mapping=tex-text}
  \usepackage{xunicode}
  \usepackage{xltxtra}
\else
  \ifluatex
    \usepackage{fontspec}
    \defaultfontfeatures{Ligatures=TeX}
  \else
    \usepackage[utf8]{inputenc}
    \usepackage[TS1,T1]{fontenc}
    \usepackage{newunicodechar}
    \usepackage{lmodern}
    \DeclareTextSymbolDefault{\textlongs}{TS1}
    \DeclareTextSymbol{\textlongs}{TS1}{115}
    \newunicodechar{ſ}{\textlongs}
    \newunicodechar{ā}{\=a}
    \newunicodechar{ṃ}{\d m}
  \fi
\fi
\usepackage{makeidx}
\usepackage{multicol}
\usepackage[toc]{multitoc}
\usepackage{nameauth}[2012/04/24]
\usepackage{hypdoc}
\makeindex
\frenchspacing
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{nameauth.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{1180}
%
% \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         \~}
%
%
% \changes{v0.7}{2011/12/26}{Initial version}
% \changes{v0.75}{2012/01/19}{New features added and described}
% \changes{v0.8}{2012/01/29}{Improved function and compatibility; added quick start guide}
% \changes{v0.85}{2012/02/05}{Added comma suppression, new class options, and more functionality}
% \changes{v0.86}{2012/02/06}{Fixed some regressions}
% \changes{v0.9}{2012/02/10}{Added first name formatting; comma and suffix handling expandable}
% \changes{v0.92}{2012/02/12}{Build with all major \LaTeX{} engines}
% \changes{v0.94}{2012/02/15}{Added index suppression, error checking, name particle caps}
% \changes{v0.95}{2012/02/17}{Bugfixes}
% \changes{v0.96}{2012/02/19}{Bugfixes}
% \changes{v1.0}{2012/02/20}{Works fully with \textsf{microtype} and \textsf{memoir}}
% \changes{v1.1}{2012/03/08}{Fixed errors when emitting warnings}
% \changes{v1.2}{2012/03/25}{Added tagging features; extensively edited documentation}
% \changes{v1.22}{2012/04/20}{Attempted first-use particle caps}
% \changes{v1.24}{2012/04/21}{Reverted functionality and suggested \cmd{\CapThis} workaround}
% \changes{v1.26}{2012/04/24}{Fixed sorting of name suffixes in index}
%
% \DoNotIndex{\@empty, \@gobble, \@period, \@token, \if@nameauth@DoComma, \if@nameauth@DoFormat, \if@nameauth@Punct, \if@nameauth@DoIndex, \if@nameauth@Comma, \if@nameauth@DoCaps, \protected@edef, \zap@space, \bfseries, \bgroup, \csgdef, \csundef,  \DeclareDocumentCommand, \DeclareOption, \def, \detokenize, \edef, \egroup, \else, \endcsname, \endinput, \ExecuteOptions, \expandafter, \fi, \Forenames, \futurelet \if, \IfBooleanTF, \ifcsname,\IfValueTF,  \ifx, \index, \itshape, \let, \newcommand, \newenvironment, \newif, \PackageWarning, \ProcessOptions, \relax, \renewcommand, \RequirePackage, \scshape, \space, \Shortnames, \Surnames, \Surnamesi, \Surnamesii, \Test, \TestDot, \TestEnd, \TestPunct, \TestStop, \uppercase}
%
% \TagName{Louis}[the Pious]{, emperor}\TagName{Ptolemy I}[Soter]{, king}\TagName{Henry}[VIII]{, English king}\TagName{Charles}[the Bald]{, emperor}\TagName{Francis, I}{, French king}\TagName{Demetrius, I Soter}{, king}\TagName{Charles, V}{, emperor}\TagName{Louis, XIV}{, French king}%
%
% \GetFileInfo{nameauth.dtx}
% \title{The \textsf{nameauth} package}
% \author{Charles P. Schaum \\ \texttt{charles dot schaum at att dot net}}
% \date{\fileversion~from \filedate}
% \maketitle
%
% \begin{abstract}
% \noindent Using the \textsf{nameauth} package, an author can encode names according to a name authority. Index entries are consistent with input parameters. In-text formatting of names is predictable and automated, making it easier to go from drafts to a final manuscript. This package mainly supports Western names, with basic features for ancient, royal, and Eastern names.
% \end{abstract}
%
% \tableofcontents
% \clearpage
%
% \section{Introduction}
%
% Suppose you were working on a collection of essays. Different publishers' permissions may force you to accept variance in the spelling of people's names. You would track and index those names using a name authority. Your index might use abbreviated name forms. This package allows the author to encode names so that the time and cost of an editor and proofreader can be minimized. This could make an author more desirable for publication. Features include:
% \begin{multicols}{2}
% \begin{itemize}\setlength\itemsep{0pt}\small
% \item Simultaneous printing and indexing of names with fuller, typographically distinct first references.
% \item Printing alternate forenames, yet indexing a canonical form.
% \item Basic handling of variant names.
% \item Basic formatting and indexing tasks.
% \item Automatic addition of tags to names in indexes.
% \end{itemize}
% \end{multicols}
%
% \subsection{Typesetting, Indexing, and Design}
%
% This package depends on \textsf{etoolbox} and \textsf{xparse.} It has been tested with \textsf{latex}, \textsf{lualatex}, \textsf{pdflatex} and \textsf{xelatex}, as well as \textsf{makeindex} and \textsf{texindy}. This file was typeset with \ifxetex\textsf{xelatex}\else\ifluatex\ifpdf\textsf{lualatex} in \texttt{pdf} mode\else\textsf{lualatex} in \texttt{dvi} mode\fi\else\ifpdf\textsf{pdflatex}\else\textsf{latex}\fi\fi\fi{} and \textsf{makeindex}. The default options and design of this package try to minimize keystrokes or trade extra work for benefits in formatting and consistency. The \texttt{.dtx} file is also a good source of information.
%
% \subsection{Thanks}
%
% Thanks to \Name[Marc van]{Dongen}, \Name[Enrico]{Gregorio}, \Name[Philipp]{Stephani}, \Name[Heiko]{Oberdiek}, \Name[Uwe]{Lueck}, and \Name[Robert]{Schlicht} for their invaluable assistance. \FName[Marc van]{Dongen}[Marc] showed me the basic structure using the \textsf{xparse} package. \FName[Enrico]{Gregorio} and \FName[Philipp]{Stephani} helped with generating control sequences and sanitizing. \FName[Heiko]{Oberdiek} gave a space-removing solution that could be passed as an argument in a macro. Code adapted from \FName[Uwe]{Lueck}'s work on the texhax list and the sagacious advice of \FName[Robert]{Schlicht}  enabled the routines to function with the \textsf{microtype} package.
%
% \subsection{Disclaimer}
% This documentation uses names of historical figures. Users will refer to real-world figures in their projects. At no time in this document am I intending either to promote, disparage, or make any assertions about any persons living or dead. All names mentioned herein deserve respect for the impact and legacy of their bearers.
% \clearpage
%
% \section{Usage}
%
% \subsection{Package Options}
% The defaults are \texttt{mainmatter}, \texttt{smallcaps}, \texttt{nocomma}, and \texttt{index}. With these options, the package begins immediately to format the first occurrences of names with small caps using a longer version of the name if one exists. It suppresses commas between surnames and suffixes and it indexes all names in place. The following class options alter this behavior.\\
%
% \begin{quote}\small
% \begin{tabular}{lp{3in}}
% \texttt{mainmatter} & Use special typesetting for the first occurrence of a name, starting at the beginning of a document.\\[1ex]
% \texttt{frontmatter} & Suppress the special typesetting \emph{before} the invocation of \cmd{\NamesActive}. This option fits well, e.g., with front matter from a contributor who may not intend the same formatting and emphasis found in the main matter. The ``first use'' mechanism used with this option works independently of the ``first use'' mechanism after the invocation of \cmd{\NamesActive}. Indexing and aliasing features remain consistent. See also Section \ref{sec:SectionFormat}.\\[0.25ex]\hline
% {\large\strut}\texttt{smallcaps} & Set the first use of a name in small caps.\\[1ex]
% \texttt{italic} & Italicize the first occurrence of a name.\\[1ex]
% \texttt{boldface} & Set the first use of a name in boldface.\\[1ex]
% \texttt{noformat} & This option suppresses name formatting \emph{after} the invocation of \cmd{\NamesActive}. It does not prevent formatting like the \texttt{frontmatter} option. Additional formatting options are discussed in Section \ref{sec:formatting}, which works differently than the methods in Section \ref{sec:SectionFormat}.\\[0.25ex]\hline
% {\large\strut}\texttt{nocomma} & Suppress commas between surnames and suffixes, following modern styles like \emph{Chicago Manual of Style}. See also Section \ref{sec:suffix}.\\[1ex]
% \texttt{comma} & Retain commas between surnames and suffixes. This imposes limits on the use of certain macros.\\[0.25ex]\hline
% {\large\strut}\texttt{index} & Create index entries in place with the names.\\[1ex]
% \texttt{noindex} & Prevent indexing before the invocation of the macro \cmd{\IndexActive}. See also Section \ref{sec:SectionIndex}.\\
% \end{tabular}
% \end{quote}
% \clearpage
%
% \subsection{Quick Start Guide}
%
% This gets one using about 60\% of the package features right away.
%
% \label{sec:start}
%
% \subsubsection{Rules of Thumb}
% \begin{multicols}{2}\small
% \begin{itemize}\setlength\itemsep{0pt}
% \item Use \cmd{\frenchspacing}.
% \item The indexed forms of the names remain the same if you follow the macro input charts consistently.
% \item Examine index entries to find and correct mistakes.
% \item Trade work for consistency.
% \item Use just the macros you \emph{need}.
% \end{itemize}
% \end{multicols}
%
% \subsubsection{Basic Naming}
% \begin{multicols}{2}\small
% \noindent The macro used most often is \cmd{\Name}. When referring to a name for the first time, the following macros all have the same result:
% \begin{enumerate}\setlength\itemsep{0pt}
% \item First reference: \ForgetName[John]{Smith}\Name[John]{Smith}\\[0.5ex]
% |\Name*[John]{Smith}| or\\ |\Name[John]{Smith}| or\\ |\FName[John]{Smith}|
% \item First mononym reference: \ForgetName{Plato}\Name{Plato}\\[0.5ex]
% |\Name*{Plato}| or\\ |\Name{Plato}| or\\ |\FName{Plato}|
% \end{enumerate}
% Subsequent references to names have a different format depending on the macro used:
% \begin{enumerate}\setlength\itemsep{0pt}
% \item Subsequent full name: \Name*[John]{Smith}\\[0.5ex]
% |\Name*[John]{Smith}|
% \item Subsequent surname: \Name[John]{Smith}\\[0.5ex]
% |\Name[John]{Smith}|
% \item Subsequent forename: \FName[John]{Smith}\\[0.5ex]
% |\FName[John]{Smith}|
% \item Subsequent mononym: \Name{Plato}\\[0.5ex]
% |\Name*{Plato}| or\\ |\Name{Plato}| or\\ |\FName{Plato}|
% \end{enumerate}
% These next examples work with or without the \texttt{comma} option. \cmd{\AKA} and \cmd{\PName} cannot cross-reference these forms. Page \pageref{sec:Intermediate}, Section \ref{sec:suffix}, and Section \ref{sec:pennames} address this issue with different solutions.
% \begin{enumerate}\setlength\itemsep{0pt}
% \item First Eastern ref: \ForgetName{Mao}[Tse-tung]\Name{Mao}[Tse-tung]\\[0.5ex]
% |\Name*{Mao}[Tse-tung]| or\\ |\Name{Mao}[Tse-tung]|
% \item Subsequent references: \Name*{Mao}[Tse-tung]\\[0.5ex]
% |\Name*{Mao}[Tse-tung]|
% \item Subsequent references: \Name{Mao}[Tse-tung]\\[0.5ex]
% |\Name{Mao}[Tse-tung]| or\\ |\FName{Mao}[Tse-tung]|
% \item First royal: \ForgetName{Louis}[the Pious]\Name{Louis}[the Pious]\\[0.5ex]
% |\Name*{Louis}[the Pious]| or\\ |\Name{Louis}[the Pious]| or\\ |\FName{Louis}[the Pious]|
% \item Subsequent refs: \Name*{Louis}[the Pious]\\[0.5ex]
% |\Name*{Louis}[the Pious]|
% \item Subsequent references: \Name{Louis}[the Pious]\\[0.5ex]
% |\Name{Louis}[the Pious]| or\\ |\FName{Louis}[the Pious]|
% \item First ancient: \ForgetName{Ptolemy I}[Soter]\Name{Ptolemy I}[Soter]\\[0.5ex]
% |\Name*{Ptolemy I}[Soter]| or\\ |\Name{Ptolemy I}[Soter]| or\\ |\FName{Ptolemy I}[Soter]|
% \item Subsequent refs: \Name*{Ptolemy I}[Soter]\\[0.5ex]
% |\Name*{Ptolemy I}[Soter]|
% \item Subsequent refs: \Name{Ptolemy I}[Soter]\\[0.5ex]
% |\Name{Ptolemy I}[Soter]| or\\ |\FName{Ptolemy I}[Soter]|
% \item First royal: \ForgetName{Henry}[VIII]\Name{Henry}[VIII]\\[0.5ex]
% |\Name*{Henry}[VIII]| or\\ |\Name{Henry}[VIII]| or\\ |\FName{Henry}[VIII]|
% \item Subsequent refs: \Name*{Henry}[VIII]\\[0.5ex]
% |\Name*{Henry}[VIII]|
% \item Subsequent references: \Name{Henry}[VIII]\\[0.5ex]
% |\Name{Henry}[VIII]| or\\ |\FName{Henry}[VIII]|
% \end{enumerate}
% These examples show printing of alternate forenames, keeping the same name in the index. They use both the first and final optional parameters of \cmd{\Name} and friends.
% \begin{enumerate}\setlength\itemsep{0pt}\small
% \item Long first ref: \ForgetName[J.Q.]{Public}\Name[J.Q.]{Public}[Jane Q.]\\[0.5ex]
% |\Name*[J.Q.]{Public}[Jane Q.]| or\\ |\Name[J.Q.]{Public}[Jane Q.]| or\\ |\FName[J.Q.]{Public}[Jane Q.]|
% \item Different forenames, same surname: \Name*[J.Q.]{Public}[Jane Qetsiyah]\\[0.5ex]
% {\footnotesize |\Name*[J.Q.]{Public}[Jane Qetsiyah]|}
% \item Subsequent name: \Name*[J.Q.]{Public}\\[0.5ex]
% |\Name*[J.Q.]{Public}|
% \item Alternate forename: \FName[J.Q.]{Public}[Janie]\\[0.5ex]
% |\FName[J.Q.]{Public}[Janie]|
% \end{enumerate}
% \end{multicols}
%
% \subsubsection{Intermediate Naming}
% \label{sec:Intermediate}
% \begin{multicols}{2}\small
% \noindent Always use a comma to delimit suffixes, followed by a space or thin space. \cmd{\AKA} and \cmd{\PName} will cross-reference these forms. See also Section \ref{sec:suffix}. Macros that are too wide for the column are split across lines using the comment token, but need not be so in the text.
% \begin{enumerate}\setlength\itemsep{0pt}
% \item First: \ForgetName[George S.]{Patton, Jr.}\Name[George S.]{Patton, Jr.}\\[0.5ex]
% {\footnotesize |\Name*[George S.]{Patton, Jr.}| or\\ |\Name[George S.]{Patton, Jr.}| or\\ |\FName[George S.]{Patton, Jr.}|}
% \item Subsequent full: \Name*[George S.]{Patton, Jr.}\\[0.5ex]
% |\Name*[George S.]{Patton, Jr.}|
% \item Subsequent surname: \Name[George S.]{Patton, Jr.}\\[0.5ex]
% |\Name[George S.]{Patton, Jr.}|
% \item Subsequent forename: \FName[George S.]{Patton, Jr.}[George]\\[0.5ex]
% |\FName[George S.]{Patton, Jr.}%|\\|[George]|
% \end{enumerate}
% These cases depend on the default \texttt{nocomma} option, whereby one can use comma suppression to implement forms of ancient, royal and Eastern names. By avoiding the final optional parameter of \cmd{\Name} and friends, \cmd{\AKA} and \cmd{\PName} will cross-reference these forms.
%
% |\Name{Ptolemy I}[Soter]| (see above) keeps the number with the name. Below, the form |\Name{Demetrius, I Soter}| keeps the number with the sobriquet. To keep the number with the name, use |\Name{Demetrius I, Soter}|.
% \begin{enumerate}\setlength\itemsep{0pt}
% \item First reference: \ForgetName{Francis, I}\Name{Francis, I}\\[0.5ex]
% |\Name*{Francis, I}| or\\ |\Name{Francis, I}| or\\ |\FName{Francis, I}|
% \item Subsequent full name: \Name*{Francis, I}\\[0.5ex]
% |\Name*{Francis, I}|
% \item Subsequent name: \Name{Francis, I}\\[0.5ex]
% |\Name{Francis, I}| or\\ |\FName{Francis, I}|
% \item First reference: \ForgetName{Demetrius, I Soter}\Name{Demetrius, I Soter}\\[0.5ex]
% |\Name*{Demetrius, I Soter}| or\\ |\Name{Demetrius, I Soter}| or\\ |\FName{Demetrius, I Soter}|
% \item Next full name: \Name*{Demetrius, I Soter}\\[0.5ex]
% |\Name*{Demetrius, I Soter}|
% \item Subsequent name: \Name{Demetrius, I Soter}\\[0.5ex]
% |\Name{Demetrius, I Soter}| or\\ |\FName{Demetrius, I Soter}|
% \item First reference: \ForgetName{Sun, Yat-sen}\Name{Sun, Yat-sen}\\[0.5ex]
% |\Name*{Sun, Yat-sen}| or\\ |\Name{Sun, Yat-sen}| or\\ |\FName{Sun, Yat-sen}|
% \item Subsequent full name: \Name*{Sun, Yat-sen}\\[0.5ex]
% |\Name*{Sun, Yat-sen}|
% \item Subsequent name: \Name{Sun, Yat-sen}\\[0.5ex]
% |\Name{Sun, Yat-sen}| or\\ |\FName{Sun, Yat-sen}|
% \end{enumerate}
% Particulate names contain prepositions that refer to an ancestral place or name. The following illustrate the American style of particulate names.
% \begin{enumerate}\setlength\itemsep{0pt}
% \item First: \Name[Walter]{de la Mare}\\[0.5ex]
% |\Name*[Walter]{de la Mare}| or\\ |\Name[Walter]{de la Mare}| or\\ |\FName[Walter]{de la Mare}|
% \item Next reference: \Name[Walter]{de la Mare}\\[0.5ex]
% |\Name[Walter]{de la Mare}|
% \item At start of sentence: \CapThis\Name[Walter]{de la Mare}\\[0.5ex]
% |\CapThis\Name[Walter]{de la Mare}|
% \item Forename: \FName[Walter]{de la Mare}\\[0.5ex]
% |\FName[Walter]{de la Mare}|
% \end{enumerate}
% \label{FirstVonLast}
% The following examples illustrate the Continental style of particulate names. Forms 1--4 keep the particles with the names in the index. Forms 5--7 omit the particles in the index by using alternate forenames. Long commands are split using the comment token, but need not be so in the text.
% \begin{enumerate}\setlength\itemsep{0pt}
% \item The (admittedly long) first use:\\\Name[Johann Wolfgang von]{Goethe}\\[0.5ex]
% |\Name*[Johann Wolfgang von]%|\\|{Goethe}| or\\ |\Name[Johann Wolfgang von]%|\\|{Goethe}| or\\ |\FName[Johann Wolfgang von]%|\\|{Goethe}|
% \item Subsequent: \Name[Johann Wolfgang von]{Goethe}\\[0.5ex]
% |\Name[Johann Wolfgang von]%|\\|{Goethe}|
% \item Forenames: \FName[Johann Wolfgang von]{Goethe}[Johann Wolfgang]\\[0.5ex]
% |\FName[Johann Wolfgang von]%|\\ |{Goethe}[Johann Wolfgang]|
% \item First: \Name[Adolf]{Harnack}[Adolf von]\\[0.5ex]
% |\Name*[Adolf]{Harnack}[Adolf von]|\,or\\ |\Name[Adolf]{Harnack}[Adolf von]|\,or\\ |\FName[Adolf]{Harnack}[Adolf von]|
% \item Next full name: \Name*[Adolf]{Harnack}[Adolf von]\\[0.5ex]
% |\Name*[Adolf]{Harnack}[Adolf von]|
% \item Subsequent surname: \Name[Adolf]{Harnack}[Adolf von]\\[0.5ex]
% |\Name[Adolf]{Harnack}[Adolf von]| or |\Name[Adolf]{Harnack}|
% \item Subsequent forename: \FName[Adolf]{Harnack}\\[0.5ex]
% |\FName[Adolf]{Harnack}|
% \end{enumerate}
% \end{multicols}
%
% \subsubsection{Common Pitfalls}
% Avoiding the following pitfalls will save much time and frustration:
% \begin{enumerate}\setlength\itemsep{0pt}
% \item Mixing sobriquets with modern forms fails due to the ``alternate name'' feature that replaces the first with the final optional parameters, e.g.:\\ |\Name[First]{Ancient}[Sobriquet]|\\ |\Name[King]{Number}[Sobriquet]|
% \item Using \cmd{\AKA} and \cmd{\PName} with forms that use the final optional parameter of \cmd{\Name} and friends will fail unless one uses comma-delimited suffixes. See Section \ref{sec:suffix} and Section \ref{sec:AKA}.
% \item Using a forename or first initials can prevent failure in some cases:\\[0.5ex]{\footnotesize OK: |\Name[J.]{Kreskin}[The Amazing] (\AKA[J.]{Kreskin}[Joseph]{Kresge})|\\[0.5ex] FAIL: |\Name[]{Kreskin}[The Amazing] (\AKA{Kreskin}[Joseph]{Kresge})|\\[0.5ex] FAIL: |\Name{Kreskin}[The Amazing] (\AKA{Kreskin}[Joseph]{Kresge})|}
% \item \cmd{\Name} can shorten a reference even if you use the full name in the text. Do not depend on the name you see when you are typing. Depend on the form of the macro, whether \cmd{\Name}, \cmd{\Name*}, or \cmd{\FName}.
% \item Unbalanced or incorrect \texttt{\{} braces \texttt{\}} and \texttt{[} brackets \texttt{]}, putting a star |*| after |\FName|, and forgetting periods in initials create errors that can be difficult to track. Leading spaces in macro arguments will create incorrectly sorted index entries. The results are usually a failure to finish scanning the document or a spurious index entry.
% \end{enumerate}
%
% \subsection{Naming Macros}
%
% \subsubsection{Surnames: \cmd{\Name} and \cmd{\Name*}}
% 
% \DescribeMacro{\Name}
% \DescribeMacro{\Name*}
% This macro generates two forms of the name: a printed form in the text and a form of the name that occurs in the index.
% The general syntax is:
% \begin{quote}
% \cmd{\Name}\oarg{forename(s)}\marg{surname(s)}\oarg{alternate names}\\
% \cmd{\Name*}\oarg{forename(s)}\marg{surname(s)}\oarg{alternate names}
% \end{quote}
%
% \noindent From now on we will abbreviate \meta{forename(s)} with \meta{FNN} and \meta{surname(s)} with \meta{SNN} at various points. The following table helps to show how the syntax description works with first and subsequent references:
%
% \begin{quote}\small
% \begin{tabular}{llll}\hline
% {\large\strut}\meta{FNN} & \meta{SNN} & \meta{Alternate Names} & Result\\\hline
% \texttt{Albert} & \texttt {Einstein} & (none) & \Name[Albert]{Einstein}\\
% \texttt{Albert} & \texttt {Einstein} & (none) & \Name[Albert]{Einstein}\\
% (none) & \texttt{Confucius} & (none) & \Name{Confucius}\\
% (none) & \texttt{Confucius} & (none) & \Name{Confucius}\\
% \texttt{M.T.} & \texttt{Cicero} & \texttt{Marcus Tullius} & \Name[M.T.]{Cicero}[Marcus Tullius]\\
% \texttt{M.T.} & \texttt{Cicero} & \texttt{Marcus Tullius} & \Name[M.T.]{Cicero}[Marcus Tullius]\\
% (none) & \texttt{Charles} & \texttt{the Bald} & \Name{Charles}[the Bald]\\
% (none) & \texttt{Charles} & \texttt{the Bald} & \Name{Charles}[the Bald]\\\hline
% \end{tabular}
% \end{quote}
%
% \noindent Basically, \cmd{\Name} connects the \meta{FNN} to the \meta{SNN} to create respective printed and indexed forms, usually \meta{FNN}\,\meta{SNN} and \meta{SNN},\,\meta{FNN}. This takes care of most Western names. For those with one name, such as ancient figures or stage names, one can drop the \meta{FNN} so that \cmd{\Name} produces the result \meta{SNN} for both text and index.\cmd{\Name} always prints the surname or ``base name.''
%
% Sometimes you might want to have the option of using either an alternate set of forenames, like a nickname, or a sobriquet that functions as a surname for ancient figures. These two alternatives are handled by the final, optional field of \cmd{\Name}. If ``regular'' \meta{FNN} are present, then the alternate names conditionally will replace the \meta{FNN} in the printed form, but not in the indexed form. If no regular \meta{FNN} are present, then the alternate names will be appended to the \meta{SNN} in the printed form \emph{and} in the indexed form. You may choose to include or exclude nicknames and such, but you must always use the sobriquet form of a name consistently.
%
% I mentioned conditional use. The unstarred form prints the ``full name'' at the first occurrence, then only the partial form thereafter. The starred form always prints the full name. Both macros usually apply a different ``font  attribute'' to the name when it first appears in the running text.
%
% As long as the ``main'' \meta{FNN} are constant in Western-style names, the ``alternate names'' field can vary, yet the index entries will be constant. Section  \ref{sec:start} contains examples that illustrate this ability to swap out forenames. This is useful when dropping out references to middle initials in \cmd{\FName}. Alternate forenames only get printed in subsequent occurrences of \cmd{\Name*} and \cmd{\FName}. The surname argument is \emph{always} printed in \cmd{\Name*} and \cmd{\Name}.
%
% Another option employs a ``sobriquet'' feature for royal names and basic Eastern names. \cmd{\AKA} and \cmd{\PName} cannot refer to these forms, although they can use these forms in the \emph{second} name argument to construct a cross-reference. A workaround is discussed in Section \ref{sec:suffix}. The following method is the only one that works with the \texttt{comma} option. Valid ``sobriquet'' forms are:\\
%
% \bgroup\footnotesize\ForgetName{Henry}[VIII]
% \begin{tabular}{llp{1.2cm}ll}\hline
% {\normalsize\strut}\meta{FNN} & \meta{SNN} & \meta{Alternate Names} & Result & Function\\\hline
% (none) & \texttt{Henry} & \texttt{VIII} & \Name{Henry}[VIII] & |\Name{Henry}[VIII]|\\
% (none) & \texttt{Henry} & \texttt{VIII} & \Name{Henry}[VIII] & |\Name{Henry}[VIII]|\\\hline
% (none) & \texttt{Chiang} & \texttt{Kai-shek} & \Name{Chiang}[Kai-shek] & |\Name{Chiang}[Kai-shek]|\\
% (none) & \texttt{Chiang} & \texttt{Kai-shek} & \Name{Chiang}[Kai-shek] & |\Name{Chiang}[Kai-shek]|\\\hline
% \end{tabular}
% \egroup\bigskip
%
% \noindent Again, alternate forenames \emph{override} the \meta{FNN} in the text. Sobriquets are \emph{appended} to \meta{SNN}. The presence or absence of \meta{FNN} triggers this difference between the two actions---\textbf{this is a central concept}. 
%
% \emph{Note}: Throughout this manual I play a ``dirty trick'' that makes a name print as if it had not yet occurred. In some cases I make a first occurrence print as if the name already had occurred. This trick can be used, for example, to force the formatting of the first name in a chapter or section. See Section \ref{sec:Tweaks} for more.
%
% \subsubsection{Forenames: \cmd{\FName}}
%
% \DescribeMacro{\FName}
% This casual friend of \cmd{\Name} prints only ``first'' names except if a first use occurs, whereupon it prints a full, formatted name as set by the class options or the formatting macros. \cmd{\FName} is intended for Western-style names. The syntax is basically the same:
% \begin{quote}
% \cmd{\FName}\oarg{FNN}\marg{SNN}\oarg{alternate names}
% \end{quote}
% Remember that \cmd{\FName} \emph{has no starred form}. Next we see what it does:
%
% \begin{quote}\small
% \begin{tabular}{llll}\hline
% {\large\strut}\meta{FNN} & \meta{SNN} & \meta{Alternate Names} & Result\\\hline
% \texttt{Albert} & \texttt {Einstein} & (none) & \FName[Albert]{Einstein}\\
% (none) & \texttt{Confucius} & (none) & \FName{Confucius}\\
% \texttt{M.T.} & \texttt{Cicero} & \texttt{Marcus Tullius} & \FName[M.T.]{Cicero}[Marcus Tullius]\\
% (none) & \texttt{Charles} & \texttt{the Bald} & \FName{Charles}[the Bald]\\\hline
% \end{tabular}
% \end{quote}
%
% \noindent If one accidentally referred to |\FName[Max]{Planck}| as a first reference, that would appear as \FName[Max]{Planck}. otherwise it would just be \FName[Max]{Planck}. For nicknames use the ``alternate names'' option. For example, aviation hero \Name[Chesley B.]{Sullenberger, III} can be noted as:
%
% \begin{quote}|``\FName[Chesley B.]{Sullenberger, III}[Sully]''|\quad``\FName[Chesley B.]{Sullenberger, III}[Sully]''\end{quote}
%
%\noindent A good way to cut keystrokes would be to assign the above macro to the control sequence \cmd{\Sully}. With comma-delimited suffixes we note special cases governed by the \texttt{nocomma} class option (see Section \ref{sec:suffix}). These include names like like \FName[J.D.]{Rock, III} and \FName{Charles, V}:
% \begin{quote}|\FName[J.D.]{Rock, III}|, ``\FName[J.D.]{Rock, III},'' |\FName{Charles, V}|, ``\FName{Charles, V}''\end{quote}
% \cmd{\FName} suppresses extra periods if a forename with initials occurs at the end of a sentence, as in the plot-line ``who shot \FName[J.D.]{Rock, III}.'' See also Section \ref{sec:suffix}.
%
% \subsection{Advanced Naming Topics}
% \subsubsection{Naming Conventions}
%
% \DescribeMacro{\CapThis}
% English names with the particles \emph{de}, \emph{de\ la}, \emph{d'}, \emph{von}, \emph{van}, and \emph{ten} generally keep them with the last name, using varied capitalization. \emph{Le}, \emph{La}, and \emph{L'} are capitalized unless preceded by \emph{de}. In English, these particles go in the \meta{SNN} field of \cmd{\Name}, e.g., \ForgetName[Walter]{de la Mare}\Name[Walter]{de la Mare}. To capitalize the first particle in a subsequent \cmd{\Name} reference at the beginning of a sentence, use |\CapThis\Name[Walter]{de la Mare}|. \CapThis\Name[Walter]{de la Mare} will think it fair. \textsc{Du Cange}\IndexName{du Cange}\SubvertName{du Cange} (\AKA{du Cange}[Charles]{du Fresne}) might disagree. For the present, at the start of a sentence, use |\textsc{Du Cange}\IndexName{du Cange}\SubvertName{du Cange}|.
%
% Names foreign to English usually put these particles in the \meta{FNN} field of \cmd{\Name}. Yet these particles are not first names. Using \cmd{\FName} with alternate forenames avoids the particles. See the examples on page \pageref{FirstVonLast}.

%
% \subsubsection{Hyphenation}
%
% I find it helpful to use respectively the \textsf{babel} or \textsf{polyglossia} packages with name hyphenation. If one is using English as the main language, the default hyphenation patterns may not suffice. For example, the name \Name[John]{Strietelmeier} may break thus: ``Stri-etelmeier.'' That is fixed by creating a \cmd{\de} macro equivalent to |\newcommand{\de}[1]{\foreignlanguage{ngerman}{#1}}| (using \textsf{babel}) and writing |\de{\Name[John]{Strietelmeier}}|.
%
% One can insert optional hyphens in the arguments of \cmd{\Name} and friends but that must be done \emph{consistently} to avoid variants being treated as different names.
%
% \subsubsection{Suffix Removal}
% \label{sec:suffix}
% 
% \cmd{\Name}---not \cmd{\Name*}---truncates comma-delimited suffixes from last names. For example, it prints the name \Name[Oskar]{Hammerstein, II} the first time and \Name[Oskar]{Hammerstein, II} thereafter. One must always use a comma to activate this, e.g., |\Name[Oskar]{Hammerstein, II}|. You should use a space or a thin space after the comma in order to separate the suffix from the surname.
%
% Again, \textbf{the comma is not optional with suffixes}. It is how this feature works. More than one comma in the \meta{SNN} argument of \cmd{\Name} and friends will cause unwanted results. Fortunately, that is unlikely.
%
%  These macros keep track of whether the name ends with the period of an abbreviation like ``Jr.'' and ``Sr.'' That should also work with abbreviations like ``d.\,\"{A}.'' (\textit{der \"{A}ltere}). Two periods are not printed when the full name is printed at the end of a sentence. The following example shows the combinations:
% 
% \ForgetName[Martin Luther]{King, Jr.}%
% \begin{quote}\small
% \begin{tabular}{ll}
% |\Name[Martin Luther]{King, Jr.}.| & \Name[Martin Luther]{King, Jr.}.\\
% |\Name[Martin Luther]{King, Jr.}.| & \Name[Martin Luther]{King, Jr.}.\\
% |\Name[Martin Luther]{King, Jr.}| & \Name[Martin Luther]{King, Jr.} (e.g., in a sentence)\\
% |\Name*[Martin Luther]{King, Jr.}.| & \Name*[Martin Luther]{King, Jr.}.\\
% |\Name*[Martin Luther]{King, Jr.}| & \Name*[Martin Luther]{King, Jr.}
% \end{tabular}
% \end{quote}
%
% Using the default class option \texttt{nocomma} with suffix removal, one can take advantage of the suffix feature to tweak more possibilities out of \cmd{\Name}. Instead of the sobriquet feature, one could use the following variants:
%
% \begin{quote}\small\ForgetName{Sun, Yat-sen}
% \begin{tabular}{llp{1.2cm}ll}\hline
% {\large\strut}\meta{FNN} & \meta{SNN} & \meta{Alternate Names} & Result & Function\\\hline
% (none) & \texttt{Louis, XIV} & (none) & \Name{Louis, XIV} & |\Name{Louis, XIV}|\\
% (none) & \texttt{Louis, XIV} & (none) & \Name{Louis, XIV} & |\Name{Louis, XIV}|\\
% (none) & \texttt{Sun, Yat-sen} & (none) & \Name{Sun, Yat-sen} & |\Name{Sun, Yat-sen}|\\
% (none) & \texttt{Sun, Yat-sen} & (none) & \Name{Sun, Yat-sen} & |\Name{Sun, Yat-sen}|\\\hline
% \end{tabular}
% \end{quote}
%
% \noindent The benefit to using this form is that one can type |\Name*{Louis, XIV}, the| |``\AKA{Louis, XIV}{Sun King}''| and get \Name*{Louis, XIV}, the ``\AKA{Louis, XIV}{Sun King}'' in the text with an appropriate reference from ``Sun King'' to ``Louis XIV'' in the index. The sobriquet feature would otherwise prevent such usage.
%
% Even though suffix and sobriquet features look like they produce the same \emph{output} in the body text using the \texttt{nocomma} option, they are internally \emph{different}. They will not respect each other regarding ``first use,'' although they will (tentatively) cooperate in the index. Use each approach consistently. An example of ``dangerous'' use of these features occurs in Section \ref{sec:formatting}. The \texttt{comma} option will cause these forms above to have commas and behave differently.
%
% \subsubsection{Accented Names}
% \label{sec:accents}
% 
% The following Unicode characters are available using \textsf{inputenc}/\textsf{fontenc}:
% \begin{quote}
% \begin{tabular}{llll}
% \scshape À Á Â Ã Ä Å Æ & \scshape Ç È É Ê Ë & \scshape Ì Í Î Ï Ð Ñ & \scshape first use \\
% À Á Â Ã Ä Å Æ & Ç È É Ê Ë & Ì Í Î Ï Ð Ñ & second use \\[1ex]
% \scshape Ò Ó Ô Õ Ö Ø & \scshape Ù Ú Û Ü Ý & \scshape Þ ß & \scshape first use \\
% Ò Ó Ô Õ Ö Ø & Ù Ú Û Ü Ý & Þ ß & second use \\[1ex]
% \scshape à á â ã ä å æ & \scshape ç è é ê ë & \scshape ì í î ï ð ñ & \scshape first use \\
% à á â ã ä å æ & ç è é ê ë & ì í î ï ð ñ & second use \\[1ex]
% \scshape ò ó ô õ ö ø & \scshape ù ú û ü ý & \scshape þ ÿ & \scshape first use \\
% ò ó ô õ ö ø & ù ú û ü ý & þ ÿ & second use \\[1ex]
% \scshape Ă ă Ą ą Ć ć Č č & \scshape Ď ď Đ đ Ę ę Ě ě & \scshape Ğ ğ İ ı & \scshape first use \\
% Ă ă Ą ą Ć ć Č č & Ď ď Đ đ Ę ę Ě ě & Ğ ğ İ ı & second use \\[1ex]
% \scshape Ĳ ĳ Ľ ľ Ł ł & \scshape Ń ń Ň ň Œ œ & \scshape Ŕ ŕ Ř ř & \scshape first use \\
% Ĳ ĳ Ľ ľ Ł ł & Ń ń Ň ň Œ œ & Ŕ ŕ Ř ř & second use \\[1ex]
% \scshape Ś Ş ş Š š Ţ ţ Ť ť & \scshape Ů ů Ű ű & \scshape Ź ź Ż ż Ž ž & \scshape first use \\
% Ś Ş ş Š š Ţ ţ Ť ť & Ů ů Ű ű & Ź ź Ż ż Ž ž &  second use \\
% \end{tabular}
% \end{quote}
% Please remember that if you use accented names, you may prefer using \textsf{xindy} (or \textsf{texindy}) on the \texttt{.idx} file. It simplifies the whole process and I recommend it.
%
%With \textsf{makeindex} there are a number of solutions, but some depend on the availability of the |-g| option and user-created settings in an |.ist| file whose description goes beyond the scope of this document. You also could use \cmd{\IndexActive} and \cmd{\IndexInactive} to suppress indexing, then create manual entries. For non-English documents, however, that solution is not optimal.
% 
% One may add control sequences to names, thanks to the help of \Name*[Robert]{Schlicht}. The next example adds more accented characters under \textsf{inputenc}/\textsf{fontenc}:
%  \begin{quote}\small
% |\usepackage{newunicodechar}|\\
% |\DeclareTextSymbolDefault{\textlongs}{TS1}|\\
% |\DeclareTextSymbol{\textlongs}{TS1}{115}|\\
% |\newunicodechar{ſ}{\textlongs}|\\
% |\newunicodechar{ā}{\=a}|\\
% |\newunicodechar{ṃ}{\d m}|
% \end{quote}
% For some situations, such as ``traditional'' NFSS, you will need fonts with TS1 glyphs, e.g., |\usepackage{lmodern}|. See the informative tables on pages 455--63 in \emph{The Latex Companion}. This allows |\Name{Ghazāli}| to generate \IndexInactive\Name{Ghazāli}\IndexActive.
%
% In some cases, indexing accented names will fail unless you use \textsf{xetex} or \textsf{luatex}, both of which use \textsf{fontspec} instead of NFSS. Control sequences like |\=a| fail even in manual index entries when using \textsf{makeindex} and \texttt{gind.ist} because the equal sign is interpreted as a ``literal'' character, as mentioned by \Name[Dan]{Luecking}. I used |\IndexInactive\Name{Ghazāli}\IndexActive| to prevent the index entry ``ali'' sorted under ``Ghaz'' because even the manual entry fails in that case.
%
% It is important that this package work in the context of multiple languages. The use of multiple typesetting engines facilitates that. This snippet from the preamble to this file allows it to be typeset with multiple engines.\\
%
% \begin{tabular}{ll}
% |\usepackage{ifxetex}|\\
% |\usepackage{ifluatex}|\\
% |\ifxetex| & |% uses fontspec|\\
% \hbox{\quad}|\usepackage{fontspec}|\\
% \hbox{\quad}|\defaultfontfeatures{Mapping=tex-text}|\\
% \hbox{\quad}|\usepackage{xunicode}|\\
% \hbox{\quad}|\usepackage{xltxtra}|\\
% |\else|\\
% \hbox{\quad}|\ifluatex| & |% also uses fontspec|\\
% \hbox{\quad}\hbox{\quad}|\usepackage{fontspec}|\\
% \hbox{\quad}\hbox{\quad}|\defaultfontfeatures{Ligatures=TeX}|\\
% \hbox{\quad}|\else| & |% traditional NFSS|\\
% \hbox{\qquad}|\usepackage[utf8]{inputenc}|\\
% \hbox{\qquad}|\usepackage[TS1,T1]{fontenc}|\\
% \hbox{\quad}|\fi|\\
% |\fi|
% \end{tabular}\\
% \clearpage
%
% I used the following in the text itself to allow for conditional processing that helps one document work under multiple engines:\\
%
% \begin{tabular}{l}
% |\ifxetex |\meta{xelatex text}|%|\\
% |\else%|\\
% \hbox{\quad}|\ifluatex%|\\
% \hbox{\qquad}|\ifpdf |\meta{lualatex in pdf mode text}|%|\\
% \hbox{\qquad}|\else |\meta{lualatex in dvi mode text}|%|\\
% \hbox{\qquad}|\fi%|\\
% \hbox{\quad}|\else%|\\
% \hbox{\qquad}|\ifpdf |\meta{pdflatex text}|%|\\
% \hbox{\qquad}|\else |\meta{latex text}|%|\\
% \hbox{\qquad}|\fi%|\\
% \hbox{\quad}|\fi%|\\
% |\fi|
% \end{tabular}
%
% \subsubsection{Name Formatting}
% \label{sec:formatting}
%
% \DescribeMacro{\NamesFormat}
% The first instance of a name is formatted with \cmd{\NamesFormat}. In addition to using the class options, one can redefine \cmd{\NamesFormat}. For example, if you wanted to suppress formatting in footnotes, you could do something like:
%
% \begin{quote}
% |\makeatletter|\\
% |\let\@oldfntext\@makefntext|\\
% |\long\def\@makefntext#1{\def\NamesFormat{}\@oldfntext{#1}}|\\
% |\makeatother|
% \end{quote}
%
% \noindent This approach synchronizes the ``first use'' feature in the text and the footnotes, but only suppresses the formatting. It takes advantage of the deep nesting of \cmd{\@makefntext} and a localized \cmd{\def} to make a temporary change.
%
% A second example puts the mention of first names in the margin. The code below gives us:
% \let\oldformat\NamesFormat
% \renewcommand{\NamesFormat}[1]{\textbf{#1}\ifinner\else\marginpar{\scriptsize #1}\fi}
%
% \begin{quote}
% \bgroup\small\ttfamily
% |\let\oldformat\NamesFormat|\\
% |\renewcommand{\NamesFormat}[1]{\textbf{#1}%|\\
% |\ifinner\else\marginpar{\scriptsize #1}\fi}|
%
% |\Name{Vlad III}[Dracula]| was known as Vlad Ţepeş, ``The Impaler,''\break  after his death. He was the son of |\Name{Vlad II}%| |[Dracul]|, a\break member of the Order of the Dragon. Later references to\break |\Name{Vlad III}[Dracula]| appear thus.\egroup
%
% \Name{Vlad III}[Dracula] was known as Vlad Ţepeş, ``The Impaler,''  after his death. He was the son of \Name{Vlad II}[Dracul], a member of the Order of the Dragon. Later references to \Name{Vlad III}[Dracula] appear thus.
% \end{quote}
%
% \noindent The forms above do not work with \cmd{\PName} and \cmd{\AKA}. Consistently use either the suffix mechanism (Section \ref{sec:suffix}) or see Section \ref{sec:pennames} regarding manual entries. If you use the suffix mechanism, you would use the following forms:
%
%\begin{quote}\ForgetName{Vlad III}[Dracula]\ForgetName{Vlad II}[Dracul]
% \bgroup\small\ttfamily |\Name{Vlad III, Dracula}| was known as |\AKA{Vlad III, Dracula}%|\break|{Vlad}[Ţepeş]|, |``\AKA*{Vlad III, Dracula}{Vlad}[the Impaler],''|\break  after his death. He was the son of |\Name{Vlad II, Dracul}|, a\break member of the Order of the Dragon. Later references to\break |\Name{Vlad III, Dracula}| appear thus.\egroup
%
% \Name{Vlad III, Dracula} was known as \AKA{Vlad III, Dracula}%
% {Vlad}[Ţepeş], ``\AKA*{Vlad III, Dracula}{Vlad}[the Impaler],''  after his death. He was the son of \Name{Vlad II, Dracul}, a member of the Order of the Dragon. Later references to \Name{Vlad III, Dracula} appear thus.
% \end{quote}
% \let\NamesFormat\oldformat
%
% \noindent After using \cmd{\let} to revert \cmd{\NamesFormat}, a first occurrence again takes the form: \ForgetName{Vlad III}[Dracula]\Name{Vlad III}[Dracula], while subsequent references are to \Name{Vlad III}[Dracula].
%
% The ``Dracula'' example  above was manipulated extensively. Mixing the sobriquet and suffix forms otherwise may cause errors to ``bite.'' Puns aside, \Name{Vlad III}[Dracula] was a complex historical figure, more so than the character of \Name[Bram]{Stoker}.
%
% \subsubsection{Formatting Certain Sections}
% \label{sec:SectionFormat}
% 
% \DescribeMacro{\NamesActive}
% \DescribeMacro{\NamesInactive}
% Using the \texttt{frontmatter} option deactivates formatting until \cmd{\NamesActive} occurs. Another macro, \cmd{\NamesInactive}, will deactivate formatting again. These two macros toggle two independent systems of formatting and first use.\\
% 
% Here we switch to the ``front matter'' mode with \cmd{\NamesInactive}:
% \NamesInactive
% \begin{quote}
% \begin{tabular}{ll}
% |\Name[Rudolph]{Carnap}| & \Name[Rudolph]{Carnap}\\
% |\Name[Rudolph]{Carnap}| & \Name[Rudolph]{Carnap}\\
% |\Name[Nicolas]{Malebranche}| & \Name[Nicolas]{Malebranche}\\
%|\Name[Nicolas]{Malebranche}| & \Name[Nicolas]{Malebranche}\\
% \end{tabular}
% \end{quote}
% 
% Then we switch back to ``main matter'' mode with \cmd{\NamesActive}:
% \NamesActive
% \begin{quote}
% \begin{tabular}{ll}
% |\Name[Rudolph]{Carnap}| & \Name[Rudolph]{Carnap}\\
% |\Name[Rudolph]{Carnap}| & \Name[Rudolph]{Carnap}\\
% |\Name[Nicolas]{Malebranche}| & \Name[Nicolas]{Malebranche}\\
%|\Name[Nicolas]{Malebranche}| & \Name[Nicolas]{Malebranche}\\
% \end{tabular}
% \end{quote}
% 
%\noindent Notice that we have two cases of ``first use.'' That works fine in different parts of the document, but not within the same part. Avoid using \cmd{\NamesInactive} to turn off formatting in footnotes because that can produce undesirable results like the example above. Fixing that would require use of the tweaking macros in both body text and footnotes. Instead, use the example for suppressing formatting in Section \ref{sec:formatting} and apply tweaks like \cmd{\ForgetName} in the body text as needed.
%
% \subsubsection{Tweaks: \cmd{\ForgetName} and \cmd{\SubvertName}}
% \label{sec:Tweaks}
% 
% These two macros are meant for tweaking text at or near final draft stage. They affect both front matter and main matter.
%
% \DescribeMacro{\ForgetName}
% This macro is a ``dirty trick'' of sorts that takes the same optional and mandatory parameters used by \cmd{\Name}. It handles its arguments in the same way, except that it ignores the final parameter if \meta{FNN} are present. The syntax is:
% \begin{quote}
% \cmd{\ForgetName}\oarg{FNN}\marg{SNN}\oarg{alternate names}
% \end{quote}
%
% \noindent This macro causes \cmd{\Name} and friends to ``forget'' prior uses of a name with respect to typesetting. The next use will print as if it were a ``first use.'' Index entries and pseudonyms (see above) are \emph{never} forgotten.
% 
% \DescribeMacro{\SubvertName}
% This macro is the opposite of the one above. It takes the same parameters. It handles its arguments in the same manner. The syntax is:
% \begin{quote}
% \cmd{\SubvertName}\oarg{FNN}\marg{SNN}\oarg{alternate names}
% \end{quote}
%
% \noindent This macro causes \cmd{\Name} and friends to think that a prior use of a name already has occurred. The next use will print as if it were a ``subsequent use.''
%
% \subsection{Name Variant Macros}
% \subsubsection{Introduction and Manual Index Entries}
% \label{sec:pennames}
% 
% The macro \cmd{\AKA} deals with pseudonyms, stage names, \emph{noms de plume}, etc. With this macro we move into a hybrid naming/indexing area of functionality. \cmd{\Name} and friends produce index entries compatible with manual index entries since version 0.9. If needed, the \texttt{.idx} file can be a helpful reference when linking manual entries with \textsf{nameauth} entries.
%
% Before we examine \cmd{\AKA} in detail, we should cover the manual solution that \cmd{\AKA} helps to automate. This remains the only solution for name forms that use the final optional parameter of \cmd{\Name} and friends, especially if one chooses the \texttt{comma} option. It also is the only option for using special formatting in the text.
%
% \begin{quote}
% \bgroup\ttfamily\small
% \verb!\index{Jean the Fearless|see{Jean sans Peur}}%!\\
% |\Name{Jean}[sans Peur]| (Jean the Fearless) reigned as Duke of\break Burgundy from 1404 to 1419.
% \egroup
%
% \TagName{Jean}[sans Peur]{, duke}%
% \index{Jean the Fearless|see{Jean sans Peur}}%
% \Name{Jean}[sans Peur] (Jean the Fearless) reigned as Duke of Burgundy from 1404 to 1419.
% \end{quote}
%
% \noindent The suffix workaround would use |\Name{Jean, sans Peur}| but be careful; see Section \ref{sec:formatting}.  A more complicated example is:
% \begin{quote}
% \bgroup\ttfamily\footnotesize
% \verb!\index{Doctor Angelicus@\textit{Doctor Angelicus}|see{Thomas Aquinas}}%!\\
% \verb!\index{Thomas of Aquino|see{Thomas Aquinas}}%!\\
% Perhaps the greatest medieval theologian was |\Name{Thomas}[Aquinas]|\break (Thomas of Aquino), also known as |\textit{Doctor Angelicus}|. His name\break ``Aquinas'' is not a surname, so many modern scholars simply refer to him\break as |\Name{Thomas}[Aquinas]|.
% \egroup
%
% \index{Doctor Angelicus=\textit{Doctor Angelicus}|see{Thomas Aquinas}}%
% \index{Thomas of Aquino|see{Thomas Aquinas}}%
% Perhaps the greatest medieval theologian was \Name{Thomas}[Aquinas] (Thomas of Aquino), also known as \textit{Doctor Angelicus}. His name ``Aquinas'' is not a surname, so many modern scholars simply refer to him as \Name{Thomas}[Aquinas].
% \end{quote} 
%
% \noindent This case must be handled manually due to the italic text formatting.
% \subsubsection{\cmd{\AKA}}
% \label{sec:AKA}
%
% \DescribeMacro{\AKA}
% \DescribeMacro{\AKA*}
% The primary macro that handles aliases is \cmd{\AKA}. Its syntax is:
% \begin{quote}
% \cmd{\AKA}\oarg{FNN}\marg{SNN}\oarg{alt. FNN}\marg{alt. SNN}\oarg{alt. names}\\
% \cmd{\AKA*}\oarg{FNN}\marg{SNN}\oarg{alt. FNN}\marg{alt. SNN}\oarg{alt. names}
% \end{quote}
%
% \noindent The \meta{FNN} and \meta{SNN} arguments \emph{do not include} the final optional argument of \cmd{\Name} to avoid ambiguity. \cmd{\AKA} will not create a \emph{see} reference to a name with a sobriquet or to an Eastern name unless one uses the suffix feature mentioned previously. This macro is designed with Western names in mind.
%
% \cmd{\AKA} only prints the alternate name. It assumes that a \cmd{\Name} macro occurs somewhere to create the page-indexed target of a cross-reference. No error checking otherwise occurs for this. The macro also prevents double periods.
%
% Here is a quick review of what works and what fails:
%
% \begin{quote}\footnotesize
% \begin{tabular}{llllll}\hline
% {\normalsize\strut}\meta{FNN} & \meta{SNN} & \meta{Alt. FNN} & \meta{Alt. SNN} & \meta{Alt. names} & Result \\\hline
% {\small\strut}\texttt{Bob} & \texttt{Hope} & \texttt{Leslie Townes} & \texttt{Hope} & (none) & success\\
% {\small\strut}\dag\texttt{Bob} & \texttt{Hope} & \texttt{Leslie Townes} & \texttt{Hope} & \texttt{Lester T.} & success\\\hline
% {\small\strut}(none) & \texttt{Louis} & \texttt{XIV} & \texttt{Sun King} & (none) & FAIL\\
% {\small\strut}\ddag(none) & \texttt{Louis, XIV} & (none) & \texttt{Sun King} & (none) & success\\\hline
% {\small\strut}(none) & \texttt{Gregory} & \texttt{I} & \texttt{Gregory} & \texttt{the Great} & FAIL\\
% {\small\strut}\S (none) & \texttt{Gregory, I} & (none) & \texttt{Gregory} & \texttt{the Great} & success\\\hline
% \end{tabular}
%
% \smallskip\dag{} This succeeds, but replaces ``Leslie Townes'' with ``Lester T.''\\
% \ddag{} This form uses the \texttt{nocomma} feature.\\
% \S{} This produces different output, depending on whether \cmd{\AKA} or \cmd{\AKA*} is used.
% \end{quote}
%
% \noindent \cmd{\AKA} prints an alternate name and creates a cross reference in the index. The target of this cross-reference is either \meta{SNN}, \meta{FNN} or just \meta{SNN}. In the cross-reference, the \meta{alternate names} replace the \meta{alternate FNN} if both exist. Otherwise the \meta{alternate names} follow the \meta{alternate SNN}.
%
% If the starred form \cmd{\AKA*} is used with the template \meta{none}\marg{alternate SNN}\oarg{alt. names}, it only prints the \meta{alt. names}. With the same template, \cmd{\AKA} prints \meta{alternate SNN} followed by \meta{alt. names}. Section \ref{sec:TagName} offers a complete presentation of related features. A brief example follows:
% 
% \begin{quote}
% \bgroup\ttfamily
% Today we consider |\AKA[George]{Eliot}[Mary Anne]{Evans}| and her literary contributions as |\Name[George]{Eliot}|.
% \egroup
%
% Today we consider \AKA[George]{Eliot}[Mary Anne]{Evans} and her literary contributions as \Name[George]{Eliot}.
% \end{quote}
% 
% \noindent The cross-references generated by \cmd{\AKA} and \cmd{\AKA*} cannot be used with other macros in this package. See also Section \ref{sec:error}.
%
% In certain cases, the alternate name might need to be indexed with page numbers. Do not use \cmd{\AKA} if that is so. Use \cmd{\Name} for both the main and the alternate names. Then create manual cross-references with \cmd{\index}, e.g.:\label{Rambam}\bigskip
%
% \bgroup\footnotesize\index{Rambam|seealso{Maimonides}}
% \begin{tabular}{p{0.7in}ll}\hline
% Authoritative Name & Alternate Name & Example of Use\\\hline
% \Name{Maimonides} & \AKA{Maimonides}{Moses ben-Maimon} & |\AKA{Maimonides}{Moses ben-Maimon}|\\
% \Name{Maimonides} & \Name{Rambam} & |\Name{Rambam}%|\\& & \verb!\index{Rambam|seealso{Maimonides}}!\\\hline
% \end{tabular}
% \egroup
%
% \bigskip\noindent\cmd{\AKA} will not create multiple instances of a cross-reference. This allows the macro \cmd{\ExcludeName} to work, but it also prevents the special case where one moniker applies to multiple people, e.g.: \PName*[Willebrord]{Snel van Royen}{Snellius} and his son \PName*[Rudolph]{Snel van Royen}{Snellius}. \cmd{\AKA} produces the first cross-reference; the user manually creates the second:
% \index{Snellius|see{Snel van Royen, Rudolph}}%
% \begin{quote}
% \verb!\index{Snellius|see{Snel van Royen, Rudolph}}!
% \end{quote}
% 
% \subsubsection{\cmd{\PName}}
%
% \DescribeMacro{\PName}
% \cmd{\PName} is a ``convenience macro'' that sacrifices flexibility for simplicity. It does not implement \cmd{\AKA*} and it works best with Western-style names. It calls \cmd{\Name} or \cmd{\Name*} and prints a Western-style ``main'' name. It then always calls \cmd{\AKA} with a full alternate name and prints it in parentheses. The syntax is:
% \begin{quote}
% \cmd{\PName}\oarg{FNN}\marg{SNN}\oarg{lesser-known FNN}\marg{lesser-known SNN}
% \end{quote}
%
% \noindent The author determines the name that is indexed (the first name) and the subsequent name that only occurs as a \emph{see} reference. For example:
%
% \begin{quote}
% |\PName*[Mark]{Twain}[Samuel L.]{Clemens}| compared to\\
% |\PName[Mark]{Twain}[Samuel L.]{Clemens}|\\
% Print \PName*[Mark]{Twain}[Samuel L.]{Clemens} the first time it appears. Later, print \PName*[Mark]{Twain}[Samuel L.]{Clemens}. The form \cmd{\PName} later just prints \PName[Mark]{Twain}[Samuel L.]{Clemens}.\\[1ex]
% |\PName*{Voltaire}[François-Marie]{Arouet}| and\\
% |\PName{Voltaire}[François-Marie]{Arouet}|\\
% Print \PName{Voltaire}[François-Marie]{Arouet} the first time it appears. Later, print \PName{Voltaire}[François-Marie]{Arouet}.
% \end{quote}
%
% \noindent If you use the unstarred forms  \cmd{\PName} and \cmd{\Name}, you must remember that, just because you include a full name as a parameter does not mean that the full name will print. You could end up with ambiguous references to the same last name, e.g., ``Snel van Royen.'' You are responsible for checking this.
%
% \subsection{Indexing Macros}
% \subsubsection{\cmd{\IndexName}}
% 
% \DescribeMacro{\IndexName}
% This macro creates an index entry like those created by \cmd{\Name} and friends. It prints no text in the body and permits no special formatting. The syntax is:
% \begin{quote}
% \cmd{\IndexName}\oarg{FNN}\marg{SNN}\oarg{alternate names}
% \end{quote}
% \cmd{\IndexName} does not index the alternate names unless \meta{FNN} are absent. If indexing is switched off (see Section \ref{sec:SectionIndex}), this macro does nothing. It will not create index entries for names that have been used as cross-references.
%
% \subsubsection{\cmd{\TagName}}
% \label{sec:TagName}
%
% \DescribeMacro{\TagName}
% This macro creates a tag that will appear in all index entries corresponding to the name arguments from the point of invocation of \cmd{\TagName} onward. For consistency throughout the document, tag names at the beginning. The syntax is:
% \begin{quote}
% \cmd{\TagName}\oarg{FNN}\marg{SNN}\oarg{alternate names}\marg{tag}
% \end{quote}
% Tags created by \cmd{\TagName} can be helpful in the indexes of history texts. Several features of this package are designed for historical research. Suppose you are working with medieval subject matter. The following macros come in handy:\\
%
% \begin{tabular}{p{2in}p{2in}}
% |\TagName{Leo, I}{, pope}| |\TagName{Gregory, I}{, pope}| & Tag these names at the beginning of the document.\TagName{Leo, I}{, pope}\TagName{Gregory, I}{, pope}\\
% \dots & \\
% |\Name{Leo, I}| |\Name{Gregory, I}| & First references to \Name{Leo, I} and \Name{Gregory, I}\\
% \dots & \\
% |\Name*{Leo, I} was known as| |\AKA{Leo, I}{Leo}[the Great].| & \Name*{Leo, I} was known as \AKA{Leo, I}{Leo}[the Great].\\
% \dots & \\
% |\Name{Gregory, I}| |``\AKA*{Gregory, I}%| |{Gregory}[the Great]''| & \Name{Gregory, I} ``\AKA*{Gregory, I}{Gregory}[the Great]'' was another major pope.\\
% \end{tabular}\\
%
% \noindent \cmd{\TagName} causes tags in the index entries to be inserted automatically from the point of invocation. \cmd{\AKA} prints the name and the sobriquet, while \cmd{\AKA*} only prints the sobriquet, One could do similarly with emperors, kings, etc.
%
% \subsubsection{\cmd{\UntagName}}
%
% \DescribeMacro{\UntagName}
% This macro removes a tag created by \cmd{\TagName}. The syntax is:
% \begin{quote}
% \cmd{\UntagName}\oarg{FNN}\marg{SNN}\oarg{alternate names}
% \end{quote}
% \cmd{\TagName} will replace one tag with another tag, but it does not remove a tag from a name. That is the role of \cmd{\UntagName}. By using these two commands, one can disambiguate different people with the same name. For example:\\
%
% \begin{tabular}{p{2in}p{2in}}
% |\ForgetName[John]{Smith}| |\TagName[John]{Smith}%| |{, the other one}| |\Name[John]{Smith}|\dots & This is the first reference to \ForgetName[John]{Smith}\TagName[John]{Smith}{, the other one}\Name[John]{Smith}, ``the other one'' in the index. Notice that it is tweaked.\\
% |\ForgetName[John]{Smith}| |\TagName[John]{Smith}%| |{, the third}| |\Name[John]{Smith}|\dots & This refers to \ForgetName[John]{Smith}\TagName[John]{Smith}{, the third}\Name[John]{Smith} ``the third'' in the index. It is tweaked again as a ``first occurrence.''\\
% |\SubvertName[John]{Smith}| |\UntagName[John]{Smith}| |\Name*[John]{Smith}| & This refers to the \SubvertName[John]{Smith}\UntagName[John]{Smith}\Name*[John]{Smith} in the quick start guide. It is tweaked in order to force a subsequent reference.\\
% \end{tabular}\\
%
% \noindent Tagging and untagging in this manner requires the author to juggle more info. With more freedom comes more responsibility.
%
% \subsubsection{\cmd{\ExcludeName}}
% 
% \DescribeMacro{\ExcludeName}
% This prevents \cmd{\Name}, etc. from both formatting and indexing a specific name, but \emph{only if that name has not been used}. See also Section \ref{sec:error}. The syntax is:
% \begin{quote}
% \cmd{\ExcludeName}\oarg{FNN}\marg{SNN}\oarg{alternate names}
% \end{quote}
% To suppress only indexing but retain formatting, enclose \cmd{\Name}, etc. between \cmd{\IndexInactive} and \cmd{\IndexActive}.
%
% \subsubsection{Indexing Certain Sections}
% \label{sec:SectionIndex}
%
% \DescribeMacro{\IndexActive}
% \DescribeMacro{\IndexInactive}
% Using the \texttt{noindex} option deactivates indexing until \cmd{\IndexActive} occurs. Another macro, \cmd{\IndexInactive}, will deactivate indexing again. These can be used throughout the document, independently of \cmd{\ExcludeName}.
%
% \subsubsection{Variant Spellings}
%
% Handling variant name spellings can be complicated, but one could create macros on a per-case basis to make it easier. For example, one might settle on the form \Name[W.E.B.]{Du Bois} in one's name authority. Yet an essay could use \IndexInactive\Name*[W.E.B.]{DuBois}\IndexActive, where the publisher would not grant the right to alter the spelling. In that case, do the following in that document section:
%
% \begin{enumerate}\setlength\itemsep{0pt}
% \item In those cases where the only variation in the name is spacing (as above), you must call \cmd{\ForgetName} to generate a ``first use'' of the alternate spelling. The ``first use'' mechanism ignores spaces.
% \item In all cases of the variant spelling, wrap \cmd{\Name} and friends between \cmd{\IndexInactive} and \cmd{\IndexActive}. A macro can do this easily.
% \item Call \cmd{\IndexName} with the authoritative form right after \cmd{\IndexActive}. Again, this can be part of a macro.
% \end{enumerate}
%
% This looks cumbersome, but it ensures accuracy. It cannot be reduced to an all-purpose macro because that would generate an ambiguous argument list. It should only be used in those cases where minor variations in spelling do not cause the reader to question the identity of the person in question.
%
% \subsection{Error Handling}
% \label{sec:error}
%
% Except for the indexing macros, most of the macros in this package print any erroneous arguments in the text without formatting. Unless there is a syntax error, all macros emit meaningful warnings. The convenience macros do not emit warnings; however, their component macros do. For example, \cmd{\PName} produces warnings via \cmd{\Name} and \cmd{\AKA}.
%
% Not all warnings are created equal. For example, the multiple creation of a cross-reference with \cmd{\AKA} will generate a warning, but it will have no ill effects. Some warnings, especially in the case of indexing macros, indicate that the macro produced no output.
%
% Examine the warning messages and check the index in order to find possible errors. Warnings result from:
%
% \begin{enumerate}\setlength{\itemsep}{-0.4ex}
% \item Using a cross-reference \oarg{alternate FNN}\marg{alternate SNN}\oarg{alt. names} created by \cmd{\AKA} as a reference in \cmd{\Name}, \cmd{\FName}, and \cmd{\PName}.
% \item Using a reference \oarg{FNN}\marg{SNN}\oarg{alternate names} created by \cmd{\Name}, \cmd{\FName}, and \cmd{\PName} as a cross-reference in \cmd{\AKA}.
% \item Using \cmd{\AKA} to create the same cross-reference multiple times.
% \item Using \cmd{\IndexName} to index a cross-reference as a main entry.
% \item Using \cmd{\TagName} to tag a cross-reference.
% \item Using \cmd{\ExcludeName} to exclude a name that has already been used.
% \end{enumerate}
% \clearpage
%
% \StopEventually{\PrintChanges\clearpage\PrintIndex}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
% \subsection{Class Options and Required Packages}
%
%    \begin{macrocode}
\newif\if@nameauth@DoFormat
\newif\if@nameauth@DoIndex
\newif\if@nameauth@DoComma
%    \end{macrocode}
% These Boolean values control formatting, index suppression, and comma suppression. They all may be set with class options. The first two can be toggled with \cmd{\NamesActive}---\cmd{\NamesInctive} and \cmd{\IndexActive}---\cmd{\IndexInctive}.\\
%
%    \begin{macrocode}
\newif\if@nameauth@Comma
\newif\if@nameauth@Punct
%    \end{macrocode}
% These Boolean values are used internally for detection of suffixes and final periods.\\
%
%    \begin{macrocode}
\newif\if@nameauth@DoCaps
%    \end{macrocode}
% This Boolean triggers capitalization in \cmd{\Name} of particles like \emph{de la} that may occur at the start of a sentence.\\
%
%    \begin{macrocode}
\DeclareOption{mainmatter}{\@nameauth@DoFormattrue}
\DeclareOption{frontmatter}{\@nameauth@DoFormatfalse}
\DeclareOption{smallcaps}{\newcommand{\NamesFormat}{\scshape}}
\DeclareOption{italic}{\renewcommand{\NamesFormat}{\itshape}}
\DeclareOption{boldface}{\renewcommand{\NamesFormat}{\bfseries}}
\DeclareOption{noformat}{\renewcommand{\NamesFormat}{}}
\DeclareOption{comma}{\@nameauth@DoCommatrue}
\DeclareOption{nocomma}{\@nameauth@DoCommafalse}
\DeclareOption{index}{\@nameauth@DoIndextrue}
\DeclareOption{noindex}{\@nameauth@DoIndexfalse}
\ExecuteOptions{smallcaps,mainmatter,nocomma,index}
\ProcessOptions\relax
\RequirePackage{etoolbox}
\RequirePackage{xparse}
%    \end{macrocode}
% The options above interact with the prior Boolean values. Suppressing and showing commas is set at load time and should not be changed in the document or else significant errors will result. Most options can be changed with user interface macros.\\
%
% \subsection{Internal Macros}
% \begin{macro}{\@nameauth@CleanName}
% \changes{v0.8}{2012/01/29}{Renamed macro to help compatibility}
%    \begin{macrocode}
\newcommand*{\@nameauth@CleanName}[1]%
{%
  \expandafter\zap@space\detokenize{#1} \@empty%
}
%    \end{macrocode}
% \end{macro}
% Thanks to \Name*[Heiko]{Oberdiek}, this macro produces a ``sanitized'' string based on the forename/surname parameters of \cmd{\Name} and friends. With this we can construct a control sequence name. Testing for the presence of that control sequence determines the existence of pseudonyms and the first occurrence of a name.\bigskip\hrule\bigskip
% \noindent The following macros parse a ``base'' name into a radix and a suffix. They are designed so that their function occurs at the time of macro expansion, not execution. This expandability is key to the proper indexing function of this package. They form the kernel of the suffix removal and comma suppression features.
%
% \begin{macro}{\@nameauth@Root}
% \changes{v0.85}{2012/02/05}{Revise suffix handling}
% \changes{v0.9}{2012/02/10}{renamed macro; suffix handling expandable}
%    \begin{macrocode}
\newcommand*{\@nameauth@Root}[1]%
{%
  \@nameauth@TrimRoot#1\relax%
}
%    \end{macrocode}
% \end{macro}
% Anything starting with a comma and ending with the end of the name is stripped off. That includes ``Sr.,'' ``Jr.,'' ``III,'' and so on. An extra comma is included at the end of the parameter when |\@nameauth@Root| is called directly from \cmd{\Name} and friends so that the delimiter list will always be correct. By using \cmd{\@nameauth@CheckComma} below, one can call this macro only when the parameter takes the form <a,b>. This allows one to select the root and suffix without having a trailing comma hanging about.
%
% \begin{macro}{\@nameauth@TrimRoot}
% \changes{v0.85}{2012/02/05}{Divide suffix handling into functional parts}
% \changes{v0.9}{2012/02/10}{Renamed macro; suffix handling expandable}
%    \begin{macrocode}
\def\@nameauth@TrimRoot#1,#2\relax{#1}
%    \end{macrocode}
% \end{macro}
% This delimited-parameter macro strips off the second parameter as it returns the first.
%
% \begin{macro}{\@nameauth@Suffix}
% \changes{v0.9}{2012/02/10}{added macro}
%    \begin{macrocode}
\newcommand*{\@nameauth@Suffix}[1]%
{%
  \@nameauth@TrimSuffix#1\relax%
}
%    \end{macrocode}
% \end{macro}
% Anything before a comma is stripped off by |\@nameauth@Suffix|, but it should be called only in a conditional governed by the Boolean |@nameauth@Comma| and the macro \cmd{\@nameauth@CheckComma} or else errors will result. This macro calls its auxiliary macro below.
%
% \begin{macro}{\@nameauth@TrimSuffix}
% \changes{v0.9}{2012/02/10}{added macro}
%    \begin{macrocode}
\def\@nameauth@TrimSuffix#1,#2\relax{#2}
%    \end{macrocode}
% \end{macro}
% This delimited-parameter macro strips off the first parameter and returns the second.
%
% \begin{macro}{\@nameauth@CheckComma}
% \changes{v0.85}{2012/02/05}{Add suffix handling functionality}
% \changes{v0.9}{2012/02/10}{Fix comma checking, now expandable}
%    \begin{macrocode}
\newcommand*{\@nameauth@CheckComma}[1]%
{%
  \@nameauth@CheckSuffix#1,\relax%
}
%    \end{macrocode}
% \end{macro}
% This macro checks for a comma-delimited suffix. It calls the auxiliary macro below.
% 
% \begin{macro}{\@nameauth@CheckSuffix}
% \changes{v0.9}{2012/02/10}{Added macro}
%    \begin{macrocode}
\def\@nameauth@CheckSuffix#1,#2\relax%
{%
  \def\Test{#2}%
  \ifx\Test\@empty\@nameauth@Commafalse\else\@nameauth@Commatrue\fi%
}
%    \end{macrocode}
% \end{macro}
% This macro checks for a comma-delimited suffix and sets the Boolean value of |@nameauth@Comma| to true if the suffix is not equal to the empty string.\bigskip\hrule\bigskip
%\noindent The next macros check whether the next token is a period. They are only called if the terminal character produced within \cmd{\Name} and \cmd{\FName} is itself a period.
%
% \begin{macro}{\@nameauth@CheckDot}
% \changes{v0.8}{2012/01/29}{Renamed macro to help compatibility}
%    \begin{macrocode}
\def\@nameauth@CheckDot{\futurelet\@token\@nameauth@EvalDot}
%    \end{macrocode}
% \end{macro}
% This macro assigns the lookahead token \cmd{\@token} to be evaluated by\break \cmd{\@nameauth@EvalDot} while keeping \cmd{\@token} non-destructively on the list of input tokens. This does not gobble spaces like \cmd{\@nextchar}.
%
% \begin{macro}{\@nameauth@EvalDot}
% \changes{v0.8}{2012/01/29}{Renamed macro to help compatibility}
%    \begin{macrocode}
\def\@nameauth@EvalDot%
{%
  \let\@period=.\ifx\@token\@period\expandafter\@gobble \fi%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\@nameauth@EvalDot} checks if \cmd{\@token} is a period. If so it gobbles it by using \cmd{\expandafter} to get past the grouping. Another \cmd{\expandafter} occurs immediately before the invocation of \cmd{\@nameauth@CheckDot} in \cmd{\Name}, \cmd{\FName}, and \cmd{\AKA}.
%
% \begin{macro}{\@nameauth@TestDot}
% \changes{v0.8}{2012/01/29}{Renamed macro to help compatibility}
%    \begin{macrocode}
\newcommand*{\@nameauth@TestDot}[1]%
{%
  \def\TestDot##1.\TestEnd##2\TestStop{\TestPunct{##2}}%
  \def\TestPunct##1%
    {\ifx\TestPunct##1\TestPunct\else\@nameauth@Puncttrue\fi}%
  \@nameauth@Punctfalse%
  \TestDot#1\TestEnd.\TestEnd\TestStop%
}
%    \end{macrocode}
% \end{macro}
% While \cmd{\@nameauth@CheckDot} looks \emph{ahead} for a period, \cmd{\@nameauth@TestDot}---based on a snippet by \Name*[Uwe]{Lueck}---checks for a terminal period in the name passed to it, ignoring medial periods. It always resets the Boolean value before making its test, making it unnecessary to reset elsewhere.\bigskip\hrule\bigskip
%
% \noindent The following macros format the output for \cmd{\Name} and friends.
%
% \begin{macro}{\@nameauth@FmtName}
% \changes{v0.8}{2012/01/29}{Renamed macro to help compatibility}
% \changes{v0.85}{2012/02/05}{Add comma suppression}
% \changes{v0.9}{2012/02/10}{Redesigned macro}
% \changes{v0.94}{2012/02/15}{Added particle caps}
% \changes{v0.95}{2012/02/17}{Fixed incompatibility with \textsf{microtype}}
%    \begin{macrocode}
\DeclareDocumentCommand\@nameauth@FmtName{s m}%
{%
  \@nameauth@DoCapsfalse%
  \@nameauth@TestDot{#2}%
  \IfBooleanTF{#1}%
    {#2}%
    {\bgroup\NamesFormat{#2}\egroup}%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\@nameauth@FmtName} is where the first occurrences of a name are formatted. Notice how \cmd{\NamesFormat} sits between a \cmd{\bgroup} and an \cmd{\egroup} to localize the font change. The \cmd{\NamesFormat} hook has been discussed above.
%
% \begin{macro}{\@nameauth@Index}
% \changes{v0.94}{2012/02/15}{Added macro}
%    \begin{macrocode}
\DeclareDocumentCommand\@nameauth@Index{m o}%
{%
  \IfValueTF{#2}
  {\ifcsname#2\endcsname%
    \if@nameauth@DoIndex\index{#1\csname#2\endcsname}\fi%
  \else%
    \if@nameauth@DoIndex\index{#1}\fi%
  \fi}%
  {\if@nameauth@DoIndex\index{#1}\fi}%
}
%    \end{macrocode}
% \end{macro}
% If the indexing flag is true, create an index entry, otherwise do nothing.\clearpage
%
% \begin{macro}{\@nameauth@CapRoot}
% \changes{v0.95}{2012/02/17}{Added macro}
%    \begin{macrocode}
\newcommand*{\@nameauth@CapRoot}[1]%
{%
  \@nameauth@CR#1\relax%
}
%    \end{macrocode}
% \end{macro}
% This macro implements the particulate name capitalization mechanism. All of the macros that manipulate strings through parametrized expansion appear to work best when called immediately in \cmd{\Name} and \cmd{\FName}.
%
% \begin{macro}{\@nameauth@CR}
% \changes{v0.95}{2012/02/17}{Added macro}
%    \begin{macrocode}
\def\@nameauth@CR#1#2\relax{\uppercase{#1}\@nameauth@Root{#2}}
%    \end{macrocode}
% \end{macro}
% This delimited-parameter macro caps the first parameter and strips suffixes on the second.
%
% \subsection{User Interface Macros}
%
% \begin{macro}{\CapThis}
% \changes{v0.94}{2012/02/15}{Added macro}
%    \begin{macrocode}
\newcommand{\CapThis}%
{%
  \@nameauth@DoCapstrue%
}
%    \end{macrocode}
% \end{macro}
% Toggle the capitalizing of particles. \cmd{\@nameauth@FmtName} always reverts the Boolean to false, thus localizing any changes until this is called again.
%
% \begin{macro}{\Name}
% \changes{v0.75}{2012/01/19}{Added ``sobriquet'' feature}
% \changes{v0.8}{2012/01/29}{Merged all major functionality here}
% \changes{v0.85}{2012/02/05}{Add comma suppression to indexing}
% \changes{v0.9}{2012/02/10}{Redesigned macro}
% \changes{v0.94}{2012/02/15}{Error checking expanded}
% \changes{v0.95}{2012/02/17}{Fixed incompatibility with \textsf{microtype}}
% \changes{v0.96}{2012/02/19}{Fixed occasional incompatibility with \textsf{memoir}.}
% \changes{v1.0}{2012/02/20}{Fixed compatibility issues.}
% \changes{v1.26}{2012/04/24}{Fixed sorting of name suffixes in index}
%    \begin{macrocode}
\DeclareDocumentCommand\Name{s o m o}%
{%
  \protected@edef\Surnames{#3}%
  \protected@edef\Suffix{\@empty}%
  \if@nameauth@DoCaps%
    \protected@edef\Shortnames{\@nameauth@CapRoot{#3,}}%
  \else%
    \protected@edef\Shortnames{\@nameauth@Root{#3,}}%
  \fi%
  \if@nameauth@DoComma\else%
    \@nameauth@CheckComma{#3}%
    \if@nameauth@Comma%
      \protected@edef\Surnames{\@nameauth@Root{#3}\@nameauth@Suffix{#3}}%
      \protected@edef\Suffix{\@nameauth@Suffix{#3}}%
    \fi%
  \fi%
  \IfValueTF{#2}%
  {\IfValueTF{#4}%
    {\def\Forenames{#4}}{\def\Forenames{#2}}%
  \ifcsname\@nameauth@CleanName{#2#3!PN!}\endcsname%
    \expandafter\@nameauth@FmtName\expandafter*\expandafter{%
      \expandafter\Forenames\expandafter\space\Surnames}%
    \PackageWarning{nameauth}%
    {macro Name Cross-reference: #2 #3 cannot be a page reference.}%
  \else%
    \if@nameauth@DoFormat%
      \ifcsname\@nameauth@CleanName{#2#3!MN!}\endcsname%
      \IfBooleanTF{#1}%
        {\expandafter\@nameauth@FmtName\expandafter*\expandafter{%
          \expandafter\Forenames\expandafter\space\Surnames}%
          \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #2}[\@nameauth@CleanName{#2#3}]%
          \else \@nameauth@Index{\Shortnames, #2, \Suffix}[\@nameauth@CleanName{#2#3}]\fi}%
        {\expandafter\@nameauth@FmtName\expandafter*\expandafter{\Shortnames}%
          \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #2}[\@nameauth@CleanName{#2#3}]%
          \else \@nameauth@Index{\Shortnames, #2, \Suffix}[\@nameauth@CleanName{#2#3}]\fi}%
      \else%
        \csgdef{\@nameauth@CleanName{#2#3!MN!}}{}%
        \expandafter\@nameauth@FmtName\expandafter{%
          \expandafter\Forenames\expandafter\space\Surnames}%
          \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #2}[\@nameauth@CleanName{#2#3}]%
          \else \@nameauth@Index{\Shortnames, #2, \Suffix}[\@nameauth@CleanName{#2#3}]\fi%
      \fi%
    \else%
      \ifcsname\@nameauth@CleanName{#2#3!NF!}\endcsname%
      \IfBooleanTF{#1}%
        {\expandafter\@nameauth@FmtName\expandafter*\expandafter{%
          \expandafter\Forenames\expandafter\space\Surnames}%
          \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #2}[\@nameauth@CleanName{#2#3}]%
          \else \@nameauth@Index{\Shortnames, #2, \Suffix}[\@nameauth@CleanName{#2#3}]\fi}%
        {\expandafter\@nameauth@FmtName\expandafter*\expandafter{\Shortnames}%
          \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #2}[\@nameauth@CleanName{#2#3}]%
          \else \@nameauth@Index{\Shortnames, #2, \Suffix}[\@nameauth@CleanName{#2#3}]\fi}%
      \else%
        \csgdef{\@nameauth@CleanName{#2#3!NF!}}{}%
        \expandafter\@nameauth@FmtName\expandafter*\expandafter{%
          \expandafter\Forenames\expandafter\space\Surnames}%
          \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #2}[\@nameauth@CleanName{#2#3}]%
          \else \@nameauth@Index{\Shortnames, #2, \Suffix}[\@nameauth@CleanName{#2#3}]\fi%
      \fi%
    \fi%
  \fi}%
  {\IfValueTF{#4}
    {\ifcsname\@nameauth@CleanName{#3#4!PN!}\endcsname%
      \expandafter\@nameauth@FmtName\expandafter*%
        \expandafter{\Surnames\space#4}%
      \PackageWarning{nameauth}%
      {macro Name Cross-reference: #3 #4 cannot be a page reference.}%
    \else%
      \if@nameauth@DoFormat%
        \ifcsname\@nameauth@CleanName{#3#4!MN!}\endcsname%
        \IfBooleanTF{#1}%
          {\expandafter\@nameauth@FmtName\expandafter*%
            \expandafter{\Surnames\space#4}%
            \@nameauth@Index{\Surnames\space#4}[\@nameauth@CleanName{#3#4}]}%
          {\expandafter\@nameauth@FmtName\expandafter*\expandafter{\Shortnames}%
            \@nameauth@Index{\Surnames\space#4}[\@nameauth@CleanName{#3#4}]}%
        \else%
          \csgdef{\@nameauth@CleanName{#3#4!MN!}}{}%
          \expandafter\@nameauth@FmtName\expandafter{%
            \Surnames\space#4}%
            \@nameauth@Index{\Surnames\space#4}[\@nameauth@CleanName{#3#4}]%
        \fi%
      \else%
        \ifcsname\@nameauth@CleanName{#3#4!NF!}\endcsname%
        \IfBooleanTF{#1}%
          {\expandafter\@nameauth@FmtName\expandafter*%
            \expandafter{\Surnames\space#4}%
            \@nameauth@Index{\Surnames\space#4}[\@nameauth@CleanName{#3#4}]}%
          {\expandafter\@nameauth@FmtName\expandafter*\expandafter{\Shortnames}%
            \@nameauth@Index{\Surnames\space#4}[\@nameauth@CleanName{#3#4}]}%
        \else%
          \csgdef{\@nameauth@CleanName{#3#4!NF!}}{}%
          \expandafter\@nameauth@FmtName\expandafter*%
            \expandafter{\Surnames\space#4}%
            \@nameauth@Index{\Surnames\space#4}[\@nameauth@CleanName{#3#4}]%
        \fi%
      \fi%
    \fi}%
    {\ifcsname\@nameauth@CleanName{#3!PN!}\endcsname%
      \expandafter\@nameauth@FmtName\expandafter*%
        \expandafter{\Surnames}%
      \PackageWarning{nameauth}%
      {macro Name Cross-reference: #3 cannot be a page reference.}%
    \else%
      \if@nameauth@DoFormat%
        \ifcsname\@nameauth@CleanName{#3!MN!}\endcsname%
        \IfBooleanTF{#1}%
          {\expandafter\@nameauth@FmtName\expandafter*%
            \expandafter{\Surnames}%
            \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#3}]}%
          {\@nameauth@FmtName*{\Shortnames}%
            \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#3}]}%
        \else%
          \csgdef{\@nameauth@CleanName{#3!MN!}}{}%
          \expandafter\@nameauth@FmtName\expandafter{\Surnames}%
            \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#3}]%
        \fi%
      \else%
        \ifcsname\@nameauth@CleanName{#3!NF!}\endcsname%
        \IfBooleanTF{#1}%
          {\expandafter\@nameauth@FmtName\expandafter*%
            \expandafter{\Surnames}%
            \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#3}]}%
          {\@nameauth@FmtName*{\Shortnames}%
            \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#3}]}%
        \else%
          \csgdef{\@nameauth@CleanName{#3!NF!}}{}%
          \expandafter\@nameauth@FmtName\expandafter*%
            \expandafter{\Surnames}%
            \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#3}]%
        \fi%
      \fi%
    \fi}%
  }%
  \if@nameauth@Punct\expandafter\@nameauth@CheckDot\fi%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\Name} is the heart of this package. \Name*[Marc van]{Dongen} provided the basic structure.
%
%The reason why one sees seven outcomes repeated three times for twenty-one variations is because one must make different decisions based on the dynamic interaction of many factors beyond mere input. Three choices occur when one tries to use an ``alternate name'' defined by \cmd{\AKA} as an argument to \cmd{\Name}. The latter prints the arguments with comma suppression if appropriate, emits a warning, and exits. One cannot use \cmd{\ForgetName} to expunge a pen name. This is a deliberate decision to avoid corruption of the index cross-references.
%
% Regarding the remaining eighteen branches, one cannot assume that the name will terminate with a suffix like ``Jr.'' until a check has been run to determine if the suffix should be truncated. The Boolean and value parameters offer eight valid patterns of input. The first or subsequent use are two more, as are front or main matter use. Operations on suffixes are governed by the first or subsequent use. The formatting or non-formatting of output is governed both by a formatting Boolean and by first/subsequent use. A final choice deals with handling alternate names in the \cmd{\Forenames} macro.
%
% Here is how these many factors interrelate: \cmd{\Name} first checks for comma suppression. if so it stores a comma-suppressed version of the third parameter in \cmd{\Surnames}. Otherwise it stores an unchanged version in \cmd{\Surnames} and \cmd{\Surnames}. The former needs to be fully expanded for the double-period checking to work, thus using \cmd{\edef}. The latter should not be fully expanded when using the \textsf{memoir} class with the utf8 option of \textsf{inputenc}. This will be passed respectively to \cmd{\@nameauth@FmtName} and \cmd{\@nameauth@Index}.\\
% 
%\noindent \cmd{\Name} then checks for the forenames argument. Two outcomes are possible.
% \begin{enumerate}
% \item Forenames are present. In this case, the alternate names argument creates two choices.
% \begin{enumerate}
% \item The alternate names replace the forenames in the printed form, not the indexed form.
% \item The absence of alternate names will result in the forenames being used for both forms.
% \end{enumerate}
% \item Forenames are absent. In that case, the alternate names argument creates two different choices.
% \begin{enumerate}
% \item The alternate names are appended to the surnames in both printed and indexed forms.
% \item Only the surnames are used.
% \end{enumerate}
% \end{enumerate}
%
% The next branch involves the Boolean value \texttt{@nameauth@DoFormat}, which is controlled by \cmd{\NamesActive} and \cmd{\NamesInactive}. If formatting is active, choose the unstarred form of \cmd{\@nameauth@FmtName}, which applies the formatting hook. Otherwise use the starred form that applies no formatting.
%
% The state of  \texttt{@nameauth@DoFormat} also controls the suffix used in the control sequences: \texttt{!MN!} for main name or \texttt{!NF!} for no format. This is the heart of the \texttt{frontmatter} / \texttt{mainmatter} mechanism.
%
% Where longer and shorter versions of names are printed, there the star parameter controls those outcomes. Comma suppression is used or not, as appropriate, in the index entries. Note again that one must always use commas with suffixes in the input, even if commas are suppressed in the output.
%
% The use of \cmd{\expandafter} before \cmd{\@nameauth@CheckDot} works with the other use of \cmd{\expandafter} mentioned with \cmd{\@nameauth@EvalDot} above to move past the closing brace and fetch the period as lookahead. That is only done when the check for a terminal period in the name succeeds.
%
% \begin{macro}{\FName}
% \changes{v0.9}{2012/02/10}{Added macro}
% \changes{v0.94}{2012/02/15}{Error checking expanded}
% \changes{v0.96}{2012/02/19}{Fixed occasional incompatibility with \textsf{memoir}.}
% \changes{v1.0}{2012/02/20}{Fixed compatibility issues.}
% \changes{v1.26}{2012/04/24}{Fixed sorting of name suffixes in index}
%    \begin{macrocode}
\DeclareDocumentCommand\FName{o m o}%
{%
  \protected@edef\Surnames{#2}%
  \protected@edef\Shortnames{\@nameauth@Root{#2,}}%
  \protected@edef\Suffix{\@empty}%
  \if@nameauth@DoComma\else%
    \@nameauth@CheckComma{#2}%
    \if@nameauth@Comma%
      \protected@edef\Surnames{\@nameauth@Root{#2}\@nameauth@Suffix{#2}}%
      \protected@edef\Suffix{\@nameauth@Suffix{#2}}%
    \fi%
  \fi%
  \IfValueTF{#1}%
  {\IfValueTF{#3}{\edef\Forenames{#3}}{\edef\Forenames{#1}}%
  \ifcsname\@nameauth@CleanName{#1#2!PN!}\endcsname%
    \expandafter\@nameauth@FmtName\expandafter*%
      \expandafter{\Forenames}%
    \PackageWarning{nameauth}%
    {macro FName Cross-reference: #1 #2 cannot be a page reference.}%
  \else%
    \if@nameauth@DoFormat%
      \ifcsname\@nameauth@CleanName{#1#2!MN!}\endcsname%
        \expandafter\@nameauth@FmtName\expandafter*%
          \expandafter{\Forenames}%
        \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #1}[\@nameauth@CleanName{#1#2}]%
        \else \@nameauth@Index{\Shortnames, #1, \Suffix}[\@nameauth@CleanName{#1#2}]\fi%
      \else%
        \csgdef{\@nameauth@CleanName{#1#2!MN!}}{}%
        \expandafter\@nameauth@FmtName\expandafter{%
          \expandafter\Forenames\expandafter\space\Surnames}%
        \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #1}[\@nameauth@CleanName{#1#2}]%
        \else \@nameauth@Index{\Shortnames, #1, \Suffix}[\@nameauth@CleanName{#1#2}]\fi%
      \fi%
    \else%
      \ifcsname\@nameauth@CleanName{#1#2!NF!}\endcsname%
        \expandafter\@nameauth@FmtName\expandafter*%
          \expandafter{\Forenames}%
        \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #1}[\@nameauth@CleanName{#1#2}]%
        \else \@nameauth@Index{\Shortnames, #1, \Suffix}[\@nameauth@CleanName{#1#2}]\fi%
      \else%
        \csgdef{\@nameauth@CleanName{#1#2!NF!}}{}%
        \expandafter\@nameauth@FmtName\expandafter*%
          \expandafter{\Forenames\expandafter\space\Surnames}%
        \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #1}[\@nameauth@CleanName{#1#2}]%
        \else \@nameauth@Index{\Shortnames, #1, \Suffix}[\@nameauth@CleanName{#1#2}]\fi%
      \fi%
    \fi%
  \fi}%
  {\IfValueTF{#3}
    {\ifcsname\@nameauth@CleanName{#2#3!PN!}\endcsname%
      \expandafter\@nameauth@FmtName\expandafter*%
        \expandafter{\Surnames\space#3}%
      \PackageWarning{nameauth}%
      {macro FName Cross-reference: #2 #3 cannot be a page reference.}%
    \else%
      \if@nameauth@DoFormat%
        \ifcsname\@nameauth@CleanName{#2#3!MN!}\endcsname%
          \@nameauth@FmtName*{\@nameauth@Root{#2,}}%
          \@nameauth@Index{\Surnames\space#3}[\@nameauth@CleanName{#2#3}]%
        \else%
          \csgdef{\@nameauth@CleanName{#2#3!MN!}}{}%
          \expandafter\@nameauth@FmtName%
            \expandafter{\Surnames\space#3}%
          \@nameauth@Index{\Surnames\space#3}[\@nameauth@CleanName{#2#3}]%
        \fi%
      \else%
        \ifcsname\@nameauth@CleanName{#2#3!NF!}\endcsname%
          \@nameauth@FmtName*{\@nameauth@Root{#2,}}%
          \@nameauth@Index{\Surnames\space#3}[\@nameauth@CleanName{#2#3}]%
        \else%
          \csgdef{\@nameauth@CleanName{#2#3!NF!}}{}%
            \expandafter\@nameauth@FmtName\expandafter*%
          \expandafter{\Surnames\space#3}%
          \@nameauth@Index{\Surnames\space#3}[\@nameauth@CleanName{#2#3}]%
        \fi%
      \fi%
    \fi}%
    {\ifcsname\@nameauth@CleanName{#2!PN!}\endcsname%
      \expandafter\@nameauth@FmtName\expandafter*%
        \expandafter{\Surnames}%
      \PackageWarning{nameauth}%
      {macro FName Cross-reference: #2 cannot be a page reference.}%
    \else%
      \if@nameauth@DoFormat%
        \ifcsname\@nameauth@CleanName{#2!MN!}\endcsname%
          \@nameauth@FmtName*{\@nameauth@Root{#2,}}%
          \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#2}]%
        \else%
          \csgdef{\@nameauth@CleanName{#2!MN!}}{}%
          \expandafter\@nameauth@FmtName\expandafter{\Surnames}%
          \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#2}]%
        \fi%
      \else%
        \ifcsname\@nameauth@CleanName{#2!NF!}\endcsname%
          \@nameauth@FmtName*{\@nameauth@Root{#2,}}%
          \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#2}]%
        \else%
          \csgdef{\@nameauth@CleanName{#2!NF!}}{}%
          \expandafter\@nameauth@FmtName\expandafter*%
            \expandafter{\Surnames}%
          \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#2}]%
        \fi%
      \fi%
    \fi}%
  }%
  \if@nameauth@Punct\expandafter\@nameauth@CheckDot\fi%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\FName} is derived from \cmd{\Name} and uses its logic to print forename(s) in a subsequent use. It obeys the \texttt{nocomma} option and eliminates double periods.
%
% \begin{macro}{\AKA}
% \changes{v0.85}{2012/02/05}{Add comma suppression, ltxdoc compatibility}
% \changes{v0.86}{2012/02/06}{Fixed some regressions}
% \changes{v0.9}{2012/02/10}{Added starred mode; redesigned}
% \changes{v0.94}{2012/02/15}{Added error checking}
% \changes{v1.0}{2012/02/20}{Fixed compatibility issues.}
% \changes{v1.1}{2012/03/08}{Fixed warning reporting.}
% \changes{v1.26}{2012/04/24}{Fixed sorting of name suffixes in index}
%    \begin{macrocode}
\DeclareDocumentCommand\AKA{s o m o m o}%
{%
  \protected@edef\Surnamesi{#3}%
  \protected@edef\Surnamesii{#5}%
  \protected@edef\Shortnamesi{\@nameauth@Root{#3,}}%
  \protected@edef\Shortnamesii{\@nameauth@Root{#5,}}%
  \protected@edef\Suffixi{\@empty}%
  \protected@edef\Suffixii{\@empty}%
  \if@nameauth@DoComma\else%
    \@nameauth@CheckComma{#3}%
    \if@nameauth@Comma%
      \protected@edef\Surnamesi{\@nameauth@Root{#3}\@nameauth@Suffix{#3}}%
      \protected@edef\Suffixi{\@nameauth@Suffix{#3}}%
    \fi%
    \@nameauth@CheckComma{#5}%
    \if@nameauth@Comma%
      \protected@edef\Surnamesii{\@nameauth@Root{#5}\@nameauth@Suffix{#5}}%
      \protected@edef\Suffixii{\@nameauth@Suffix{#5}}%
    \fi%
  \fi%
  \IfValueTF{#4}%
  {\IfValueTF{#6}%
    {\edef\Forenames{#6}}{\edef\Forenames{#4}}%
    \expandafter\@nameauth@FmtName\expandafter*\expandafter{%
      \expandafter\Forenames\expandafter\space\Surnamesii}%
    \ifcsname\@nameauth@CleanName{#4#5!PN!}\endcsname%
      \PackageWarning{nameauth}%
      {macro AKA XRef: #4 #5 exists.}%
    \else%
      \ifcsname\@nameauth@CleanName{#4#5!MN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro AKA Name reference: #4 #5 already exists; no see ref.}%
      \else%
        \ifcsname\@nameauth@CleanName{#4#5!NF!}\endcsname%
          \PackageWarning{nameauth}%
          {macro AKA Name reference: #4 #5 already exists; no see ref.}%
        \else%
          \csgdef{\@nameauth@CleanName{#4#5!PN!}}{}%
          \IfValueTF{#2}%
            {%
              \ifx\Suffixi\@empty%
                \ifx\Suffixii\@empty%
                  \@nameauth@Index{\Surnamesii, #4|see{\Surnamesi, #2}}%
                \else%
                  \@nameauth@Index{\Shortnamesii, #4, \Suffixii|see{\Surnamesi, #2}}%
                \fi%
              \else%
                \ifx\Suffixii\@empty%
                  \@nameauth@Index{\Surnamesii, #4|see{\Shortnamesi, #2, \Suffixi}}%
                \else%
                  \@nameauth@Index{\Shortnamesii, #4, \Suffixii|see{\Shortnamesi, #2, \Suffixi}}%
                \fi%
              \fi%
            }%
            {%
              \ifx\Suffixii\@empty \@nameauth@Index{\Surnamesii, #4|see{\Surnamesi}}%
              \else\@nameauth@Index{\Shortnamesii, #4, \Suffixii|see{\Surnamesi}}\fi%
            }%
        \fi%
      \fi%
    \fi}%
  {\IfValueTF{#6}%
    {\IfBooleanTF{#1}%
      {\@nameauth@FmtName*{#6}}%
      {\expandafter\@nameauth@FmtName\expandafter*%
        \expandafter{\Surnamesii\space#6}}%
    \ifcsname\@nameauth@CleanName{#5#6!PN!}\endcsname%
      \PackageWarning{nameauth}%
      {macro AKA XRef: #5 #6 exists.}%
    \else%
      \ifcsname\@nameauth@CleanName{#5#6!MN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro AKA Name reference: #5 #6 already exists; no see ref.}%
      \else%
        \ifcsname\@nameauth@CleanName{#5#6!NF!}\endcsname%
          \PackageWarning{nameauth}%
          {macro AKA Name reference: #5 #6 already exists; no see ref.}%
        \else%
          \csgdef{\@nameauth@CleanName{#5#6!PN!}}{}%
          \IfValueTF{#2}%
            {%
              \ifx\Suffixi\@empty \@nameauth@Index{\Surnamesii\space#6|see{\Surnamesi, #2}}%
              \else\@nameauth@Index{\Surnamesii\space#6|see{\Shortnamesi, #2, \Suffixi}}\fi%
            }%
            {\@nameauth@Index{\Surnamesii\space#6|see{\Surnamesi}}}%
        \fi%
      \fi%
    \fi}%
    {\expandafter\@nameauth@FmtName\expandafter*\expandafter{\Surnamesii}%
    \ifcsname\@nameauth@CleanName{#5!PN!}\endcsname%
      \PackageWarning{nameauth}%
      {macro AKA XRef: #5 exists.}%
    \else%
      \ifcsname\@nameauth@CleanName{#5!MN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro AKA Name reference: #5 already exists; no see ref.}%
      \else%
        \ifcsname\@nameauth@CleanName{#5!NF!}\endcsname%
          \PackageWarning{nameauth}%
          {macro AKA Name reference: #5 already exists; no see ref.}%
        \else%
          \csgdef{\@nameauth@CleanName{#5!PN!}}{}%
          \IfValueTF{#2}%
            {%
              \ifx\Suffixi\@empty \@nameauth@Index{\Surnamesii|see{\Surnamesi, #2}}%
              \else\@nameauth@Index{\Surnamesii|see{\Shortnamesi, #2, \Suffixi}}\fi%
            }%
            {\@nameauth@Index{\Surnamesii|see{\Surnamesi}}}%
        \fi%
      \fi%
    \fi}%
  }%
  \if@nameauth@Punct\expandafter\@nameauth@CheckDot\fi%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\AKA} prints a pseudonym and creates index cross-references. Its starred form prints only the alternate name parameter, if that exists. It prevents multiple generation of cross-references and suppresses double periods.
%
% \begin{macro}{\PName}
% \changes{v0.85}{2012/02/05}{Add comma suppression}
%    \begin{macrocode}
\DeclareDocumentCommand\PName{s o m o m o}%
{%
  \IfBooleanTF{#1}{\Name*[#2]{#3}}{\Name[#2]{#3}}%
  {\space}(\AKA[#2]{#3}[#4]{#5}[#6])%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\PName} is a convenience macro whose starred and unstarred forms call the respective versions of \cmd{\Name}, followed only by \cmd{\AKA}.
%
% \begin{macro}{\TagName}
% \changes{v1.2}{2012/02/25}{Added macro.}
%    \begin{macrocode}
\DeclareDocumentCommand\TagName{o m o m}%
{%
  \IfValueTF{#1}%
    {\ifcsname\@nameauth@CleanName{#1#2!PN!}\endcsname%
      \PackageWarning{nameauth}%
      {macro TagName Cannot tag xref: #1 #2.}%
    \else%
      \csgdef{\@nameauth@CleanName{#1#2}}{#4}%
    \fi}%
    {\IfValueTF{#3}
      {\ifcsname\@nameauth@CleanName{#2#3!PN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro TagName Cannot tag xref: #2 #3.}%
      \else%
        \csgdef{\@nameauth@CleanName{#2#3}}{#4}%
      \fi}%
      {\ifcsname\@nameauth@CleanName{#2!PN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro TagName Cannot tag xref: #2.}%
      \else%
        \csgdef{\@nameauth@CleanName{#2}}{#4}%
      \fi}%
    }%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\TagName} creates an index entry tag after a name that is not already a pseudonym.
%
% \begin{macro}{\UntagName}
% \changes{v1.2}{2012/02/25}{Added macro.}
%    \begin{macrocode}
\DeclareDocumentCommand\UntagName{o m o}%
{%
  \IfValueTF{#1}%
    {\csundef{\@nameauth@CleanName{#1#2}}}%
    {\IfValueTF{#3}
      {\csundef{\@nameauth@CleanName{#2#3}}}%
      {\csundef{\@nameauth@CleanName{#2}}}%
    }%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\TagName} creates an index entry tag after a name that is not already a pseudonym.
%
% \begin{macro}{\IndexName}
% \changes{v0.75}{2012/01/19}{Optional parameter added; mandatory parameter deleted}
% \changes{v0.85}{2012/02/05}{Add comma suppression, ltxdoc compatibility}
% \changes{v0.86}{2012/02/06}{Slight tweak using \cmd{\edef}}
% \changes{v0.9}{2012/02/10}{redesigned macro}
% \changes{v1.0}{2012/02/20}{Fixed compatibility issues.}
% \changes{v1.2}{2012/02/25}{Added warnings.}
% \changes{v1.26}{2012/04/24}{Fixed sorting of name suffixes in index}
%    \begin{macrocode}
\DeclareDocumentCommand\IndexName{o m o}%
{%
  \protected@edef\Surnames{#2}%
  \protected@edef\Short{\@nameauth@Root{#2,}}%
  \protected@edef\Suffix{\@empty}%
  \if@nameauth@DoComma\else%
    \@nameauth@CheckComma{#2}%
    \if@nameauth@Comma%
      \protected@edef\Surnames{\@nameauth@Root{#2}\@nameauth@Suffix{#2}}%
      \protected@edef\Suffix{\@nameauth@Suffix{#2}}%
    \fi%
  \fi%
  \IfValueTF{#1}%
    {\ifcsname\@nameauth@CleanName{#1#2!PN!}\endcsname%
      \PackageWarning{nameauth}%
      {macro IndexName XRef: #1 #2 exists.}%
    \else%
        \ifx\Suffix\@empty \@nameauth@Index{\Surnames, #1}[\@nameauth@CleanName{#1#2}]%
        \else \@nameauth@Index{\Short, #1, \Suffix}[\@nameauth@CleanName{#1#2}]\fi%
    \fi}%
    {\IfValueTF{#3}
      {\ifcsname\@nameauth@CleanName{#2#3!PN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro IndexName XRef: #2 #3 exists.}%
      \else%
        \@nameauth@Index{\Surnames\space#3}[\@nameauth@CleanName{#2#3}]%
      \fi}%
      {\ifcsname\@nameauth@CleanName{#2!PN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro IndexName XRef: #2 exists.}%
      \else%
        \@nameauth@Index{\Surnames}[\@nameauth@CleanName{#2}]%
      \fi}%
    }%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\IndexName} creates an index entry that is not already a pseudonym. It prints nothing. It does ensure consistent formatting.
%
% \begin{macro}{\ExcludeName}
% \changes{v0.94}{2012/02/15}{Added macro}
%    \begin{macrocode}
\DeclareDocumentCommand\ExcludeName{o m o}%
{%
  \IfValueTF{#1}%
  {%
    \ifcsname\@nameauth@CleanName{#1#2!PN!}\endcsname%
      \PackageWarning{nameauth}%
      {macro ExcludeName XRef: #1 #2 exists.}%
    \else%
      \ifcsname\@nameauth@CleanName{#1#2!MN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro ExcludeName Reference: #1 #2 already exists; no exclusion.}%
      \else%
        \ifcsname\@nameauth@CleanName{#1#2!NF!}\endcsname%
          \PackageWarning{nameauth}%
          {macro ExcludeName Reference: #1 #2 already exists; no exclusion.}%
        \else%
          \csgdef{\@nameauth@CleanName{#1#2!PN!}}{}%
        \fi%
      \fi%
    \fi}%
  {\IfValueTF{#3}%
    {\ifcsname\@nameauth@CleanName{#2#3!PN!}\endcsname\relax%
    \else%
      \ifcsname\@nameauth@CleanName{#2#3!MN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro ExcludeName Reference: #2 #3 already exists; no exclusion.}%
      \else%
        \ifcsname\@nameauth@CleanName{#2#3!NF!}\endcsname%
          \PackageWarning{nameauth}%
          {macro ExcludeName Reference: #2 #3 already exists; no exclusion.}%
        \else%
          \csgdef{\@nameauth@CleanName{#2#3!PN!}}{}%
        \fi%
      \fi%
    \fi}%
    {\ifcsname\@nameauth@CleanName{#2!PN!}\endcsname\relax%
    \else%
      \ifcsname\@nameauth@CleanName{#2!MN!}\endcsname%
        \PackageWarning{nameauth}%
        {macro ExcludeName Reference: #2 already exists; no exclusion.}%
      \else%
        \ifcsname\@nameauth@CleanName{#2!NF!}\endcsname%
          \PackageWarning{nameauth}%
          {macro ExcludeName Reference: #2 already exists; no exclusion.}%
        \else%
          \csgdef{\@nameauth@CleanName{#2!PN!}}{}%
        \fi%
      \fi%
    \fi}%
  }%
}
%    \end{macrocode}
% \end{macro}
% This macro prevents a name from being formatted or indexed by using the exclusion mechanism of \cmd{\AKA}. The result is that \cmd{\Name} and friends will print their arguments, emit a warning, and continue.
%
% \begin{macro}{\ForgetName}
% \changes{v0.75}{2012/01/19}{New parameter added}
%    \begin{macrocode}
\DeclareDocumentCommand\ForgetName{o m o}%
{%
  \IfValueTF{#1}%
    {\csundef{\@nameauth@CleanName{#1#2!MN!}}%
    \csundef{\@nameauth@CleanName{#1#2!NF!}}}%
    {\IfValueTF{#3}%
      {\csundef{\@nameauth@CleanName{#2#3!MN!}}%
      \csundef{\@nameauth@CleanName{#2#3!NF!}}}%
      {\csundef{\@nameauth@CleanName{#2!MN!}}%
      \csundef{\@nameauth@CleanName{#2!NF!}}}%
    }%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\ForgetName} undefines control sequences to force the ``first use'' option of \cmd{\Name}.
%
% \begin{macro}{\SubvertName}
% \changes{v0.9}{2012/02/10}{Added macro}
%    \begin{macrocode}
\DeclareDocumentCommand\SubvertName{o m o}%
{%
  \IfValueTF{#1}%
    {\csgdef{\@nameauth@CleanName{#1#2!MN!}}%
    \csgdef{\@nameauth@CleanName{#1#2!NF!}}}%
    {\IfValueTF{#3}%
      {\csgdef{\@nameauth@CleanName{#2#3!MN!}}%
      \csgdef{\@nameauth@CleanName{#2#3!NF!}}}%
      {\csgdef{\@nameauth@CleanName{#2!MN!}}%
      \csgdef{\@nameauth@CleanName{#2!NF!}}}%
    }%
}
%    \end{macrocode}
% \end{macro}
% \cmd{\SubvertName} defines control sequences to suppress the ``first use'' of \cmd{\Name}.\bigskip\hrule\bigskip
%
% \noindent The following macros toggle formatting and indexing.
%
% \begin{macro}{\NamesInactive}
%    \begin{macrocode}
\newcommand{\NamesInactive}{\@nameauth@DoFormatfalse}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\NamesActive}
%    \begin{macrocode}
\newcommand{\NamesActive}{\@nameauth@DoFormattrue}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\IndexInactive}
% \changes{v0.94}{2012/02/15}{Added macro}
%    \begin{macrocode}
\newcommand{\IndexInactive}{\@nameauth@DoIndexfalse}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\IndexActive}
% \changes{v0.94}{2012/02/15}{Added macro}
%    \begin{macrocode}
\newcommand{\IndexActive}{\@nameauth@DoIndextrue}
%    \end{macrocode}
% \end{macro}
% \clearpage
% \Finale
\endinput
% \iffalse
%</package>
% \fi
