From facafbb26a0554617788e362d73e71d7b070ffa3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 17 Oct 2012 22:45:04 +0000 Subject: loops (17oct12) git-svn-id: svn://tug.org/texlive/trunk@28002 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/loops/README | 99 ++++++++++++++++++++++------- Master/texmf-dist/tex/latex/loops/loops.sty | 48 ++++++++++---- 2 files changed, 112 insertions(+), 35 deletions(-) diff --git a/Master/texmf-dist/doc/latex/loops/README b/Master/texmf-dist/doc/latex/loops/README index 6eaa9719cbf..ca4a68a07e6 100644 --- a/Master/texmf-dist/doc/latex/loops/README +++ b/Master/texmf-dist/doc/latex/loops/README @@ -1,14 +1,16 @@ This is the README file for the 'loops' package. -*** Location: latex/macros - AUTHOR Ahmed Musa VERSION -Version 1.0, September 2012. +Version 1.1, October 2012. + +LOCATION ON CTAN + +macros/latex/contrib/loops/ LICENSE @@ -21,6 +23,11 @@ is provided 'as it is', without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for any particular purpose. +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. SUMMARY @@ -173,7 +180,7 @@ The looping macros include: terminate the loop prematurely (ie, before exhausting the list). - \skvnewregister\count\nr\nr=\tw@ + \newcount\nr\nr=\tw@ \def\do#1{% \let\noexpand#1% \expandafter\noexpand\csname\skvremovescape{#1}@% @@ -183,6 +190,32 @@ The looping macros include: \show\x -> \let\cmda\cmda@ii \let\cmdb\cmdb@ii +\skvgenloop: + + \skvgenloop{}{}{<1.parameter.callback>} + + \skvgenloop is non-expandable but it takes any arbitrary + list separator (parser). In the case of non-separated (nsv/tsv) + lists, can be empty. The list is not normalized prior to + parsing, and it is not possible to terminate the loop prematurely + (ie, before exhausting the list). + + Here, <1.parameter.callback> is not a macro, unlike the + <1.parameter.callback.macro> for \skvfor. + + \newcount\nr\nr=\tw@ + \def\stack{} + \skvgenloop{,}{\cmda,\cmdb}{% + \edef\stack{% + \unexpanded\expandafter{\stack}% + \let\noexpand#1% + \expandafter\noexpand\csname\skvremovescape{#1}@% + \romannumeral\nr\endcsname + }% + } + \show\stack + + \skvcommaloop, \skvecommaloop, \skvcommaparse, \skvkvparse: \skvcommaloop{}{} @@ -274,13 +307,18 @@ The looping macros include: restore the values of holder macros and some other internal parameters/quantities. - There is a long list of options, ie, keys in , - available for \newforeach and \foxloop. Also, there are many - internal macros that can be accessed by the user. A few of them - are \interruptforeach, \foreachcurrentitem, \foreachnextitem, + There is a long list of options/keys in , available for + \newforeach and \foxloop. 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, \ifforeachlastitem, \foreachnestdepth, \foreachlistremainder. + \foreachitemcount counts the items as the loop progresses. It is depth dependent, ie, it can be called to access the number of items processed on each depth of nesting of @@ -353,6 +391,26 @@ 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: + + \newforeach \x [ + item counter = \xc, + exit when = \ifskvstreq#1\with 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}% + }% + } + \begin{document} + Numbers: {\tt\string\xc}: \xc, {\tt\string\yc}: \yc + \par\skvcsuse{a1} + \par\skvcsuse{e10} + \end{document} + + \newforeach found a bug in PGF's \foreach, as reported at . However, \newforeach itself @@ -365,17 +423,18 @@ The looping macros include: \foxloop*[]{}{} \foxloop does everything that \newforeach does, but, in addition, - it can process nsv/tsv (non-separated lists). It can auto-complete - ellipsis lists (ie, lists with '...'), but this feature is - available only for csv lists and not for nsv lists. + 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 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, #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'. + 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 + argument list. 4. Unlike \newforeach, \foxloop doesn't recognize the semicolon (;) as a callback terminator. In fact, the callback for \foxloop should ideally be always enclosed in balanced braces. PGF @@ -434,8 +493,8 @@ The looping macros include: \end{multicols} \end{document} - - % Example credit: Heiko Oberdiek + + % Example credit: Heiko Oberdiek. \makeatletter \let\do\newdimen\do\DimWD\do\DimHT\do\DimDP \newcommand*{\DimBox}[1]{% @@ -474,10 +533,4 @@ The looping macros include: \end{document} -NOTE - -Non-LaTeX users can use the \newforeach macro (and some other -looping macros) by loading the file skeyval-for.tex. - - % End of readme file of loops.sty \ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/loops/loops.sty b/Master/texmf-dist/tex/latex/loops/loops.sty index 4183be5ba27..f05a61d6c10 100644 --- a/Master/texmf-dist/tex/latex/loops/loops.sty +++ b/Master/texmf-dist/tex/latex/loops/loops.sty @@ -1,5 +1,5 @@ %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% -% This is file 'loops.sty', version 1.0, September 2012. % +% This is file 'loops.sty', version 1.1, October 2012. % % % % This package and accompanying files may be distributed and/or % % modified under the conditions of the LaTeX Project Public License, % @@ -53,11 +53,16 @@ \do 032=10,033=12,036=03,038=04,040=12,041=12,042=12,043=12,% 059=12,045=12,047=12,058=12,063=12,091=12,093=12,126=13,\do=,% -\ProvidesPackage{loops}[2012/09/29 v1.0 Loops and list processors (AM)] +\ProvidesPackage{loops}[2012/10/14 v1.1 Loops and list processors (AM)] \NeedsTeXFormat{LaTeX2e}[2011/06/27] +% This is the way to load 'skeyval-for-core' here, otherwise we +% can't access some of the needed commands from 'skeyval-core': + \@ifpackageloaded{skeyval}{}{\RequirePackage{skeyval}} + \skvnewlet\ltxkernelfor\@for +\skvnewlet\ltxkerneltfor\@tfor % \skvusetwoprev{}{}{}{} % @@ -223,13 +228,12 @@ % \edef\x{\skvfor{\cmda,\cmdb}\do} % \show\x -> \let\cmda\cmda@ii \let\cmdb\cmdb@ii % -\skvnewdef\skvfor#1#2{\skv@for@a#1,\skv@for@nil,\skv@for@nnil{#2}} -\skvnewdef\skv@for@a#1,#2\skv@for@nnil#3{% - \skvifblank{#1}{% - \skv@for@a#2\skv@for@nnil{#3}% +\skvnewdef\skvfor#1#2{\skv@for@a{#2}#1,\skv@for@nil,} +\skvnewdef\skv@for@a#1#2,{% + \skvifblank{#2}{% + \skv@for@a{#1}% }{% - \skvifstrcmp{#1}{\skv@for@nil}% - {}{#3{#1}\skv@for@a#2\skv@for@nnil{#3}}% + \skvifstrcmp{#2}\skv@for@nil{}{#1{#2}\skv@for@a{#1}}% }% } @@ -385,7 +389,7 @@ % Define \foxloop keys. Name all the macros with 'foreach' prefix so % that we can avoid new command names and use the list auto-completion % scheme of \newforeach. -\quickkeys.define{foxloop}{% +\quickkeys.define{skvfoxloop}{% parser/{,}/ \def\skv@foreach@parser{#1} \skvstripouterbraces{2}\skv@foreach@parser @@ -505,10 +509,14 @@ \skv@fox@parseremember{#1}% }% ; + reverse list,reverse/true/ + \edef\skv@foreach@reverselist{0\skvifstrcmp{true}{#1}01}% + /true,false + ; } % Set up \foxloop defaults: -\quickkeys.set{foxloop}{% +\quickkeys.set{skvfoxloop}{% parser={,}, list is a macro=false, list type=csv, @@ -520,6 +528,7 @@ keep decimals=true, keep high decimals=false, expand before fill=false, + reverse list=false, } % Parser for 'evaluate' key: @@ -827,7 +836,17 @@ }% } -\skvnewlet\setupfoxloop\setupforeach +\skvnewdef*\skv@foxloop@kvlist{} +% \setupfoxloop{} +\skvrobustdef*\setupfoxloop#1{% + \skvifblank{#1}{}{% + \skvaddtolist\skv@foxloop@kvlist{#1}% + }% +} +\skvrobustdef*\skv@foxloop@setkeys#1{% + \def\reserved@a{\quickkeys.set{skvfoxloop}}% + \expandafter\reserved@a\expandafter{\skv@foxloop@kvlist,#1}% +} % \atbeginfoxloop[]{} \skvnewlet\atbeginfoxloop\atbeginforeach @@ -835,6 +854,7 @@ \skvnewlet\atendfoxloop\atendforeach \skvrobustdef*\foxloop{\skv@teststopt\skv@foxloop{}} +\skvnewlet\foreachfox\foxloop \skvrobustdef*\skv@foxloop[#1]#2#3{% \ifskv@tempst \def\skv@foreach@st{00}% @@ -848,7 +868,7 @@ \def\skv@foreach@precallback{}% \def\skv@foreach@postcallback{}% \def\skv@foreach@onlyinitially{}% - \quickkeys.set{foxloop}{#1}% + \skv@foxloop@setkeys{#1}% \if\skv@foreach@st\else \if\skv@foreach@listismacro \def\skv@foreach@st{00}% @@ -921,6 +941,10 @@ \skvifempty\skv@foreach@userlist{}{% \expandafter\skv@foreach@filllist\expandafter {\skv@foreach@parser}\skv@foreach@userlist + \if\skv@foreach@reverselist\skvafterfi + \expandafter\skv@foreach@doreverselist\expandafter + {\skv@foreach@parser}\skv@foreach@userlist + \fi }% % If \skv@foreach@userlist is empty, \currentfox in % \skv@foxloop@b will terminate the loop. -- cgit v1.2.3