summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/xifthen/xifthen.sty
blob: 247546fabd8558719d592672dfa346cfc44e53e8 (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
\def \filedate    {2015/11/05}%
\def \fileversion {v1.4.0}%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xifthen}%
  [\filedate \space \fileversion \space Extended ifthen features]

% v1.4 Removed the etex package for compatibility reasons

\RequirePackage{calc}
\RequirePackage{ifthen}
\RequirePackage{ifmtarg}

% First of all, \TE@repl (ifthen) needs to be patched. (v1.2)
%   (viz. \newtest{\superlogique}[1]{\(\NOT#1\AND\boolean{true}\)})
%   Pointed out by MPG and Pierre Albar\`ede [19 Mar 2009]

\def \TE@repl #1#2{%
  \long \def \@tempc ##1#1##2{%
    \def \@tempb{\@tempc}%
    \begingroup % Thanks MPG
      \toks@ {##2}%
      \edef \@tempa {\the \toks@}% <- UF v1.3
    \expandafter \endgroup
    \ifx \@tempa \@tempb
      \toks@ \expandafter {\the \toks@ ##1}%
      \expandafter \@gobble
    \else
      \toks@ \expandafter {\the \toks@ ##1#2}%
      \expandafter \@tempc
    \fi
    ##2%
  }%
  \toks@ \expandafter {\expandafter}%
  \expandafter \@tempc \the \toks@ #1\@tempc
}

% \cnttest {<counter expression>} {<relation>} {<counter expression>}
%
\newcommand*{\TE@cnttest}[4]{%
  \TE@throw
  \noexpand \calc@assign@count{\@tempcnta}{\unexpanded{#1}}%
  \noexpand \calc@assign@count{\@tempcntb}{\unexpanded{#3}}%
  \noexpand \if \noexpand \TE@cnttest@ {#2}%
  #4%
}

\newcommand*{\TE@cnttest@}[1]{%
  \ifcsname TE@cnttest@@#1\endcsname
    \csname TE@cnttest@@#1\expandafter\expandafter\expandafter \endcsname
    \expandafter \@gobble
  \else
    \expandafter \@firstofone
  \fi
  {FF\PackageError{xifthen}{Not a valid comparison operator "#1"}%
                         {Valid comparisons are <, =, >, <=, and =>.}}%
}

\@namedef{TE@cnttest@@<}{\ifnum \@tempcnta<\@tempcntb AA\else AB\fi}
\@namedef{TE@cnttest@@>}{\ifnum \@tempcnta>\@tempcntb AA\else AB\fi}
\@namedef{TE@cnttest@@=}{\ifnum \@tempcnta=\@tempcntb AA\else AB\fi}
\@namedef{TE@cnttest@@<=}{%
  \ifnum \@tempcnta<\@tempcntb AA\else
    \ifnum \@tempcnta=\@tempcntb AA\else AB\fi
  \fi
}
\@namedef{TE@cnttest@@>=}{%
  \ifnum \@tempcnta>\@tempcntb AA\else
    \ifnum \@tempcnta=\@tempcntb AA\else AB\fi
  \fi
}

% \dimtest {<dimension expression>} {<relation>} {<dimension expression>}
%
\newcommand*{\TE@dimtest}[4]{%
  \TE@throw
  \noexpand \calc@assign@skip{\@tempskipa}{\unexpanded{#1}}%
  \noexpand \calc@assign@skip{\@tempskipb}{\unexpanded{#3}}%
  \noexpand \if \noexpand \TE@dimtest@ {#2}%
  #4%
}

\newcommand*{\TE@dimtest@}[1]{%
  \ifcsname TE@dimtest@@#1\endcsname
    \csname TE@dimtest@@#1\expandafter\expandafter\expandafter \endcsname
    \expandafter \@gobble
  \else
    \expandafter \@firstofone
  \fi
  {FF\PackageError{xifthen}{Not a valid comparison operator "#1"}%
                         {Valid comparisons are <, =, >, <=, and =>.}}%
}

\@namedef{TE@dimtest@@<}{\ifdim \@tempskipa<\@tempskipb AA\else AB\fi}
\@namedef{TE@dimtest@@>}{\ifdim \@tempskipa>\@tempskipb AA\else AB\fi}
\@namedef{TE@dimtest@@=}{\ifdim \@tempskipa=\@tempskipb AA\else AB\fi}
\@namedef{TE@dimtest@@<=}{%
  \ifdim \@tempskipa<\@tempskipb AA\else
    \ifdim \@tempskipa=\@tempskipb AA\else AB\fi
  \fi
}
\@namedef{TE@dimtest@@>=}{%
  \ifdim \@tempskipa>\@tempskipb AA\else
    \ifdim \@tempskipa=\@tempskipb AA\else AB\fi
  \fi
}

% \isnamedefined {<command name>}
%
\newcommand*{\TE@isnamedefined}[2]{%
  \TE@throw
  \noexpand \ifcsname #1\endcsname
  #2%
}

% \isempty {<content>}
%
\newcommand*{\TE@isempty}[2]{%
  \TE@throw
  \noexpand \if FF\noexpand \@nameuse{fi}%
  \noexpand \@ifmtarg{\unexpanded{#1}}{%
    \noexpand \@nameuse{iftrue}%
  }{%
    \noexpand \@nameuse{iffalse}%
  }%
  #2%
}

% \isequivalentto {<command>} {<command>}
%
\newcommand*{\TE@isequivalentto}[3]{%
  \TE@throw
  \noexpand \ifx \noexpand #1\noexpand#2%
  #3%
}

% \isin {<substring>} {<string>}
%
\newcommand*{\TE@isin}[3]{%
  \TE@throw
  \unexpanded {\in@{#1}{#2}}%
  \noexpand \ifin@
  #3%
}

% \endswith {<string>} {<substring>}
%
\newcommand*{\TE@endswith}[3]{%
  \TE@throw
  \unexpanded {\in@{#2\@nil}{#1\@nil}}%
  \noexpand \ifin@
  #3%
}

% \newtest <command> [<number>] {<definition>}
%
\newcommand*{\newtest}[1]{%
  \@ifnextchar[{%
    \@newtest{#1}%
  }{%
    \@newtest{#1}[0]%
  }%
}%

\newcommand*{\@newtest}{}
\def \@newtest #1[#2]#3{%
  \toks@ = {\(#3\)}%
  \TE@repl \or  \TE@or
  \TE@repl \and \TE@and
  \TE@repl \not \TE@neg
  \TE@repl \OR  \TE@or
  \TE@repl \AND \TE@and
  \TE@repl \NOT \TE@neg
  \edef \@tempa {%
    \unexpanded{\newcommand*{#1}[{#2}]}{\the \toks@}%
  }%
  \@tempa
}%

\newcommand*{\TE@hook}{%
  \let \isequivalentto = \TE@isequivalentto
  \let \terminateswith = \TE@endswith % For compability reasons (deprecated)
  \let \endswith       = \TE@endswith
  \let \isnamedefined  = \TE@isnamedefined
  \let \isempty        = \TE@isempty
  \let \cnttest        = \TE@cnttest
  \let \dimtest        = \TE@dimtest
  \let \isin           = \TE@isin
}

\renewcommand{\ifthenelse}[1]{%
  \toks@{#1}%
  \TE@repl \or  \TE@or
  \TE@repl \and \TE@and
  \TE@repl \not \TE@neg
  \TE@repl \OR  \TE@or
  \TE@repl \AND \TE@and
  \TE@repl \NOT \TE@neg
  \begingroup
    \let \protect = \@unexpandable@protect
    \def \@setref ##1##2##3{\ifx ##1\relax \z@ \else \expandafter ##2##1\fi}%
    \def \value ##1{\the \csname c@##1\endcsname}%
    \let \equal = \TE@equal
    \let \( = \TE@lparen
    \let \) = \TE@rparen
    \let \isodd = \TE@odd
    \let \lengthtest = \TE@length
    \let \isundefined = \TE@undef
    \TE@hook
    \begingroup
      \let \@tempa = \relax
      \let \@tempb = \relax
      \xdef \@gtempa {\expandafter \TE@eval \the \toks@ \TE@endeval}%
    \endgroup
    \@gtempa
    \expandafter \endgroup
  \ifTE@val
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}

\endinput