summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ltxnew/ltxnew.sty
blob: f20b86126a6abe09fa5a03f619d44dd67631bf88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
%%
%% 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}
   [2011/03/02 v1.3 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\char        \def\z{\chardef}%%44
                  \else\ifx\x\chardef     \def\z{\chardef}%%45
                  \else\ifx\x\mathchar    \def\z{\mathchardef}%%46
                  \else\ifx\x\mathchardef \def\z{\mathchardef}%%47
                  \else\ifx\x\protect     \ltxn@error@prefix%%48
                  \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
      \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\space undefined}\fi
   \else       \ltxn@error{renew: \ltxn@name\space 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'.