% \iffalse meta-comment
%%% File: gaux.sty
%% Copyright (C) 2017 Michael N\"usken.
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3a
% 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.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% -----------------------------------------------------------
% 
%<*chartab>
%\fi
%% \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         \~}
% \iffalse meta-comment
%</chartab>
% \fi
% \iffalse
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{gaux}[2017/04/21 v0.94 %
Global auxiliaries: global sets and lists. MNuesken, Bonn]
% \fi
%
% \CheckSum{0}
%

\long\def\gobble#1{}

\def\@expandonearg#1#2{%
  \edef\reserved@a{\noexpand#1{#2}}\reserved@a}

\def\@expandsecondarg#1#2#3{%
  \toks@{#2}%
  \edef\reserved@a{\noexpand#1{\the\toks@}{#3}}\reserved@a}


%%% \@firstoftwo, \@secondoftwo, \g@addto@macro are defined in
%%% <latex.ltx>.  \@nameuse is also helpful.
%%%
%%% \long\def\@firstoftwo#1#2
%%% \long\def\@secondoftwo#1#2
%%% \long\def\g@addto@macro#1#2
% Global name definition:
\def\@namegdef#1{\expandafter\gdef\csname #1\endcsname}
%
\long\def\g@addto@macro@left#1#2{%
  \begingroup
    \toks@\expandafter{#1}%
    \@temptokena{#2}%
    \xdef#1{\the\@temptokena\the\toks@}%
  \endgroup}
%
\def\g@addto@name@left#1{%
  \expandafter\g@addto@macro@left\csname #1\endcsname%
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Read file once.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\RequireFile}[1]{%
  \@ifundefined{file@#1}{%
    \@namegdef{file@#1}{Loaded}%
    \InputIfFileExists{#1}{}{%
      %%% \PackageError{gaux}{RequireFile: #1 not found.}{}%
      \GenericError{%
        \space\space\space\@spaces\@spaces\@spaces
      }{%
        Error: RequireFile: #1 not found.%
      }{%
        % See the gaux package for documentation.%
      }{}%
    }%
  }{%
    %%% \PackageInfo{gaux}{RequireFile: #1 already loaded.}{}%
    \GenericInfo{%
      \space\space\space\@spaces\@spaces\@spaces
    }{%
      Info: RequireFile: #1 already loaded.%
    }{%
      % See the gaux package for documentation.%
    }{}%
  }%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Auxiliary commands for macros
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% If #1 empty then execute #2 else execute #3.
%%%
%%% Here, empty means that it's at most white space.
%%%
%%% from amsgen.sty:
\long\def\@ifempty#1{\@xifempty#1@@..\@nil}
\long\def\@xifempty#1#2@#3#4#5\@nil{%
  \ifx#3#4\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
\long\def\@ifnotempty#1{\@ifempty{#1}{}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% If #1=#2 then execute #3 else execute #4.
\long\def\@ifequal#1#2{%
  % #1 = arg1
  % #2 = arg2
  % #3 = cmd if arg1=arg2
  % #4 = cmd if arg1<>arg2
  \long\def\@tempa{#1}%
  \long\def\@tempb{#2}%
  \ifx\@tempa\@tempb
  %%% \typeout{ifequal: #1=#2}% DEBUG
  \expandafter\@firstoftwo
  \else
  %%% \typeout{ifequal: #1<>#2}% DEBUG
  \expandafter\@secondoftwo
  \fi
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Auxiliary commands for sets and lists
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Sets are lists of \do{stuff}.
%%%
% Clear list or set.
\def\g@clear#1{%
  \expandafter\global\expandafter\let\csname #1\endcsname\relax\relax
}
% Initialize list.
\def\g@setdef@do#1#2{%
  % #1 = listname or setname
  % #2 = stuff
  \expandafter\gdef\csname #1\endcsname{\do{#2}}%
}
% Start or extend set #1 by #2.
\def\g@setadd@do#1#2{%
  % #1 = setname
  % #2 = stuff
  \@ifundefined{#1}{%
    \expandafter\gdef\csname #1\endcsname{\do{#2}}%
  }{{%
    \def\do##1{\@ifequal{#2}{##1}{\@tempswatrue}{}}%
    \@tempswafalse
    \csname #1\endcsname
    %%% \let\do\undefined
    \if@tempswa\else
    \expandafter\g@addto@macro\csname #1\endcsname{\do{#2}}%
    \fi
  }}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Lists are lists of stuff.
%%%
%%% You can use item=\do{stuff} but this is not automatic
%%% to allow for other formats.
%%%
%%% Each lists is registered in g@setoflists.
%%% So \showalllists can display all of them.
%%%
% Initialize list.
\def\g@listdef#1{%
  % #1 = listname or setname
  % #2 = stuff
  \g@setadd@do{g@setoflists}{#1}%
  \expandafter\gdef\csname #1\endcsname
}
% Start or extend list #1 by #2.
\def\g@listadd#1#2{%
  % #1 = listname
  % #2 = stuff
  \g@setadd@do{g@setoflists}{#1}% Register each list for debugging
  \@ifundefined{#1}{%
    \expandafter\gdef\csname #1\endcsname{#2}%
  }{%
    \expandafter\g@addto@macro\csname #1\endcsname{#2}%
  }%
}
% Start or extend list #1 by #2.
\def\g@listadd@left#1#2{%
  % #1 = listname
  % #2 = stuff
  \g@setadd@do{g@setoflists}{#1}% Register each list for debugging
  \@ifundefined{#1}{%
    \expandafter\gdef\csname #1\endcsname{#2}%
  }{%
    \expandafter\g@addto@macro@left\csname #1\endcsname{#2}%
  }%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% For debugging: show a list or set or all lists.
%%%
\def\showlist#1{%
  \@ifundefined{#1}{
    \typeout{#1 undefined^^J}%
  }{%
    \typeout{#1=%
      \expandafter\expandafter%
      \expandafter\strip@prefix%
      \expandafter\meaning%
      \csname #1\endcsname%
      ^^J}}%
}
\let\showset\showlist
\def\showalllists{%
  \let\do\showlist
  \do{g@setoflists}%
  \csname g@setoflists\endcsname
}
\def\printalllists#1{%
  \immediate\openout\@inputcheck#1 %
  \def\do##1{\immediate\write\@inputcheck{##1=%
      \expandafter\expandafter%
      \expandafter\strip@prefix%
      \expandafter\meaning%
      \csname ##1\endcsname%
      ^^J}}%
  \do{g@setoflists}%
  \csname g@setoflists\endcsname
  \immediate\closeout\@inputcheck
}
\endinput