summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/loops
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-02-12 23:53:37 +0000
committerKarl Berry <karl@freefriends.org>2013-02-12 23:53:37 +0000
commitb00ddd78e03236a73df3113f75cb0c607654d5a6 (patch)
treeabe63d734ede6c61983c4e8ebb8175859651b1ad /Master/texmf-dist/doc/latex/loops
parentdcf4eb75b6ae8a7d1ebab1fc40af55709bfd8139 (diff)
loops (12feb13)
git-svn-id: svn://tug.org/texlive/trunk@29090 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/loops')
-rw-r--r--Master/texmf-dist/doc/latex/loops/README153
1 files changed, 112 insertions, 41 deletions
diff --git a/Master/texmf-dist/doc/latex/loops/README b/Master/texmf-dist/doc/latex/loops/README
index 955e90f4994..61eb1c82929 100644
--- a/Master/texmf-dist/doc/latex/loops/README
+++ b/Master/texmf-dist/doc/latex/loops/README
@@ -6,7 +6,7 @@ Ahmed Musa
VERSION
-Version 1.1, 2012/10/16.
+Version 1.2, 2013/02/10.
LOCATION ON CTAN
@@ -14,7 +14,7 @@ macros/latex/contrib/loops/
LICENSE
-Copyright (c) 2012 Ahmed Musa
+Copyright (c) 2012-2013 Ahmed Musa
This software is author-maintained. Permission is granted to copy,
distribute and/or modify this software under the terms of the
@@ -27,7 +27,7 @@ NOTE
Non-LaTeX users can use the \newforeach macro (and some other
looping macros) by loading the file skeyval-for.tex. These exclude
-\foxloop or \foreachfox, which are available only in loops.sty.
+\foreachfox, which are available only in loops.sty.
SUMMARY
@@ -308,15 +308,17 @@ The looping macros include:
parameters/quantities.
There is a long list of options/keys in <options>, available for
- \newforeach and \foxloop or \foreachfox. For example, key 'reverse list'
+ \newforeach and \foreachfox. For example, key 'reverse list'
allows users to automatically reverse their lists prior to processing.
Also, there are many internal macros that can be accessed by the user.
A few of them are
- \interruptforeach, \foreachcurrentitem, \foreachnextitem,
- \foreachitemcount, \foreachprevitem, \prependtobeginforeach,
- \appendtobeginforeach, \prependtoendforeach, \appendtoendforeach,
+ \breaknewforeach (=\skvbreakloop),
+ \breakallforeachloops, \foreachcurrentitem,
+ \foreachnextitem, \foreachitemcount, \foreachprevitem,
+ \prependtobeginforeach, \appendtobeginforeach (=\atbeginforeach),
+ \prependtoendforeach, \appendtoendforeach (=\atendforeach),
\ifforeachlastitem, \foreachnestdepth, \foreachlistremainder,
\skvforeachonlyinitially.
@@ -325,11 +327,11 @@ The looping macros include:
number of items processed on each depth of nesting of
\newforeach. On any depth, the user can say, eg,
- \ifnum\foreachitemcount>10\relax\interruptforeach\fi
+ \ifnum\foreachitemcount>10\relax\breaknewforeach\fi
or
- \ifnum\foreachitemcount>10\relax\interruptloop\fi
+ \ifnum\foreachitemcount>10\relax\breaknewforeach\fi
You can insert \listbreaker as an item in <list> or <listcmd>
to terminate the list prematurely. \listpauser will pause
@@ -340,8 +342,7 @@ The looping macros include:
outcome-from-pgfs-foreach>. However, \newforeach itself
can't be said to be bug free.
- Maybe you fancy the following syntactic sugar, which PGF's
- \foreach can't presently process:
+ Maybe you fancy the following syntactic sugar:
\begingroup
\catcode`\,=13
@@ -369,6 +370,25 @@ The looping macros include:
\end{tikzpicture}
\show\xc
+ \begin{document}
+ \begin{tikzpicture}[every node/.style=draw]
+ \node (A) at (0,0) {A};
+ \node (B) at (1,0) {B};
+ \node (C) at (2,0) {C};
+ \node (D) at (3,0) {D};
+ \newforeach \n [remember=\n as \lastn initially A] in {B,C,D}
+ \draw [->] (\lastn) -- (\n);
+ \end{tikzpicture}
+
+ \foreachfox [remember=#1 as \x initially A] in {B,...,H} {%
+ $\overrightarrow{\x#1}$\ifforeachlastitem.\else,\space\fi
+ }
+
+ \foreachfox [list type=tsv,remember=#1 as \x initially A] {B(C1)DE[F1]GH} {%
+ $\overrightarrow{\x#1}$\ifforeachlastitem.\else,\space\fi
+ }
+ \end{document}
+
% Example credit: Tom Bombadil
\usetikzlibrary{arrows}
\parindent-40pt
@@ -398,25 +418,47 @@ The looping macros include:
need to manually expand the holder macros \x,\y,\z in the callbacks,
as I have seen some TikZ users do.
- Here is an example that uses parameters:
+ Here is an example that uses parameters.
+
+ \newforeach will not accept \skvifstreq or \skvifstrcmpTF because
+ they don't start with '\if'. So skeyval package cast \skvifstreq to
+ \ifforeachstrcmp.
+
+ Normally, breaking an inner loop doesn't affect the continuation of
+ outer loops, but \breakallforeachloops will break all current inner
+ and outer loops.
\newforeach \x [
item counter = \xc,
- exit when = \ifskvstreq#1\with b\then\fi,
+ exit when = \ifforeachstrcmp{#1}{b}\then\fi
] in {a,b,c} do {%
\newforeach [
count in = \yc all \y satisfying \ifnum\y>2\fi,
loop stopper = \ifnum\y>3\fi
] \y in {1,2,3,4,5} {%
- \skvcsdef{#1##1}{Items: #1, ##1}%
+ \typeout{Doing items: #1, ##1}%
+ %\ifnum\y=3 \breakallforeachloops\fi
}%
}
\begin{document}
Numbers: {\tt\string\xc}: \xc, {\tt\string\yc}: \yc
- \par\skvcsuse{a1}
- \par\skvcsuse{e10}
\end{document}
+ Because of 'continue={\ifnum\y=3\fi}' item number 3 will not appear
+ in the log file from the following loop:
+
+ \newforeach [
+ item counter = \xc,
+ exit when = \ifforeachstrcmp{#1}{c}\then\fi
+ ] \x in {a,...,e} do {%
+ \newforeach \y [
+ count in = \yc all \y satisfying \ifnum\y>2\fi,
+ continue = {\ifnum\y=3\fi}
+ ] in {1,...,10} {%
+ \typeout{Doing items: #1, ##1}%
+ % \ifnum\y=5 \breakallforeachloops\fi
+ }%
+ }
\begin{document}
\begin{tikzpicture}[scale=2]
@@ -435,7 +477,7 @@ The looping macros include:
\end{document}
- % A complete graph
+ % A complete graph.
% Example credit:
% Quintin Jean-Noël
% <http://moais.imag.fr/membres/jean-noel.quintin/>
@@ -466,60 +508,60 @@ The looping macros include:
\end{tikzpicture}
-\foxloop or \foreachfox:
+\foreachfox:
- \foxloop[<options>]{<list>}{<parametered.callback>}
- \foxloop*[<options>]{<listcmd>}{<parametered.callback>}
+ \foreachfox[<options>]{<list>}{<parametered.callback>}
+ \foreachfox*[<options>]{<listcmd>}{<parametered.callback>}
- \foxloop does everything that \newforeach does, but, in addition,
- it can process nsv/tsv (non-separated, tokenwise, lists). It can
+ \foreachfox does everything that \newforeach does, but, in addition,
+ it can process nsv/tsv (non-separated, tokenwise lists). It can
auto-complete ellipsis lists (ie, lists with '...'), but this
feature is available only for csv lists and not for tsv lists.
- 1. One important characteristic of \foxloop is that it doesn't use
+ 1. One important characteristic of \foreachfox is that it doesn't use
holder macros (eg, \x/\y), but instead it uses parameter
characters directly. So it doesn't accept/expect holder macros.
2. That means that if the argument isn't simple (ie, if it isn't #1),
then it has to be specified as the value of the key/option 'arg'
(eg, arg=#1/#2).
- 3. Note that \foxloop doesn't expect any optional 'in' or 'do' in the
+ 3. Note that \foreachfox doesn't expect any optional 'in' or 'do' in the
argument list.
- 4. Unlike \newforeach, \foxloop doesn't recognize the semicolon
- (;) as a callback terminator. In fact, the callback for \foxloop
+ 4. Unlike \newforeach, \foreachfox doesn't recognize the semicolon
+ (;) as a callback terminator. In fact, the callback for \foreachfox
should ideally be always enclosed in balanced braces. PGF
often uses the semicolon as the callback terminator. \newforeach
supports that feature.
The following macros are available to the user:
- \breakfoxloop, \interruptloop, \foxloopdepth, \foxcount,
- \previousfox, \currentfox, \nextfox, \iflastfox,
- \foxlistremainder, \prependtobeginfoxloop, \appendtobeginfoxloop,
- \prependtoendfoxloop, \appendtoendfoxloop.
+ \breakforeachfox, \foreachnestdepth, \foreachitemcount, \foreachprevitem,
+ \foreachcurrentitem, \foreachnextitem, \ifforeachlastitem, \foreachlistremainder,
+ \prependtobeginforeach, \appendtobeginforeach (=\atbeginforeachfox),
+ \prependtoendforeach, \appendtoendforeach (=\atendforeachfox).
Examples:
- \foxloop [
+ \foreachfox [
remember=#1 as \x initially A
] {B,...,H} {%
- $\overrightarrow{\x#1}$\iflastfox.\else,\space\fi
+ $\overrightarrow{\x#1}$\ifforeachlastitem.\else,\space\fi
}
This is equivalent to:
- \foxloop [
+ \foreachfox [
list type=tsv,
remember=#1 as \x initially A
- ] {BCDEFGH} {%
- $\overrightarrow{\x#1}$\iflastfox.\else,\space\fi
+ ] in {BCDEFGH} {%
+ $\overrightarrow{\x#1}$\ifforeachlastitem.\else,\space\fi
}
\usepackage{multicol}
\begin{document}
\begin{multicols}{2}
- \foxloop [count=\nchar] {a,...,f} {
- \foxloop [
+ \foreachfox [count=\nchar] {a,...,f} {
+ \foreachfox [
evaluate=##1 as \xe using \numexpr##1*20,
evaluate=##1 as \hx using \pgfmathparse{##1 mm*5},
evaluate=##1 as \vx using \pgfmathparse{##1 mm*1.5},
@@ -556,7 +598,7 @@ The looping macros include:
\node at (0,0) {%
\let\do\global
\do\DimWD\z@\do\DimHT\z@\do\DimDP\z@
- \foxloop* [arg=##1/##2,parser={#1}] #2 {%
+ \foreachfox* [arg=##1/##2,parser={#1}] #2 {%
\sbox0{#3}%
\ifdim\wd0>\DimWD\global\DimWD=\wd0\fi
\ifdim\ht0>\DimHT\global\DimHT=\ht0\fi
@@ -570,16 +612,45 @@ The looping macros include:
\def\bluelist{a/b,b/c,c/d,d/e,e/f,f/g,g/h,h/a}
\begin{tikzpicture}[scale=1.2,auto=left,every node/.style={circle,thick}]
\DimMeasure{;}{\yellowlist}{#1}
- \foxloop* [arg=#1/#2,parser={;},count=\xc] \yellowlist {
+ \foreachfox* [arg=#1/#2,parser={;},count=\xc] \yellowlist {
\node (#1) at (#2) [fill=blue!20,draw=yellow] {\DimBox{#1}};
}
\DimMeasure{,}{\bluelist}{#1--#2}
- \foxloop* [arg=#1/#2] \bluelist {
+ \foreachfox* [arg=#1/#2] \bluelist {
\draw [->] (#1) -- (#2)
node [midway,fill=red!20,draw=blue]{\DimBox{#1--#2}};
}
\end{tikzpicture}
\end{document}
+ \foreachfox [
+ item counter = \xc,
+ exit when = \ifforeachstrcmp{#1}{c}\then\fi
+ ] {a,b,c,d} {%
+ \foreachfox [
+ count in = \yc all ##1 satisfying \ifnum##1>2\fi,
+ ignore callback = {\ifnum##1=3\fi}
+ ] {1,...,10} {%
+ \typeout{Doing items: #1, ##1}%
+ \ifnum##1=8 \breakforeachfox\fi
+ }%
+ }
+ %\show\xc
+ \show\yc
+
+* Unfortunately, for drawing instructions like
+
+ \draw[blue] (p) \newforeach \p in {1,...,8}{...};
+
+ (ie, when \draw precedes \newforeach), both \newforeach and \foreachfox
+ will not work, because of the way TikZ hardwires \foreach for this type
+ of task. The tack that loops package resorts to in this situation is
+ simply to replace \newforeach and \foreachfox with \foreach. The fact
+ here is that in this case, both \newforeach and \foreachfox will not work
+ but leave everything for \foreach. This can be a problem when \newforeach
+ or \foreachfox is called to avoid a known bug in \foreach, such as at
+
+ <http://tex.stackexchange.com/questions/79586/foreach-has-a-%
+ problem-with-initially-argument-in-remember-part/79644#79644>
-% End of readme file of loops.sty \ No newline at end of file
+% End of readme file of loops package