summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/dowith
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-05-10 23:11:16 +0000
committerKarl Berry <karl@freefriends.org>2012-05-10 23:11:16 +0000
commit2b98282d58db23ce342019c8f3aacfa417eb61b1 (patch)
tree593c8bb698dc1539b31ba2bb9296c29c94ede74d /Master/texmf-dist/tex/generic/dowith
parentdd4ed517c862a027861583962334b41bf201ce5f (diff)
new generic package dowith (10may12)
git-svn-id: svn://tug.org/texlive/trunk@26292 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/dowith')
-rw-r--r--Master/texmf-dist/tex/generic/dowith/dowith.sty192
1 files changed, 192 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/dowith/dowith.sty b/Master/texmf-dist/tex/generic/dowith/dowith.sty
new file mode 100644
index 00000000000..89e34b74d3c
--- /dev/null
+++ b/Master/texmf-dist/tex/generic/dowith/dowith.sty
@@ -0,0 +1,192 @@
+\def\filename{dowith} \def\fileinfo{simple list loop (UL)}
+\def\filedate{2011/11/19} \def\fileversion{v0.2}
+%% Copyright (C) 2011 Uwe Lueck,
+%% http://www.contact-ednotes.sty.de.vu
+%% -- author-maintained in the sense of LPPL below --
+%%
+%% This file can be redistributed and/or modified under
+%% the terms of the LaTeX Project Public License; either
+%% version 1.3c of the License, or any later version.
+%% The latest version of this license is in
+%% http://www.latex-project.org/lppl.txt
+%% We did our best to help you, but there is NO WARRANTY.
+%%
+%% Please report bugs, problems, and suggestions via
+%%
+%% http://www.contact-ednotes.sty.de.vu
+%%
+%% == Proceeding without \LaTeX ==
+%% A little \LaTeX\ as in Bernd Raichle's %% 2011/11/19
+%% \CtanPkgRef{ngerman}{ngerman.sty}:
+\begingroup\expandafter\expandafter\expandafter\endgroup
+%% I need `\ProvidesPackage' for \ctanpkgref{fileinfo},
+%% my package version tools.
+\expandafter\ifx\csname ProvidesPackage\endcsname\relax
+%% %% 2011/11/07:
+%% When `\ProvidesPackage' is not defined, we provide
+%% a version of \LaTeX's `\in@'
+%% (an old version that may wrongly
+%% claim to have found an occurrence of a sequence,
+%% but is correct for single tokens)
+%% for checking token list macros.
+%% \LaTeX\ must not see `\ifin@' when it parses the
+%% `\ifx' conditional:
+ \expandafter\newif\csname ifin@\endcsname
+ \def\in@#1#2{%
+ \def\in@@##1#1##2##3\in@@{%
+ \ifx\in@##2\in@false\else\in@true\fi}%
+ \in@@#2#1\in@\in@@}
+%% 'readprov' stops reading the file at `\Provides'\texttt{...},
+%% therefore ...
+ \long\def\@gobble#1{} \expandafter\@gobble
+\else
+ \expandafter\@firstofone
+\fi
+{ \ProvidesPackage{\filename}[\filedate\space
+ \fileversion\space \fileinfo] }
+\chardef\atcode=\catcode`\@
+\catcode`\@=11 % \makeatletter
+%%
+%% == Applying a Command == %% 2011/11/07
+%% === Core ===
+%% |\DoWith{<cmd>}<list>\StopDoing| applies <cmd> to all elements
+%% of <list>. An element of <list> (after tokenizing)
+%% may be either a single token or a group `{<balanced>}'.
+\def\DoWith#1#2{%
+ \ifx\StopDoing#2%
+ \else#1{#2}\expandafter\DoWith\expandafter#1\fi}
+%% |\StopDoing| delimits the list:
+\let\StopDoing\DoWith
+%% ... something arbitrary that is not expected to occur in a list.
+%% With \[`\let\StopDoing*'\] instead, the star would end lists.
+%%
+%% |\DoWithAllOf{<cmd>}{<list>}| works like
+%% \[`\DoWith{<cmd>}<list>\StopDoing':\]
+\def\DoWithAllOf#1#2{\DoWith#1#2\StopDoing}
+%%
+%% === `&\do' being the Command ===
+%% \label{sec:do}
+%% When the <list> is worked at a single time in the \TeX\ run
+%% where assignments are possible, instead of introducing a new
+%% macro name for <cmd> you can use `\do' for <cmd> as a
+%% ``temporary" macro and define it right before
+%% \[`\DoWith{\do}<list>\StopDoing'\]
+%% However, we provide \[|\DoDoWith{<cmd>}<list>\StopDoing|\]
+%% as a substitute for the former line that at least saves one token.
+%% For the definition of `\do', we provide
+%% |\setdo{<def-text>}|.
+%% It works similarly to \[`\renewcommand{\do}[1]{<def-text>}',\]
+%% so <def-text> should contain a `#1':
+\def\setdo{\long\def\do##1}
+%% With |\letdo<cmd>| that is provided next where <cmd> is defined
+%% elsewhere, you could type
+%% \[`\letdo<cmd>\DoDoWith<list>\StopDoing'\]
+%% It seems to me, however, that you better type
+%% \[`\dowith<cmd><list>\StopDoing'\] instead.
+%% So I provide `\letdo' although I consider it useless here.
+%% It is provided somewhat for the sake of ``completeness,"
+%% thinking that it might be useful at other occasions such as
+%% preceding `\dospecials'.
+\def\letdo{\let\do}
+%% |\DoDoWith| has been described above:
+\def\DoDoWith{\DoWith\do}
+%% By analogy to `\DoWithAllOf', we provide
+%% |\DoDoWithAllOf{<list>}|:
+\def\DoDoWithAllOf{\DoWithAllOf\do}
+%%
+%% === Expand List Macro ===
+%% The former facilities may be quite useless
+%% as such a <list> will not be typed at a single place in the
+%% source code, rather the items to run <cmd> on may be collected
+%% occasionally when some routines run. The elements may be collected
+%% in a macro <list-macro> expanding to <list>.
+%% So we provide \[|\DoWithAllIn{<cmd>}{<list-macro>}|\]
+%% (or `\DoWithAllIn<cmd><list-macro>').
+%% There is no need to type `\StopDoing' here:
+\def\DoWithAllIn#1#2{%
+ \expandafter\DoWith\expandafter#1#2\StopDoing}
+%% |\DoDoWithAllIn{<list-macro>}| saves a backslash or token
+%% for `\do' as above in Sec.~\ref{sec:do}:
+\def\DoDoWithAllIn{\DoWithAllIn\do}
+%%
+%%
+%% == Handling List Macros ==
+%% === Initializing ===
+%% Here is some advanced `\let<cmd>\empty', perhaps a little
+%% irrelevant for practical purposes. Both
+%% \[|\InitializeListMacro{<list-macro>}|\] and
+%% \[|\ReInitializeListMacro{<list-macro>}|\] attempt to ``empty"
+%% <list-macro>, and when we don't believe that \LaTeX\ has been
+%% loaded, both do the same indeed. Otherwise the first one
+%% complains when <list-macro> seems to have been used earlier
+%% while the second complains when <list-macro> seems \emph{not} to
+%% have been used before:
+\expandafter\ifx\csname @latex@error\endcsname\relax
+ \def\InitializeListMacro#1{\let#1\empty} %% not \@empty 2011/11/07
+ \let\ReInitializeListMacro\InitializeListMacro
+\else
+ \def\InitializeListMacro#1{\@ifdefinable#1{\let#1\empty}}
+ \def\ReInitializeListMacro#1{%
+ \edef\@tempa{\expandafter\@gobble\string#1}%
+ \expandafter\@ifundefined\expandafter{\@tempa}%
+ {\@latex@error{\noexpand#1undefined}\@ehc}%
+ {\let#1\empty}}
+\fi
+%% |\ToListMacroAdd{<list-macro>}{<cmd-or>}|
+%% appends <cmd-or> to the replacement token list of <list-macro>.
+%% <cmd-or> may either be tokenized into a single token,
+%% or it is some `{<balanced>}'.
+\def\ToListMacroAdd#1#2{\DefExpandStart#1{#1#2}}
+\def\DefExpandStart#1{\expandafter\def\expandafter#1\expandafter}
+%%
+%% === Testing for Occurrence of a Token ===
+%% |\TestListMacroForToken{<list-macro>}{<cmd>}|
+%% sets `\in@true' when <cmd> occurs in <list-macro>
+%% and sets `\in@false' otherwise: %% 2011/11/07
+\def\TestListMacroForToken#1#2{%
+ \expandafter \in@ \expandafter #2\expandafter{#1}}
+%% Indeed I removed an earlier `\IfTokenInListMacro',
+%% now it's a kind of compromise between having a shorthand macro
+%% below and a generalization for users of the package.
+%%
+%% === Adding and Removing ===
+%% |\FromTokenListMacroRemove{<list-macro>}{<cmd>}|
+%% removes the token corresponding to <cmd> from the list
+%% stored in <list-macro>
+%% (our parsing method does not work with braces): %% 2011/11/07
+\def\FromTokenListMacroRemove#1#2{%
+%% I am not happy about defining \emph{two} parser macros,
+%% but for now ...
+ \TestListMacroForToken#1#2%
+ \ifin@
+ \def\RemoveThisToken##1#2{##1}%
+ \expandafter \DefExpandStart
+ \expandafter #1\expandafter {%
+ \expandafter\RemoveThisToken #1}%
+%% TODO warning otherwise?
+ \fi}
+%% %% 2011/11/07:
+%% ... but this only removes a single occurrence ...
+%% \[|\InTokenListMacroProvide{<list-macro>}{<cmd>}|\]
+%% avoids multiple entries of a token
+%% by \emph{not} adding anything when <cmd>
+%% already occurs in <list-macro> (again, this does not work with
+%% braces, try `\in@{{}}{{}}').
+\def\InTokenListMacroProvide#1#2{%
+ \TestListMacroForToken#1#2%
+ \ifin@ \else %% TODO warning?
+ \ToListMacroAdd#1#2%
+ \fi}
+%%
+%%
+%% == Leaving and History ==
+\catcode`\@=\atcode
+\endinput
+
+VERSION HISTORY
+v0.1 2011/06/23/28 stored separately
+v0.2 2011/11/02 simpler, documented
+ 2011/11/03 corrected \if/\else for init
+ 2011/11/07 \TestListMacroForToken, \InListMacroProvide;
+ doc.: \pagebreak, structure
+ 2011/11/19 modified LaTeX supplements