summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/misc/redefine.tex
blob: 9b24b024e7943452c1b1a1074dfdca6de20e55ad (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
% -*- Mode: TeX -*-

\ifx\thisfileis\anUndefinedMacro\input maybeload \fi

\thisfileis{<eb.tex.texlocal>redefine} % abort loading if we're already loaded

% The LaTex macros in this file provide redefinition warnings.
% Also, the LaTex \newcommand facility is changed so that using
% \newcommand to redefine a function produces only a warning
% message, not an error.

% A control sequence equivalent to \relax is considered
% undefined, as in LaTex.

% However, allocation commands such as \newtoks are changed so
% that no redefinition takes place if their arguments are already
% defined.

\makeatletter

\edef\@backslash{\expandafter\@car\string\relax\@nil}

\def\@warnredef#1{\typeout{WARNING: The `#1' control sequence is being redefined.}}

\def\@warnnoredef#1{\typeout{WARNING: Aborting redefinition of the `#1' control sequence.}}

\def\@ifcsundefined#1#2#3{\ifx #1\anUndefinedMacro
   \def\@@temp{#2}\else\ifx #1\relax\def\@@temp{#2}\else
   \def\@@temp{#3}\fi\fi\@@temp}

% Change LaTex behavior.

\def\@notdefinable{\@warnredef{\@backslash\@tempa}}

% Define \redefcheck{\ctlseq} that just checks the sequence
% and ignores it.

\def\redefcheck#1{\@ifcsundefined#1{}{\@warnredef{\string#1}}}

% \redefabort{\oneargdefiner}{\ctlseq} puts out \oneargdefiner\ctlseq,
% except that if \ctlseq is already defined, it just gobbles both
% of them.

\def\redefabort#1#2{\@ifcsundefined#2{#1#2}{\@warnnoredef{\string#2}}}

% Define \newdef = \def with \redefcheck, and similarly for \gdef and \let.

\def\newdef#1{\redefcheck{#1}\def#1}
\def\newgdef#1{\redefcheck{#1}\gdef#1}
\def\newlet#1{\redefcheck{#1}\let#1}

% Add redefinition checking to \newif.
% \newif is declared as \outer, so we need to delay the definition
% of \latexnewif until we've scanned the definition of the new
% \newif.

\let\@tempa\newif
\def\newif#1{\redefcheck{#1}\latexnewif#1}
\let\latexnewif\@tempa

% Now for the allocation commands, which I'm setting up to skip the
% redefinition if their target control sequences are already defined.
% These are also declared \outer, but the above \@tempa trick won't work
% here; it's necessary to use another level of macros.

\def\latexnewbox{\latexouternewbox}
\let\latexouternewbox\newbox
\def\newbox#1{\redefabort\latexnewbox{#1}}

\def\latexnewcount{\latexouternewcount}
\let\latexouternewcount\newcount
\def\newcount#1{\redefabort\latexnewcount{#1}} 

\def\latexnewdimen{\latexouternewdimen}
\let\latexouternewdimen\newdimen
\def\newdimen#1{\redefabort\latexnewdimen{#1}} 

\def\latexnewtoks{\latexouternewtoks}
\let\latexouternewtoks\newtoks
\def\newtoks#1{\redefabort\latexnewtoks{#1}} 

\makeatother