1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \iffalse %%%%
% %
% Copyright (c) 2012 - Michiel Helvensteijn (www.mhelvens.net) %
% %
% http://latex-with.googlecode.com %
% %
% This work may be distributed and/or modified under the conditions %
% of the LaTeX Project Public License, either version 1.3 of this %
% license or (at your option) any later version. The latest version %
% of this license is in http://www.latex-project.org/lppl.txt %
% and version 1.3 or later is part of all distributions of LaTeX %
% version 2005/12/01 or later. %
% %
% This work has the LPPL maintenance status `author-maintained'. %
% %
% The Current Maintainer of this work is Michiel Helvensteijn. %
% %
% This work consists of the file with.sty and with.tex. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \fi %%%%
% \CheckSum{0}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Package Info} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
\ProvidesExplPackage{with}{2012/12/23}{0.0.1}
{an inline construct for passing token lists as parameters}
% \end{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Required Packages} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macrocode}
\RequirePackage{xparse}
\RequirePackage{l3regex}
% \end{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Package Code} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macrocode}
\cs_generate_variant:Nn \cs_generate_variant:Nn {cn}
% \end{macrocode}
% \begin{macrocode}
\cs_new:Nn \gen_use:nn {
\cs_generate_variant:cn
{ #1 : \prg_replicate:nn{\tl_count:n{#2}}{n} }
{ #2 }
\use:c{ #1 : #2 }
}
% \end{macrocode}
% \begin{macrocode}
\cs_new_protected:Nn \with:n {#1}
\cs_new_protected:Nn \with:nn {
\cs_set:Npn \__with:n ##1 {#2}
\__with:n {#1} }
\cs_new_protected:Nn \with:nnn {
\cs_set:Npn \__with:nn ##1##2 {#3}
\__with:nn {#1}{#2} }
\cs_new_protected:Nn \with:nnnn {
\cs_set:Npn \__with:nnn ##1##2##3 {#4}
\__with:nnn {#1}{#2}{#3} }
\cs_new_protected:Nn \with:nnnnn {
\cs_set:Npn \__with:nnnn ##1##2##3##4 {#5}
\__with:nnnn {#1}{#2}{#3}{#4} }
\cs_new_protected:Nn \with:nnnnnn {
\cs_set:Npn \__with:nnnnn ##1##2##3##4##5 {#6}
\__with:nnnnn {#1}{#2}{#3}{#4}{#5} }
\cs_new_protected:Nn \with:nnnnnnn {
\cs_set:Npn \__with:nnnnnn ##1##2##3##4##5##6 {#7}
\__with:nnnnnn {#1}{#2}{#3}{#4}{#5}{#6} }
\cs_new_protected:Nn \with:nnnnnnnn {
\cs_set:Npn \__with:nnnnnnn ##1##2##3##4##5##6##7 {#8}
\__with:nnnnnnn {#1}{#2}{#3}{#4}{#5}{#6}{#7} }
\cs_new_protected:Nn \with:nnnnnnnnn {
\cs_set:Npn \__with:nnnnnnnn ##1##2##3##4##5##6##7##8 {#9}
\__with:nnnnnnnn {#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8} }
% \end{macrocode}
% \begin{macrocode}
\msg_new:nnnn{with}{invalid-parameter-specs}{
The~argument~specification~'#1'~is~not~valid.
}{
The~argument~specification~should~consist~of~between~
one~and~seven~of~the~letters~'n',~'o',~'f',~'x',~'u'~or~'U'.
}
% \end{macrocode}
% \begin{macrocode}
\msg_new:nnnn{with}{invalid-parameter-number}{
You~specified~#1~arguments~but~provided~#2.
}{
Your~argument~specification~is~'#3',~which~means~you~should~
provide~#1~optional~arguments.~However,~you~provided~only~#2.
}
% \end{macrocode}
% \begin{macrocode}
\tl_new:N \l__with_argspec_tl
\tl_new:c {l__with_p_1_tl} \tl_new:c {l__with_p_2_tl}
\tl_new:c {l__with_p_3_tl} \tl_new:c {l__with_p_4_tl}
\tl_new:c {l__with_p_5_tl} \tl_new:c {l__with_p_6_tl}
\tl_new:c {l__with_p_7_tl}
\tl_new:N \l__with_code_tl
% \end{macrocode}
% \begin{macrocode}
\int_new:N \l__with_arg_int
\cs_new:Nn \__with_param_name: {
l__with_p_
\int_use:N\l__with_arg_int
_tl
}
% \end{macrocode}
% \begin{macrocode}
\tl_new:N \l__with_unique_counter_tl
\tl_new:N \l__with_param_tl
% \end{macrocode}
% \begin{macrocode}
\cs_generate_variant:Nn \with:nn {xn}
\cs_generate_variant:Nn \with:nnnnnnnnn {oooooooon}
% \end{macrocode}
% \begin{macrocode}
\NewDocumentCommand \with {m +o +o +o +o +o +o +o +m} {
% \end{macrocode}
% \begin{macrocode}
\regex_match:nnF {^[noxfuU]{1,7}$} {#1}
{ \msg_critical:nnn{with}{invalid-parameter-specs}{#1} }
% \end{macrocode}
% \begin{macrocode}
\tl_set:Nn \l__with_argspec_tl {#1}
\int_zero:N \l__with_arg_int
\IfValueT{#2} {
\tl_set:cn {l__with_p_1_tl} {#2} \int_incr:N \l__with_arg_int
\IfValueT{#3} {
\tl_set:cn {l__with_p_2_tl} {#3} \int_incr:N \l__with_arg_int
\IfValueT{#4} {
\tl_set:cn {l__with_p_3_tl} {#4} \int_incr:N \l__with_arg_int
\IfValueT{#5} {
\tl_set:cn {l__with_p_4_tl} {#5} \int_incr:N \l__with_arg_int
\IfValueT{#6} {
\tl_set:cn {l__with_p_5_tl} {#6} \int_incr:N \l__with_arg_int
\IfValueT{#7} {
\tl_set:cn {l__with_p_6_tl} {#7} \int_incr:N \l__with_arg_int
\IfValueT{#8} {
\tl_set:cn {l__with_p_7_tl} {#8} \int_incr:N \l__with_arg_int
}}}}}}}
\tl_set:Nn \l__with_code_tl {#9}
% \end{macrocode}
% \begin{macrocode}
\int_compare:nNnF {\tl_count:n{#1}} = {\l__with_arg_int} {
\msg_error:nnxxx{with}{invalid-parameter-number}
{ \tl_count:n{#1} }
{ \int_use:N \l__with_arg_int }
{ #1 }
}
% \end{macrocode}
% \begin{macrocode}
\tl_replace_all:Nnn \l__with_argspec_tl {u} {x}
\tl_replace_all:Nnn \l__with_argspec_tl {U} {c}
% \end{macrocode}
% \begin{macrocode}
\int_zero:N \l__with_arg_int
\tl_map_inline:nn {#1} {
\int_incr:N \l__with_arg_int
% \end{macrocode}
% \begin{macrocode}
\tl_if_in:nnT {uU} {##1} {
\tl_set:Nx \l__with_unique_counter_tl
{ g__with_unique_ \use:c{\__with_param_name:} _count_int }
\int_if_exist:cF {\l__with_unique_counter_tl}
{ \int_new:c {\l__with_unique_counter_tl} }
\int_incr:c {\l__with_unique_counter_tl}
\tl_put_left:cx {\__with_param_name:}
{ g_with_unique_ }
\tl_put_right:cx {\__with_param_name:}
{ _ \int_use:c{\l__with_unique_counter_tl} }
}
% \end{macrocode}
% \uninteresting\begin{macrocode}
}
% \end{macrocode}
% \begin{macrocode}
\with:oooooooon {\l__with_argspec_tl}
{\cs:w l__with_p_1_tl \cs_end:}
{\cs:w l__with_p_2_tl \cs_end:}
{\cs:w l__with_p_3_tl \cs_end:}
{\cs:w l__with_p_4_tl \cs_end:}
{\cs:w l__with_p_5_tl \cs_end:}
{\cs:w l__with_p_6_tl \cs_end:}
{\cs:w l__with_p_7_tl \cs_end:} {
\with:oooooooon {##1o}{##2}{##3}{##4}
{##5}{##6}{##7}{##8} {
\int_case:nnn {\l__with_arg_int} {
{1} { \gen_use:nn{with}{####1}
{####2} {\l__with_code_tl} }
{2} { \gen_use:nn{with}{####1}
{####2}{####3} {\l__with_code_tl} }
{3} { \gen_use:nn{with}{####1}
{####2}{####3}{####4} {\l__with_code_tl} }
{4} { \gen_use:nn{with}{####1}
{####2}{####3}{####4}
{####5} {\l__with_code_tl} }
{5} { \gen_use:nn{with}{####1}
{####2}{####3}{####4}
{####5}{####6} {\l__with_code_tl} }
{6} { \gen_use:nn{with}{####1}
{####2}{####3}{####4}
{####5}{####6}{####7} {\l__with_code_tl} }
{7} { \gen_use:nn{with}{####1}
{####2}{####3}{####4}
{####5}{####6}{####7}
{####8} {\l__with_code_tl} }
}{}
}
}
% \end{macrocode}
% \uninteresting\begin{macrocode}
}
% \end{macrocode}
|