1 % \iffalse meta-comment
4 % The LaTeX3 Project and any individual authors listed elsewhere
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % http://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2005/12/01 or later.
18 % This file has the LPPL maintenance status "maintained".
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
31 %%% From File: ltcntrl.dtx
34 \ProvidesFile{ltcntrl.dtx}
35 [2014/04/21 v1.0h LaTeX Kernel (program control)]
37 \documentclass{ltxdoc}
38 \GetFileInfo{ltcntrl.dtx}
50 \MaintainedByLaTeXTeam{latex}
58 % \changes{v1.0a}{1994/05/16}{(ASAJ) Split from ltinit.dtx.}
59 % \changes{v1.0b}{1994/11/17}
60 % {\cs{@tempa} to \cs{reserved@a}}
61 % \changes{v1.0c}{1994/11/28}
62 % {Documentation improvements}
64 % \section{Program control structure}
66 % This section defines a number of control structure macros, such as
67 % while-loops and for-loops.
77 % \@whilenum TEST \do {BODY}
78 % \@whiledim TEST \do {BODY} : These implement the loop
79 % while TEST do BODY od
80 % where TEST is a TeX \ifnum or \ifdim test, respectively.
81 % They are optimized for the normal case of TEST initially false.
83 % \@whilesw SWITCH \fi {BODY} : Implements the loop
84 % while SWITCH do BODY od
85 % Optimized for normal case of SWITCH initially false.
87 % \@for NAME := LIST \do {BODY} : Assumes that LIST expands to A1,A2,
89 % Executes BODY n times, with NAME = Ai on the i-th iteration.
90 % Optimized for the normal case of n = 1. Works for n=0.
92 % \@tfor NAME := LIST \do {BODY}
93 % if, before expansion, LIST = T1 ... Tn where each Ti is a
94 % token or {...}, then executes BODY n times, with NAME = Ti
95 % on the i-th iteration. Works for n=0.
97 % NOTES: 1. These macros use no \@temp sequences.
98 % 2. These macros do not work if the body contains anything that
99 % looks syntactically to TeX like an improperly balanced \if
102 % \@whilenum TEST \do {BODY} ==
106 % \@iwhilenum{TEST \relax BODY}
109 % \@iwhilenum {TEST BODY} ==
113 % \@nextwhile = def(\@iwhilenum)
114 % else \@nextwhile = def(\@whilenoop)
116 % \@nextwhile {TEST BODY}
119 % \@whilesw SWITCH \fi {BODY} ==
123 % \@iwhilesw {SWITCH BODY}\fi
127 % \@iwhilesw {SWITCH BODY} \fi ==
131 % \@nextwhile = def(\@iwhilesw)
132 % else \@nextwhile = def(\@whileswnoop)
134 % \@nextwhile {SWITCH BODY} \fi
139 % \begin{macro}{\@whilenoop}
140 % \begin{macro}{\@whilenum}
141 % \begin{macro}{\@iwhilenum}
142 % \changes{v1.0f}{1995/07/09}{Reimplemented using Kabelschacht method}
143 % \changes{v1.0g}{1995/08/16}{Removed \cs{@whilenoop}}
144 % \changes{v1.0g}{1995/08/16}{Made defs long}
146 \long\def\@whilenum#1\do #2{\ifnum #1\relax #2\relax\@iwhilenum{#1\relax
148 \long\def\@iwhilenum#1{\ifnum #1\expandafter\@iwhilenum
149 \else\expandafter\@gobble\fi{#1}}
155 % \begin{macro}{\@whiledim}
156 % \begin{macro}{\@iwhiledim}
157 % \changes{v1.0f}{1995/07/09}{Reimplemented using Kabelschacht method}
158 % \changes{v1.0g}{1995/08/16}{Removed \cs{@whilenoop}}
159 % \changes{v1.0g}{1995/08/16}{Made defs long}
161 \long\def\@whiledim#1\do #2{\ifdim #1\relax#2\@iwhiledim{#1\relax#2}\fi}
162 \long\def\@iwhiledim#1{\ifdim #1\expandafter\@iwhiledim
163 \else\expandafter\@gobble\fi{#1}}
168 % \begin{macro}{\@whileswnoop}
169 % \begin{macro}{\@whilesw}
170 % \begin{macro}{\@iwhilesw}
171 % \changes{v1.0f}{1995/07/09}{Reimplemented using Kabelschacht method}
172 % \changes{v1.0g}{1995/08/16}{Removed \cs{@whileswnoop}}
174 \long\def\@whilesw#1\fi#2{#1#2\@iwhilesw{#1#2}\fi\fi}
175 \long\def\@iwhilesw#1\fi{#1\expandafter\@iwhilesw
176 \else\@gobbletwo\fi{#1}\fi}
182 % \begin{oldcomments}
184 % \@for NAME := LIST \do {BODY} ==
185 % BEGIN \@forloop expand(LIST),\@nil,\@nil \@@ NAME {BODY} END
187 % \@forloop CAR, CARCDR, CDRCDR \@@ NAME {BODY} ==
190 % if def(NAME) = def(\@nnil)
193 % if def(NAME) = def(\@nnil)
195 % \@iforloop CDRCDR \@@ NAME \do {BODY}
200 % \@iforloop CAR, CDR \@@ NAME {BODY} =
202 % if def(NAME) = def(\@nnil)
203 % then \@nextwhile = def(\@fornoop)
205 % \@nextwhile = def(\@iforloop)
207 % \@nextwhile name cdr {body}
209 % \@tfor NAME := LIST \do {BODY}
210 % = \@tforloop LIST \@nil \@@ NAME {BODY}
212 % \@tforloop car cdr \@@ name {body} =
214 % if def(name) = def(\@nnil)
215 % then \@nextwhile == \@fornoop
217 % \@nextwhile == \@forloop
219 % \@nextwhile name cdr {body}
222 % \begin{macro}{\@nnil}
228 % \begin{macro}{\@empty}
234 % \begin{macro}{\@fornoop}
235 % \changes{v1.0g}{1995/08/16}{Made defs long}
236 % \changes{v1.0h}{2007/08/06}{Really make defs long}
238 \long\def\@fornoop#1\@@#2#3{}
242 % \begin{macro}{\@for}
243 % \changes{v1.0d}{1995/04/24}
244 % {Dont expand second argument with \cs{edef}: /1317 (DPC)}
246 \long\def\@for#1:=#2\do#3{%
247 \expandafter\def\expandafter\@fortmp\expandafter{#2}%
248 \ifx\@fortmp\@empty \else
249 \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}\fi}
253 % \begin{macro}{\@forloop}
254 % \changes{v1.0g}{1995/08/16}{Made defs long}
256 \long\def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
257 #5\def#4{#2}\ifx #4\@nnil \else#5\@iforloop #3\@@#4{#5}\fi\fi}
261 % \begin{macro}{\@iforloop}
262 % \changes{v1.0f}{1995/07/09}{Reimplemented using Kabelschacht method}
263 % \changes{v1.0g}{1995/08/16}{Made defs long}
265 \long\def\@iforloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
266 \expandafter\@fornoop \else
267 #4\relax\expandafter\@iforloop\fi#2\@@#3{#4}}
271 % \begin{macro}{\@tfor}
272 % \changes{LaTeX209}{1991/10/17}
273 % {(Rms) \cs{xdef} replaced by \cs{def}
274 % (See FMi's array.doc)}
275 % \changes{v1.0c}{1994/03/13}
276 % {(DPC) Add \cs{@tf@r} so a single group is
277 % correctly treated.}
278 % \changes{v1.0f}{1995/07/09}{Reimplemented using Kabelschacht method}
279 % \changes{v1.0g}{1995/08/16}{Made defs long}
281 \def\@tfor#1:={\@tf@r#1 }
282 \long\def\@tf@r#1#2\do#3{\def\@fortmp{#2}\ifx\@fortmp\space\else
283 \@tforloop#2\@nil\@nil\@@#1{#3}\fi}
284 \long\def\@tforloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
285 \expandafter\@fornoop \else
286 #4\relax\expandafter\@tforloop\fi#2\@@#3{#4}}
290 % \begin{macro}{\@break@tfor}
291 % Break out of a |\@tfor| loop. This should be called \emph{inside}
292 % the scope of an |\if|. See |\@iffileonpath| for an example.
293 % \changes{v1.0l}{1994/05/02}{Macro added (from ltfiles.dtx)}
294 % \changes{v1.0g}{1995/08/16}{Made long}
296 \long\def\@break@tfor#1\@@#2#3{\fi\fi}
300 % \begin{macro}{\@removeelement}
301 % Removes an element from a comma-separated list and puts it into
302 % a control sequence, called as
303 % |\@removeelement{|\meta{element}|}{|\meta{list}|}{|\meta{cs}|}|.
304 % Due to the implementation method the \meta{element} is not allowed
307 \def\@removeelement#1#2#3{%
308 \def\reserved@a##1,#1,##2\reserved@a{##1,##2\reserved@b}%
309 \def\reserved@b##1,\reserved@b##2\reserved@b{%
310 \ifx,##1\@empty\else##1\fi}%
312 \expandafter\reserved@b\reserved@a,#2,\reserved@b,#1,\reserved@a}}
317 % \changes{v1.0e}{1995/04/29}{Removed unused defs for
318 % \cs{@setprotect} and \cs{@resetprotect}}
319 % \changes{v1.0e}{1995/04/29}{Moved init of \cs{protect}