%%
%% This is file `ltxnew.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ltxnew.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% ltxnew : provides the \new \renew and \provide prefixes for checking definitions.
%% 
%% 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
%% 
%% This work consists of the main source file ltxnew.dtx
%% and the derived files
%%    ltxnew.sty, ltxnew.pdf, ltxnew.ins,
%% 
%% ltxnew : provides the \new \renew and \provide prefixes for checking definitions
%% Copyright (C) 2009-2010 by Florent Chervet <florent.chervet@free.fr>
%% 

\NeedsTeXFormat{LaTeX2e}% LaTeX 2.09 can't be used (nor non-LaTeX)
   [2005/12/01]% LaTeX must be 2005/12/01 or younger (see kvsetkeys.dtx).
\ProvidesPackage{ltxnew}
   [2010/04/17 v1.2 provides the new and renew prefixes for checking definitions]

\RequirePackage{etex}

% \ltxn@expandonce is the copy of \expandonce from etoolbox.sty
\def\ltxn@expandonce#1{\unexpanded\expandafter{#1}}

% This is the entry point of the prefixes scanner:
% The whole job is done by \futurelet
\def\ltxn@prefix{\begingroup
   \newif\ifglobal
   \let\ltxn@prfx\@empty
   \let\ltxn@rubbish\relax
   \futurelet\x\ltxn@@prefix}
% Here is the test macro: testing each prefix token one after another:
% It consists in a long list of \ifx
\def\ltxn@@prefix{%
   \let\ltxn@next@addto\ltxn@next@prefix
   \ifx\x\@sptoken         \let\next\ltxn@space@prefix%%1
   \else                   \let\next\ltxn@addto@prfx
      \ifx\x\long          \def\z{\long}%%2
      \else\ifx\x\protected\def\z{\protected}%%3
      \else\ifx\x\global   \let\z\@empty\globaltrue%%4
      \else\ifx\x\outer    \def\z{\outer}%%5
      \else
         \ifx\x\expandafter \def\z{\expandafter}%%6
         \else\ifx\x\noexpand    \def\z{\noexpand}%%7
         \else\ifx\x\relax       \def\z{\relax}%%8
         \else
                  \def\ltxn@next@addto{\expandafter\ltxn@def\noexpand}%
            \ifx\x\let              \def\z{\let}%%9
                                    \let\ltxn@cancel\ltxn@cancel@let
            \else                   \let\ltxn@cancel\ltxn@cancel@def
               \ifx\x\def           \edef\z{\ifglobal\global\fi\def}%%10
               \else\ifx\x\edef     \edef\z{\ifglobal\global\fi\edef}%%11
               \else\ifx\x\gdef     \def\z{\gdef}%%12
               \else\ifx\x\xdef     \def\z{\xdef}%%13
               \else                \let\ltxn@cancel\ltxn@cancel@new
                  \ifx\x\count       \def\z{\newcount}%%14
                  \else\ifx\x\countdef%%15
                     \ifglobal\def\z{\globcount}\else\def\z{\loccount}\fi
                  \else\ifx\x\loccount%%16
                     \ifglobal\def\z{\globcount}\else\def\z{\loccount}\fi
                  \else\ifx\x\globcount   \def\z{\globcount}%%17
                  \else\ifx\x\dimen       \def\z{\newdimen}%%18
                  \else\ifx\x\dimendef%%19
                     \ifglobal\def\z{\globdimen}\else\def\z{\locdimen}\fi
                  \else\ifx\x\locdimen%%20
                     \ifglobal\def\z{\globdimen}\else\def\z{\locdimen}\fi
                  \else\ifx\x\globdimen   \def\z{\globdimen}%%21
                  \else\ifx\x\skip        \def\z{\newskip}%%22
                  \else\ifx\x\skipdef%%23
                     \ifglobal\def\z{\globskip}\else\def\z{\locskip}\fi
                  \else\ifx\x\locskip%%24
                     \ifglobal\def\z{\globskip}\else\def\z{\locskip}\fi
                  \else\ifx\x\globskip    \def\z{\globskip}%%25
                  \else\ifx\x\muskip      \def\z{\newmuskip}%%26
                  \else\ifx\x\muskipdef%%27
                     \ifglobal\def\z{\globmuskip}\else\def\z{\locmuskip}\fi
                  \else\ifx\x\locmuskip%%28
                     \ifglobal\def\z{\globmuskip}\else\def\z{\locmuskip}\fi
                  \else\ifx\x\globmuskip  \def\z{\globmuskip}%%29
                  \else\ifx\x\savebox     \def\z{\newsavebox}%%30
                  \else\ifx\x\box%%31
                     \ifglobal\def\z{\globbox}\else\def\z{\locbox}\fi
                  \else\ifx\x\locbox%%§32
                     \ifglobal\def\z{\globbox}\else\def\z{\locbox}\fi
                  \else\ifx\x\globbox     \def\z{\globbox}%%33
                  \else\ifx\x\toksdef%%34
                     \ifglobal\def\z{\globtoks}\else\def\z{\loctoks}\fi
                  \else\ifx\x\toks        \def\z{\newtoks}%%35
                  \else\ifx\x\loctoks%%36
                     \ifglobal\def\z{\globtoks}\else\def\z{\loctoks}\fi
                  \else\ifx\x\globtoks    \def\z{\globtoks}%%37
                  \else\ifx\x\locmarks%%38
                     \ifglobal\def\z{\globmarks}\else\def\z{\locmarks}\fi
                  \else\ifx\x\marks       \def\z{\newmarks}%%39   %\newmarks=\globmarks
                  \else\ifx\x\globmarks   \def\z{\globmarks}%%40
                  \else\ifx\x\font        \def\z{\font}%%41
                  \else\ifx\x\write       \def\z{\newwrite}%%42
                  \else\ifx\x\read        \def\z{\newread}%%43
                  \else\ifx\x\protect     \ltxn@error@prefix%%44
                  \else
                     \let\ltxn@next@addto\ltxn@next@prefix
                     \ifx\y\x\ltxn@error@prefix
                     \else\let\y\x
                     \fi
                     \let\next\ltxn@expand@prefix
                  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
                  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
                  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
               \fi\fi\fi\fi
            \fi
         \fi\fi\fi
      \fi\fi\fi\fi% so many fees...
   \fi\next}
\def\ltxn@next@prefix{\futurelet\x\ltxn@@prefix}
\def\ltxn@expand@prefix{%
   \expandafter\futurelet\expandafter\x\expandafter\ltxn@@prefix}
\def\ltxn@addto@prfx#1{\let\y\@undefined
   \expandafter\expandafter\expandafter\def
      \expandafter\expandafter\expandafter\ltxn@prfx
         \expandafter\expandafter\expandafter{\expandafter\ltxn@prfx\z}%
   \ltxn@next@addto}
\expandafter\def\expandafter\ltxn@space@prefix\space{\ltxn@next@prefix}
\def\ltxn@error@prefix{\@latex@error{A \string\def\space
   (or \string\countdef\space or\string\toksdef\space etc.)\MessageBreak
   was expected after \string\new\MessageBreak
   I found a \meaning\x!\MessageBreak
   see ltxnew documentation for more information}\@ehd}

% These are the macros used in case we have to cancel definition (nonstopmode)
% #1 is always the control sequence not to redefine
\def\ltxn@cancel@let{\afterassignment\endgroup\let\ltxn@rubbish}
\def\ltxn@cancel@def{\afterassignment\endgroup\def\ltxn@rubbish}
\def\ltxn@cancel@new{\endgroup}

% new: Do define or cancel, depending on the result of \@ifdefinable
\def\ltxn@new#1{%
   \let\next\ltxn@cancel
   \ifdefined#1\unless\ifx#1\relax\def#1{new:error}\fi\fi
   \expandafter\@ifdefinable\noexpand#1{%
      \expandafter\let\noexpand#1=\relax
      \edef\next{\endgroup\ltxn@expandonce\ltxn@prfx#1}}%
   \next}


% renew: Throws an error in case the control sequence is unknown or \relax
\def\ltxn@renew#1{%
   \edef\ltxn@name{\string#1}%
   \ifdefined#1\ifx#1\relax\ltxn@error{renew: \ltxn@name undefined}\fi
   \else       \ltxn@error{renew: \ltxn@name undefined}%
   \fi
   \let#1=\relax
   \def\next{\ltxn@new#1}%
   \next}

% provide: Never throw an error but conditionally defines the control sequence
\def\ltxn@provide#1{%
   \let\next\ltxn@cancel
   \edef\ltxn@name{\string#1}%
   \ifdefined#1\ifx#1\relax \ltxn@provide@new\fi
   \else \ltxn@provide@new
   \fi
   \next}
\def\ltxn@provide@new{%
   \edef\next{\noexpand\ltxn@new\csname\expandafter\@gobble\ltxn@name\endcsname}}

% \new: the entry point:
%       just let the definition macro to be \ltxn@new and start scanning prefixes.
\protected\def\new{\let\ltxn@def\ltxn@new\ltxn@prefix}

% \renew: the entry point:
%         just let the definition macro to be \ltxn@renew and start scanning prefixes.
\protected\def\renew{\let\ltxn@def\ltxn@renew\ltxn@prefix}

% \provide: the entry point:
%           just let the definition macro to be |\ltxn@provide| and start scanning prefixes.
\protected\def\provide{\let\ltxn@def\ltxn@provide\ltxn@prefix}

% In case of redefinition, throws an |\ehc|-type error:
\def\ltxn@error#1{\@latex@error{#1}\@ehc}
\endinput
%%
%% End of file `ltxnew.sty'.
