Debian Codegraph @

texmf-dist/tex/generic/dowith/domore.sty

raw
1 \input plainpkg
2 \ProvidesPackage{domore}[2015/09/17 v0.32 dowith extended (UL)]
3 %% Copyright (C) 2012 2013 2015 Uwe Lueck,
4 %% http://www.contact-ednotes.sty.de.vu
5 %% -- author-maintained in the sense of LPPL below --
6 %%
7 %% This file can be redistributed and/or modified under
8 %% the terms of the LaTeX Project Public License; either
9 %% version 1.3c of the License, or any later version.
10 %% The latest version of this license is in
11 %% http://www.latex-project.org/lppl.txt
12 %% We did our best to help you, but there is NO WARRANTY.
13 %%
14 %% Please report bugs, problems, and suggestions via
15 %%
16 %% http://www.contact-ednotes.sty.de.vu
17 %%
18 \PushCatMakeLetterAt %% 2015/09/17
19 %% == With \LaTeX, extend 'dowith''s \cs{setdo} ==
20 %% %% mod. 2012/11/06:
21 %% The original 'dowith' offers |\setdo{<do>}|
22 %% for defining a one-parameter macro `\do' expanding to <do>.
23 %% The present package allows applying a <digit>-parameter macro
24 %% (maybe `\do', <digit> being 2, 3, or ...)
25 %% to a list of "brace groups" where each brace group
26 %% contains <digit> arguments. If \LaTeX\ is present ...
27 \ifltx
28 %% ... the following extension
29 %% \[|\setdo[<digit>]{<do>}]|\]
30 %% of the basic 'dowith' version
31 %% can be used to define a <digit>-parameter macro `\do'.
32 %% You also can equip `\do' with an initial optional argument by
33 %% \[|\setdo[<digit>][<default>]{<do>}]|\]
34 %% The next two moves allow loading the package
35 %% independently of 'dowith' (overriding its definition of `\setdo')
36 %% as well as using the package
37 %% with a format that has not defined `\do' before.
38 %% The first parameter of `\do' may even be \emph{optional.}
39 \let\setdo\relax \let\do\empty
40 \newcommand*{\setdo}[1][1]{\renewcommand\do[#1]}
41 \fi
42 %%
43 %% == Auxiliaries ==
44 %% |\@firstsecondoftwo{<balanced-1>}{<balanced-2>}| \
45 %% is a variant of \LaTeX's `\@firstofone{<balanced>}' for
46 %% \emph{two} arguments. It just removes outer braces
47 %% from each of the two arguments (provided it has outer braces),
48 %% resulting in \[<balanced-1><balanced-2>\]
49 \long\def\@firstsecondoftwo#1#2{#1#2}
50 %% % |\@secondfirstoftwo<arg-1><arg-2>| results in <ark-2><ark-1>
51 %% % where <ark-1> is ...
52 %% % [TODO declare "meta-function removing braces"---in 'dowith' documentation]
53 %% % (<arg-1>, <arg-2> must not contain `\par' tokens so far---TODO):
54 %% |\@secondfirstoftwo{<balanced-1>}{<balanced-2>}|
55 %% \emph{additionally} interchanges the two arguments
56 %% (after removing braces):
57 \long\def\@secondfirstoftwo#1#2{#2#1}
58 %% Our main application is using it as an extended `\expandafter'
59 %% before `\fi':
60 %% \[`\@secondfirstoftwo{<do>}\fi'\]
61 %% will expand to
62 %% \[`\fi<do>'\]
63 %% This won't work with `\else' in place of `\fi'.
64 %%
65 %% == Enhanced \cs{DoWith} ==
66 %% Here comes a more powerful variant of 'dowith''s `\DoWith'.
67 %% Instead of iterating a single "command" <cmd>
68 %% on an arglist <args> by
69 %% \[`\DoWith{<cmd>}<args>\StopDoing'\]
70 %% (cf. `dowith.pdf'), the present `\DoWith' can have a
71 %% more complex first argument. If <args> consists
72 %% of some brace groups the first of which is {<farg>}
73 %% so that <args> is
74 %% \[`{<farg>}<rgs>'\]
75 %% ---<rgs> being the remaining arglist---
76 %% \[|\DoWith{<repeat>}<args>\StopDoing|\]
77 %% works like
78 %% \[`<repeat>{<farg>}\DoWith{<repeat>}<rgs>\StopDoing'\]
79 %% and so on---a recursive explanation. Or if <args> is
80 %% \[`{<arg-1>}{<arg-2>}'\dots`{<arg-n>}'\]
81 %% ($n$ items), the result is like
82 %% \[`<repeat>{<arg-1>}<repeat>{<arg-2>}'\dots`<repeat>{<arg-n>}'\]
83 %% The actual definition is:
84 \def\DoWith#1#2{%
85 \ifx\StopDoing#2\empty %% not \@empty for Plain 2012/11/05
86 \else\@secondfirstoftwo{#1{#2}\DoWith{#1}}\fi}
87 %% In order to \strong{use} the remaining definitions from \strong{'dowith'
88 %% together with the present package}, %% \strong 2012/11/06
89 %% load `dowith.sty' before `domore.sty'.
90 %%
91 %% (v0.32:) |\StopDoing| must be provided in case 'dowith'
92 %% is not loaded at all. Being "undefined" is very
93 %% bad when `\DoWithMore' is used for a list of \emph{assignments.}
94 %% As in 'dowith', we assume that no argument starts with something
95 %% that has the same meaning as `\DoWith' itself:
96 \let\StopDoing\DoWith
97 %%
98 %% == Applications of \cs{DoWith} ==
99 %% `\DoWith' still is somewhat auxiliary. What I have used in practice,
100 %% are the following definitions.
101 %%
102 %% |\DoWithMore{<repeat>}<args>\StopDoing| %% was \DoMore 2015/05/22
103 %% with <args> as above
104 %% "unpacks" each arglist item so that <repeat> may be a macro
105 %% with more than one argument---say, <digit> arguments.
106 %% Then <f-arg> or <arg-1>, as well as <arg-2> $\dots$ <arg-n>,
107 %% should provide an arglist consisting of <digit> items.
108 \def\DoWithMore#1{\DoWith{\@firstsecondoftwo{#1}}}
109 %% Now I use metavariable <do> instead of <repeat>.
110 %% We consider some "separator" material <sep> to be inserted
111 %% between instances of applying <do> to an item of <args>.
112 %% We want to get
113 %% \[`<do>{<arg-1>}<sep><do>{<arg-2>}<sep>'\dots`<sep><do>{<arg-n>}'\]
114 %% This is achieved simply by starting with
115 %% \[`<do>{<farg>}'\]
116 %% and then proceeding as with
117 %% \[`\DoWith{<sep><do>}<rgs>\StopDoing'\]
118 %% And that's what |\DoSeparateWith{<do>}{<sep>}<args>\StopDoing| does:
119 \def\DoSeparateWith#1#2#3{#1{#3}\DoWith{#2#1}}
120 %% |\DoSeparateWithMore{<do>}{<sep>}<args>\StopDoing| combines
121 %% the two previous things, inserting separator material <sep>
122 %% and unpacking the nested arg\-lists:
123 \def\DoSeparateWithMore#1#2{% %% wieder 2012/06/05
124 \DoSeparateWith{\@firstsecondoftwo{#1}}{#2}}
125 %% My main application is that <do> is a link macro with arguments
126 %% <target> and <text> and that <sep> is \qtdcode{~\string|~}
127 %% (or some tie variant) to get a horizontal list of links like
128 %% \[\def|{$\vert$}\mbox{<text-1> | <text-2> | \dots | <text-n>}\]
129 %%
130 %% == Without \cs{StopDoing} == %% 2013/03/20, mv. 2013/03/22
131 %% The following enhancements of 'dowith' are provided by %% 2013/03/22
132 %% v0.31.
133 %%
134 %% |\DoWithAllOf{<repeat>}{<list>}| works like
135 %% \[`\DoWith{<repeat>}<list>\StopDoing'\]
136 %% as in 'dowith', but now with a more general first argument:
137 \def\DoWithAllOf#1#2{\DoWith{#1}#2\StopDoing}
138 %% |\DoWithAllIn{<repeat>}{<list-macro>}| works as in 'dowith' too
139 %% and needs the <repeat> enhancement too: %% 2013/03/21
140 \def\DoWithAllIn#1#2{%
141 \expandafter \@secondfirstoftwo \expandafter {#2}{\DoWith{#1}}%
142 \StopDoing}
143 %%
144 %% == Leaving and History ==
145 \PopLetterCatAt
146 \endinput
147
148 VERSION HISTORY
149 v0.1 2012/01/17 developed in `texblog.fdf'
150 (using \[re]newcommand*)
151 v0.2 2012/08/07 own file `domore.sty', \def's only
152 2012/08/08 dealing with "more" \setdo
153 v0.3 2012/11/05 using `plainpkg'; removing old % code
154 (see stored v0.2); auxiliaries \long
155 2012/11/06 doc.: more on \setdo (<digit>, opt. arg.),
156 usage with `dowith' \strong
157 2012/11/18 doc.: adjusted for `catchdq'; reworking for
158 \DoWith; \DoWithMore, \DoSeparateWith
159 2012/11/19 doc.: \DoSeparateWithMore
160 v0.31 2013/03/20 \DoWithAllOf
161 2013/03/21 \DoWithAllIn
162 2013/03/22 moving down new section, mod. doc.
163 v0.32 2015/05/22 doc. fix \DoWithMore; providing \StopDoing
164 2015/09/17 \PushCatMakeLetterAt!