| 1 |
%\iffalse meta-comment |
| 2 |
%<*internal> |
| 3 |
\iffalse |
| 4 |
%</internal> |
| 5 |
%<*readme> |
| 6 |
Abstract |
| 7 |
---- |
| 8 |
The `cdcmd` package provides some conditional command, just like `styledcmd` |
| 9 |
package. The difference is `cdcmd` can define expandable command. |
| 10 |
|
| 11 |
See `cdcmd.pdf` (in English) or `cdcmd-cn.pdf` (in Chinese) for more details. |
| 12 |
|
| 13 |
Contributing |
| 14 |
---- |
| 15 |
[Issues](https://github.com/Sophanatprime/cdcmd/issues) and |
| 16 |
[pull requests](https://github.com/Sophanatprime/cdcmd/pulls) |
| 17 |
are always welcome. |
| 18 |
|
| 19 |
Copyright and license |
| 20 |
---- |
| 21 |
Copyright (C) 2021--2021 |
| 22 |
Wenjian Chern (Longaster) and any individual authors listed elsewhere in this file. |
| 23 |
-------------------------------------------------------------------------- |
| 24 |
|
| 25 |
This work may be distributed and/or modified under the |
| 26 |
conditions of the LaTeX Project Public License, either |
| 27 |
version 1.3c of this license or (at your option) any later |
| 28 |
version. This version of this license is in |
| 29 |
http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 30 |
and the latest version of this license is in |
| 31 |
http://www.latex-project.org/lppl.txt |
| 32 |
and version 1.3 or later is part of all distributions of |
| 33 |
LaTeX version 2005/12/01 or later. |
| 34 |
|
| 35 |
This work has the LPPL maintenance status `maintained`. |
| 36 |
|
| 37 |
The Current Maintainers of this work are Wenjian Chern (Longaster). |
| 38 |
-------------------------------------------------------------------------- |
| 39 |
%</readme> |
| 40 |
%<*internal> |
| 41 |
\fi |
| 42 |
%</internal> |
| 43 |
%\fi |
| 44 |
%\iffalse |
| 45 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 46 |
%<package>\RequirePackage{expl3}[2021/05/11] |
| 47 |
%<package>\GetIdInfo$Id: cdcmd.dtx 1.0 2021/10/12 +0815 Longaster$ |
| 48 |
%<package> {Expandable Conditional Command In LaTeX2e} |
| 49 |
%<package>\ProvidesExplPackage{cdcmd} |
| 50 |
%<package> {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} |
| 51 |
%<*driver> |
| 52 |
\documentclass{l3doc} |
| 53 |
\usepackage{xcolor} |
| 54 |
\usepackage{cdcmd} |
| 55 |
\EnableCrossrefs |
| 56 |
\CodelineIndex |
| 57 |
\RecordChanges |
| 58 |
\begin{document} |
| 59 |
\DocInput{\jobname.dtx} |
| 60 |
\PrintChanges |
| 61 |
\PrintIndex |
| 62 |
\end{document} |
| 63 |
%</driver> |
| 64 |
%\fi |
| 65 |
% |
| 66 |
%\GetFileInfo{cdcmd.sty} |
| 67 |
% \title{The \pkg{cdcmd} package} |
| 68 |
% |
| 69 |
% \author{Wenjian Chern |
| 70 |
% (Longaster\thanks{Email: \url{[email protected]}}~)} |
| 71 |
% |
| 72 |
% \date{Released \today, version \fileversion} |
| 73 |
% |
| 74 |
% \maketitle |
| 75 |
% |
| 76 |
% \begin{documentation} |
| 77 |
% \ExplSyntaxOn \let\strcmp\tex_strcmp:D \ExplSyntaxOff |
| 78 |
% |
| 79 |
% \begin{abstract} |
| 80 |
% \pkg{cdcmd} is a package that allows you define `polymorphic' command. Like \pkg{styledcmd} package, |
| 81 |
% you can define \tn{protected} command, but \pkg{cdcmd} can define expandable conditional command as well. |
| 82 |
% \end{abstract} |
| 83 |
% |
| 84 |
%\section{Main Interface} |
| 85 |
% |
| 86 |
%\begin{function}{\newcondition,\setcondition,\clearcondition} |
| 87 |
% \begin{syntax} |
| 88 |
% \cs{newcondition} \marg{identifier} \marg{id(s)} |
| 89 |
% \cs{setcondition} + \marg{identifier=ids list} |
| 90 |
% \cs{clearcondition}\oarg{identifier(s)} |
| 91 |
% \end{syntax} |
| 92 |
% \cs{newcondition} new \meta{identifier} and its \meta{ids}. |
| 93 |
% The leading and trailing spaces in \meta{identifier} will be removed. |
| 94 |
% |
| 95 |
% \cs{setcondition} sets \meta{ids} of \meta{identifier} locally. |
| 96 |
% The un-\verb|+| version will clear \meta{ids} formerly set. |
| 97 |
% |
| 98 |
% Both \meta{identifier} and \meta{id} cannot be \verb|*|. |
| 99 |
% |
| 100 |
% \cs{clearcondition} will clear ids from given \meta{identifiers} locally. Default value is \verb|*|, that is, clear all. |
| 101 |
%\end{function} |
| 102 |
% |
| 103 |
%\begin{function}{ |
| 104 |
% \conditionif,\conditioncmd, |
| 105 |
% \econditionif,\econditioncmd, |
| 106 |
%} |
| 107 |
% \begin{syntax} |
| 108 |
% \cs{conditionif} * \oarg{identifier=ids list} \marg{true} \marg{false} |
| 109 |
% \cs{conditioncmd} * \oarg{identifier=ids list} \marg{material} |
| 110 |
% \end{syntax} |
| 111 |
% When the \meta{identifier=ids list} makes \texttt{true} condition, leave \meta{true}/\marg{material} in the input stream. |
| 112 |
% Leaving \meta{false} when the condition is \texttt{false}. |
| 113 |
% |
| 114 |
% The starred version is \texttt{all}, unstarred version is \text{any}. |
| 115 |
% See below for more details. |
| 116 |
% |
| 117 |
% The \cs{econditionif} and \cs{econditioncmd} are expandable (\verb|f-|expandable). |
| 118 |
% \cs{conditionif}, \cs{conditioncmd} are \tn{protected}. |
| 119 |
% |
| 120 |
% The default value of \meta{identifier=id list} is \verb|*|, will leave \meta{true}/\meta{material} in the input stream. |
| 121 |
%\end{function} |
| 122 |
% |
| 123 |
%\begin{function}{ |
| 124 |
% \conditioncase,\conditioncaseTF, |
| 125 |
% \econditioncase,\econditioncaseTF |
| 126 |
%} |
| 127 |
% \begin{syntax} |
| 128 |
% \cs{conditioncaseTF} * ! |
| 129 |
% ~~\{ |
| 130 |
% ~~~~\marg{identifier=ids list case_1} \marg{code_1} |
| 131 |
% ~~~~\marg{identifier=ids list case_2} \marg{code_2} |
| 132 |
% ~~~~... |
| 133 |
% ~~~~\marg{identifier=ids list case_n} \marg{code_n} |
| 134 |
% ~~\} |
| 135 |
% ~~\marg{true code} |
| 136 |
% ~~\marg{false code} |
| 137 |
% \end{syntax} |
| 138 |
% Evaluates in turn each of the \meta{identifier=ids list} until the first one that evaluates |
| 139 |
% to \texttt{true} or to \texttt{false}, for un-\verb|!| version or \verb|!| version, respectively. |
| 140 |
% The \meta{code} associated to this first case is left in the input stream, followed by the \meta{true code}, |
| 141 |
% and other cases are discarded. If none of the cases match then only the \meta{false code} is inserted. |
| 142 |
% |
| 143 |
% The unstarred version is \verb|any|, starred version is \verb|all|. |
| 144 |
%\end{function} |
| 145 |
% |
| 146 |
%\begin{texnote} |
| 147 |
% The process in \meta{ids} is using \cs{clist_map_...} of \LaTeX3. It will view \verb|{,}| as empty, |
| 148 |
% while \verb|{{},}| are not. See \pkg{interface3.pdf} for more details. |
| 149 |
%\end{texnote} |
| 150 |
% |
| 151 |
% Supposing following commands have been used. |
| 152 |
%\begin{verbatim} |
| 153 |
% \newcondition{defined}{} |
| 154 |
% \newcondition{paper}{a4,a5,b5} |
| 155 |
% \setcondition{paper={a5,b5}} |
| 156 |
%\end{verbatim} |
| 157 |
% It will define an identifier named \verb|defined|, which has not id. |
| 158 |
% And define an identifier named \verb|paper|, which has three ids: \verb|a4, a5, b5|. |
| 159 |
% Then set two ids: \verb|a5,b5| for \verb|paper| identifier. |
| 160 |
% |
| 161 |
% \verb|any| will be evaluated to \texttt{true} if \meta{identifier=ids list} |
| 162 |
% matches any of one statement described followed: |
| 163 |
%\begin{enumerate} |
| 164 |
% \item \meta{identifier=ids list} is exactly \verb|*|; |
| 165 |
% \item \meta{identifier=ids list} is exactly a defined $\mathit{identifier}$, such as \verb|paper|, or \verb|defined|; |
| 166 |
% \item \meta{identifier=ids list} is a defined $\mathit{identifier}$, and its \meta{id} is \verb|*|, such as \verb|paper=*| or \verb|defined=*|; |
| 167 |
% \item \meta{identifier=ids list} is a defined $\mathit{identifier}$, and \emph{one of} item in \meta{ids} has been set, such as \verb|paper=b5| or \verb|paper={a5,b5}| or \verb|paper={a5,a0}| (\verb|a0| unset, but \verb|a5| already set. Any id set to \meta{identifier} \verb|defined| will evaluate to \texttt{false}, except \verb|*|, because the $\mathit{identifier}$ never have defined id, even the \meta{ids} is empty (\verb|defined=|); |
| 168 |
% \item \emph{Any} single item in \meta{identifier=ids list} matches any statements listed above, such as \verb|paper={a5,a0},undefined|. |
| 169 |
%\end{enumerate} |
| 170 |
% |
| 171 |
% \verb|all| will be evaluated to \text{true} if \meta{identifier=ids list} |
| 172 |
% matches any of one statement described followed. |
| 173 |
%\begin{enumerate} |
| 174 |
% \item \meta{identifier=ids list} is exactly \verb|*|; |
| 175 |
% \item \meta{identifier=ids list} is exactly a defined $\mathit{identifier}$, such as \verb|paper|, or \verb|defined|; |
| 176 |
% \item \meta{identifier=ids list} is a defined $\mathit{identifier}$, and its \meta{id} is \verb|*|, such as \verb|paper=*| or \verb|defined=*|; |
| 177 |
% \item \meta{identifier=ids list} is a defined $\mathit{identifier}$, and \emph{all of} the \meta{ids} has been set, such as \verb|paper=b5| or \verb|paper={a5,b5}|. The any id set to \meta{identifier} \verb|defined| will evaluate to \texttt{false}, except \verb|*|, because the $\mathit{identifier}$ never have defined id, even the \meta{ids} is empty (\verb|defined=|); |
| 178 |
% \item \emph{All} items in \meta{identifier=ids list} match any statements listed above, such as \verb|paper={a5,b5},defined|. |
| 179 |
%\end{enumerate} |
| 180 |
% |
| 181 |
%\begin{function}{ |
| 182 |
% \newconditioncommand, |
| 183 |
% \renewconditioncommand, |
| 184 |
% \provideconditioncommand, |
| 185 |
% \declareconditioncommand, |
| 186 |
% \neweconditioncommand, |
| 187 |
% \reneweconditioncommand, |
| 188 |
% \provideeconditioncommand, |
| 189 |
% \declareeconditioncommand, |
| 190 |
%} |
| 191 |
% \begin{syntax} |
| 192 |
% \cs{newconditioncommand} * \meta{function} \oarg{arg nums} \oarg{default} \marg{code} |
| 193 |
% \cs{neweconditioncommand} * \meta{function} \oarg{arg nums} \marg{code} |
| 194 |
% \end{syntax} |
| 195 |
% Those commands are just like \tn{newcommand}, \tn{renewcommand}, etc. They will define command like |
| 196 |
% \verb|\foo+|\marg{identifier=ids list}\meta{args}. The optional argument cannot contain \tn{par}. |
| 197 |
% |
| 198 |
% The \verb|e|-version commands define expandable command, and cannot set default value. |
| 199 |
% However you can use \pkg{xparse}-like command illustrated followed, |
| 200 |
% which can set default value. |
| 201 |
% |
| 202 |
% Unstarred version is \tn{long}, just like \LaTeX's. |
| 203 |
% |
| 204 |
% The new \meta{function} will take one optional argument: \verb|+|, the function is just like |
| 205 |
% the \verb|*| in \cs{conditionif}, etc. And one mandatory argument \meta{identifier=ids list}. |
| 206 |
% After absorbing these two arguments, then absorb arguments of given \meta{arg nums}, or use \meta{default}, if given. |
| 207 |
%\end{function} |
| 208 |
% |
| 209 |
%\begin{function}{ |
| 210 |
% \NewConditionCommand , |
| 211 |
% \RenewConditionCommand , |
| 212 |
% \ProvideConditionCommand , |
| 213 |
% \DeclareConditionCommand , |
| 214 |
% \NewExpandableConditionCommand , |
| 215 |
% \RenewExpandableConditionCommand , |
| 216 |
% \ProvideExpandableConditionCommand , |
| 217 |
% \DeclareExpandableConditionCommand , |
| 218 |
%} |
| 219 |
% \begin{syntax} |
| 220 |
% \cs{NewConditionCommand} \meta{function} \marg{arg spec} \marg{code} |
| 221 |
% \end{syntax} |
| 222 |
% Those commands are just like \pkg{xparse}'s \cs{NewDocumentCommand}, etc. |
| 223 |
% They will define command like \verb|\foo+|\marg{identifier=ids list}\meta{args}. |
| 224 |
% |
| 225 |
% \meta{arg spec} must follow the rules of the \pkg{xparse} package. |
| 226 |
% |
| 227 |
% The new \meta{function} will take one optional argument: \verb|+|, the function is just like |
| 228 |
% the \verb|*| in \cs{conditionif}, etc. And one mandatory argument \meta{identifier=ids list}. |
| 229 |
% After absorbing these two arguments, then absorb arguments of given \meta{arg spec}. |
| 230 |
%\end{function} |
| 231 |
% |
| 232 |
% \section{Examples} |
| 233 |
% |
| 234 |
% \input{cdcmd-test.tex} |
| 235 |
% |
| 236 |
% \section{For package authors} |
| 237 |
% |
| 238 |
% \begin{function}[pTF]{ |
| 239 |
% \cdcmd_any_if:n, |
| 240 |
% \cdcmd_all_if:n, |
| 241 |
% \cdcmd_any_if:o, |
| 242 |
% \cdcmd_all_if:o, |
| 243 |
% \cdcmd_any_if:V, |
| 244 |
% \cdcmd_all_if:V, |
| 245 |
% \cdcmd_any_if:f, |
| 246 |
% \cdcmd_all_if:f, |
| 247 |
% } |
| 248 |
% The meaning should be obvious. |
| 249 |
% \end{function} |
| 250 |
% |
| 251 |
% \begin{function}[TF]{ |
| 252 |
% \cdcmd_any_case_true:n, |
| 253 |
% \cdcmd_any_case_false:n, |
| 254 |
% \cdcmd_all_case_true:n, |
| 255 |
% \cdcmd_all_case_false:n, |
| 256 |
% } |
| 257 |
% The meaning should be obvious. |
| 258 |
% \end{function} |
| 259 |
% |
| 260 |
% \end{documentation} |
| 261 |
% |
| 262 |
% \begin{implementation} |
| 263 |
% |
| 264 |
% \section{Implementation} |
| 265 |
% |
| 266 |
% \begin{macrocode} |
| 267 |
%<*package> |
| 268 |
% \end{macrocode} |
| 269 |
% \begin{macrocode} |
| 270 |
%<@@=cdcmd> |
| 271 |
% \end{macrocode} |
| 272 |
% \begin{macrocode} |
| 273 |
\str_const:Nn \c_cdcmd_all_str { * } |
| 274 |
\clist_new:N \g__cdcmd_clist |
| 275 |
\bool_new:N \l__cdcmd_clear_set_bool |
| 276 |
\msg_new:nnn { cdcmd } { condition-exist } |
| 277 |
{ The~ condition~ `#1'~ you~ try~ to~ new~ already~ exists. } |
| 278 |
\msg_new:nnn { cdcmd } { condition-not-exist } |
| 279 |
{ The~ condition~ `#1'~ not~ exists. } |
| 280 |
\msg_new:nnn { cdcmd } { condition-id-not-exist } |
| 281 |
{ The~ id~ `#2' of~ condition~ `#1'~ not~ exists. } |
| 282 |
% \end{macrocode} |
| 283 |
% \begin{macro}[pTF]{\cdcmd_if_exist:n} |
| 284 |
% Condition \meta{indentifier} if exist. |
| 285 |
% \begin{macrocode} |
| 286 |
\prg_new_conditional:Npnn \cdcmd_if_exist:n #1 { p, T, F, TF } |
| 287 |
{ |
| 288 |
\clist_if_exist:cTF { c__cdcmd_condition@ #1 _clist } |
| 289 |
{ \prg_return_true: } { \prg_return_false: } |
| 290 |
} |
| 291 |
% \end{macrocode} |
| 292 |
% \end{macro} |
| 293 |
% \begin{macro}[TF]{\cdcmd_cd_id_if_exist:nn} |
| 294 |
% ID \meta{id} of condition \meta{indentifier} if exist. |
| 295 |
% \begin{macrocode} |
| 296 |
\prg_new_conditional:Npnn \cdcmd_cd_id_if_exist:nn #1#2 { T, F, TF } |
| 297 |
{ |
| 298 |
\clist_if_in:cnTF { c__cdcmd_condition@ #1 _clist } {#2} |
| 299 |
{ \prg_return_true: } { \prg_return_false: } |
| 300 |
} |
| 301 |
% \end{macrocode} |
| 302 |
% \end{macro} |
| 303 |
% \begin{macro}{ |
| 304 |
% \cdcmd_new:nn, |
| 305 |
% \cdcmd_set:nn, |
| 306 |
% \cdcmd_set_cdcmd_single:nn, |
| 307 |
% \cdcmd_set_cdcmd_all:n, |
| 308 |
% \cdcmd_set:n, |
| 309 |
% \cdcmd_clear_set:n, |
| 310 |
% } |
| 311 |
% \begin{macrocode} |
| 312 |
\cs_new_nopar:Npn \cdcmd_new:nn #1#2 |
| 313 |
{ |
| 314 |
\cdcmd_if_exist:nTF {#1} |
| 315 |
{ \msg_error:nnn { cdcmd } { condition-exist } {#1} } |
| 316 |
{ |
| 317 |
\clist_gput_right:Nn \g__cdcmd_clist {#1} |
| 318 |
\clist_const:cn { c__cdcmd_condition@ #1 _clist } {#2} |
| 319 |
\clist_new:c { l__cdcmd_curr_condition@ #1 _clist } |
| 320 |
} |
| 321 |
} |
| 322 |
\cs_new_nopar:Npn \cdcmd_set:nn #1#2 |
| 323 |
{ |
| 324 |
\cdcmd_if_exist:nTF {#1} |
| 325 |
{ |
| 326 |
\bool_if:NT \l__cdcmd_clear_set_bool |
| 327 |
{ \clist_clear:c { l__cdcmd_curr_condition@ #1 _clist } } |
| 328 |
\clist_map_inline:nn {#2} |
| 329 |
{ |
| 330 |
\str_if_eq:eeTF {##1} { \c_cdcmd_all_str } |
| 331 |
{ \clist_map_break:n { \cdcmd_set_cdcmd_all:n {#1} } } |
| 332 |
{ \cdcmd_set_cdcmd_single:nn {#1} {##1} } |
| 333 |
} |
| 334 |
} |
| 335 |
{ \msg_warning:nnn { cdcmd } { condition-not-exist } {#1} } |
| 336 |
} |
| 337 |
\cs_new_nopar:Npn \cdcmd_set_cdcmd_single:nn #1#2 |
| 338 |
{ |
| 339 |
\cdcmd_if_exist:nTF {#1} |
| 340 |
{ |
| 341 |
\cdcmd_cd_id_if_exist:nnTF {#1} {#2} |
| 342 |
{ \clist_put_right:cn { l__cdcmd_curr_condition@ #1 _clist } {#2} } |
| 343 |
{ \msg_warning:nnnn { cdcmd } { condition-id-not-exist } {#1} {#2} } |
| 344 |
} |
| 345 |
{ \msg_warning:nnn { cdcmd } { condition-not-exist } } |
| 346 |
} |
| 347 |
\cs_new_nopar:Npn \cdcmd_set_cdcmd_all:n #1 |
| 348 |
{ |
| 349 |
\cdcmd_if_exist:nTF {#1} |
| 350 |
{ |
| 351 |
\clist_set_eq:cc |
| 352 |
{ l__cdcmd_curr_condition@ #1 _clist } |
| 353 |
{ c__cdcmd_condition@ #1 _clist } |
| 354 |
} |
| 355 |
{ \msg_warning:nnn { cdcmd } { condition-not-exist } {#1} } |
| 356 |
} |
| 357 |
\cs_new_nopar:Npn \cdcmd_set:n |
| 358 |
{ \keyval_parse:NNn \cdcmd_set_cdcmd_all:n \cdcmd_set:nn } |
| 359 |
\cs_new_nopar:Npn \cdcmd_clear_set:n #1 |
| 360 |
{ |
| 361 |
\bool_set_true:N \l__cdcmd_clear_set_bool |
| 362 |
\keyval_parse:NNn \cdcmd_set_cdcmd_all:n \cdcmd_set:nn {#1} |
| 363 |
\bool_set_false:N \l__cdcmd_clear_set_bool |
| 364 |
} |
| 365 |
% \end{macrocode} |
| 366 |
% \end{macro} |
| 367 |
% \begin{macro}[pTF]{ |
| 368 |
% \cdcmd_any_if:n, |
| 369 |
% \cdcmd_any_if:o, |
| 370 |
% \cdcmd_any_if:V, |
| 371 |
% \cdcmd_any_if:f, |
| 372 |
% } |
| 373 |
% \begin{macrocode} |
| 374 |
\cs_new:Npn \cdcmd_any_if:nTF #1 |
| 375 |
{ |
| 376 |
\bool_if:nTF |
| 377 |
{ |
| 378 |
\keyval_parse:NNn |
| 379 |
\__cdcmd_any_i:n \__cdcmd_any_ii:nn {#1} |
| 380 |
\c_false_bool |
| 381 |
} |
| 382 |
} |
| 383 |
\cs_new:Npn \cdcmd_any_if_p:n #1 |
| 384 |
{ |
| 385 |
\bool_if_p:n |
| 386 |
{ |
| 387 |
\keyval_parse:NNn |
| 388 |
\__cdcmd_any_i:n \__cdcmd_any_ii:nn {#1} |
| 389 |
\c_false_bool |
| 390 |
} |
| 391 |
} |
| 392 |
\cs_new:Npn \cdcmd_any_if:nT #1#2 { \cdcmd_any_if:nTF {#1} {#2} { } } |
| 393 |
\cs_new:Npn \cdcmd_any_if:nF #1 { \cdcmd_any_if:nTF {#1} { } } |
| 394 |
\cs_new:Npn \cdcmd_any_if:nFT #1#2#3 { \cdcmd_any_if:nTF {#1} {#3} {#2} } |
| 395 |
\prg_generate_conditional_variant:Nnn \cdcmd_any_if:n { o, V, f } { p, T, F, TF } |
| 396 |
\cs_new:Npn \__cdcmd_any_i:n #1 |
| 397 |
{ |
| 398 |
\str_if_eq:eeTF {#1} { \c_cdcmd_all_str } |
| 399 |
{ \c_true_bool || } |
| 400 |
{ \cdcmd_if_exist:nT {#1} { \c_true_bool || } } |
| 401 |
} |
| 402 |
\cs_new:Npn \__cdcmd_any_ii:nn #1#2 |
| 403 |
{ |
| 404 |
\cdcmd_if_exist:nT {#1} |
| 405 |
{ |
| 406 |
\clist_map_tokens:nn {#2} |
| 407 |
{ \__cdcmd_any_ii_aux:nn {#1} } |
| 408 |
} |
| 409 |
} |
| 410 |
\cs_new:Npn \__cdcmd_any_ii_aux:nn #1#2 |
| 411 |
{ |
| 412 |
\str_if_eq:eeTF {#2} { \c_cdcmd_all_str } |
| 413 |
{ \clist_map_break:n { \tex_the:D \c_true_bool || } } |
| 414 |
{ |
| 415 |
\__cdcmd_clist_if_in:cnT { l__cdcmd_curr_condition@ #1 _clist } {#2} |
| 416 |
{ \clist_map_break:n { \tex_the:D \c_true_bool || } } |
| 417 |
} |
| 418 |
} |
| 419 |
% \end{macrocode} |
| 420 |
% \end{macro} |
| 421 |
% \begin{macro}[pTF]{ |
| 422 |
% \cdcmd_all_if:n, |
| 423 |
% \cdcmd_all_if:o, |
| 424 |
% \cdcmd_all_if:V, |
| 425 |
% \cdcmd_all_if:f, |
| 426 |
% } |
| 427 |
% \begin{macrocode} |
| 428 |
\cs_new:Npn \cdcmd_all_if:nTF #1 |
| 429 |
{ |
| 430 |
\bool_if:nTF |
| 431 |
{ |
| 432 |
\keyval_parse:NNn |
| 433 |
\__cdcmd_all_i:n \__cdcmd_all_ii:nn {#1} |
| 434 |
\c_true_bool |
| 435 |
} |
| 436 |
} |
| 437 |
\cs_new:Npn \cdcmd_all_if_p:n #1 |
| 438 |
{ |
| 439 |
\bool_if_p:n |
| 440 |
{ |
| 441 |
\keyval_parse:NNn |
| 442 |
\__cdcmd_all_i:n \__cdcmd_all_ii:nn {#1} |
| 443 |
\c_true_bool |
| 444 |
} |
| 445 |
} |
| 446 |
\cs_new:Npn \cdcmd_all_if:nT #1#2 { \cdcmd_all_if:nTF {#1} {#2} { } } |
| 447 |
\cs_new:Npn \cdcmd_all_if:nF #1 { \cdcmd_all_if:nTF {#1} { } } |
| 448 |
\cs_new:Npn \cdcmd_all_if:nFT #1#2#3 { \cdcmd_all_if:nTF {#1} {#3} {#2} } |
| 449 |
\prg_generate_conditional_variant:Nnn \cdcmd_all_if:n { o, V, f } { p, T, F, TF } |
| 450 |
\cs_new:Npn \__cdcmd_all_i:n #1 |
| 451 |
{ |
| 452 |
\str_if_eq:eeF {#1} { \c_cdcmd_all_str } |
| 453 |
{ \cdcmd_if_exist:nF {#1} { \c_false_bool && } } |
| 454 |
} |
| 455 |
\cs_new:Npn \__cdcmd_all_ii:nn #1#2 |
| 456 |
{ |
| 457 |
\cdcmd_if_exist:nTF {#1} |
| 458 |
{ |
| 459 |
\bool_lazy_and_p:nn |
| 460 |
{ \int_compare_p:n { \clist_count:n {#2} > 0 } } |
| 461 |
{ |
| 462 |
\int_compare_p:n |
| 463 |
{ \clist_map_tokens:nn {#2} { \__cdcmd_all_ii_aux:nn {#1} } 1 > 0 } |
| 464 |
} && |
| 465 |
} |
| 466 |
{ \c_false_bool && } |
| 467 |
} |
| 468 |
\cs_new:Npn \__cdcmd_all_ii_aux:nn #1#2 |
| 469 |
{ |
| 470 |
\str_if_eq:eeF {#2} { \c_cdcmd_all_str } |
| 471 |
{ |
| 472 |
\__cdcmd_clist_if_in:cnF { l__cdcmd_curr_condition@ #1 _clist } {#2} |
| 473 |
{ \clist_map_break:n { - } } |
| 474 |
} |
| 475 |
} |
| 476 |
% \end{macrocode} |
| 477 |
% \end{macro} |
| 478 |
% \begin{macro}[pTF]{ |
| 479 |
% \__cdcmd_clist_if_in:Nn, |
| 480 |
% \__cdcmd_clist_if_in:NV, |
| 481 |
% \__cdcmd_clist_if_in:No, |
| 482 |
% \__cdcmd_clist_if_in:cn, |
| 483 |
% \__cdcmd_clist_if_in:cV, |
| 484 |
% \__cdcmd_clist_if_in:co, |
| 485 |
% \__cdcmd_clist_if_in:nn, |
| 486 |
% \__cdcmd_clist_if_in:nV, |
| 487 |
% \__cdcmd_clist_if_in:no, |
| 488 |
% } |
| 489 |
% \begin{macrocode} |
| 490 |
\prg_new_conditional:Npnn \__cdcmd_clist_if_in:Nn #1#2 { p, T, F, TF } |
| 491 |
{ |
| 492 |
\int_compare:nTF |
| 493 |
{ 0 \clist_map_tokens:Nn #1 { \__cdcmd_if_eq_break:ee {#2} } > 0 } |
| 494 |
{ \prg_return_true: } { \prg_return_false: } |
| 495 |
} |
| 496 |
\prg_generate_conditional_variant:Nnn \__cdcmd_clist_if_in:Nn |
| 497 |
{ NV, No, cn, cV, co } { p, T, F, TF } |
| 498 |
\prg_new_conditional:Npnn \__cdcmd_clist_if_in:nn #1#2 { p, T, F, TF } |
| 499 |
{ |
| 500 |
\int_compare:nTF |
| 501 |
{ 0 \clist_map_tokens:nn {#1} { \__cdcmd_if_eq_break:ee {#2} } > 0 } |
| 502 |
{ \prg_return_true: } { \prg_return_false: } |
| 503 |
} |
| 504 |
\prg_generate_conditional_variant:Nnn \__cdcmd_clist_if_in:nn { nV, no } { p, T, F, TF } |
| 505 |
\cs_new:Npn \__cdcmd_if_eq_break:ee #1#2 |
| 506 |
{ |
| 507 |
\str_if_eq:eeT {#1} {#2} { \clist_map_break:n { 1 } } |
| 508 |
} |
| 509 |
% \end{macrocode} |
| 510 |
% \end{macro} |
| 511 |
% \begin{macro}[TF]{ |
| 512 |
% \cdcmd_any_case_true:n, |
| 513 |
% \cdcmd_any_case_false:n, |
| 514 |
% \cdcmd_all_case_true:n, |
| 515 |
% \cdcmd_all_case_false:n, |
| 516 |
% } |
| 517 |
% Conditional case, see also \cs{bool_case_true:n} and \cs{bool_case_false:n} in \pkg{source3.pdf}. |
| 518 |
% \begin{macrocode} |
| 519 |
\scan_new:N \s__cdcmd_mark |
| 520 |
\scan_new:N \s__cdcmd_stop |
| 521 |
\cs_new:Npn \cdcmd_any_case_true:nTF { \exp:w \__cdcmd_any_case_true:nTF } |
| 522 |
\cs_new:Npn \cdcmd_any_case_true:n #1 { \exp:w \__cdcmd_any_case_true:nTF {#1} { } { } } |
| 523 |
\cs_new:Npn \cdcmd_all_case_true:nTF { \exp:w \__cdcmd_all_case_true:nTF } |
| 524 |
\cs_new:Npn \cdcmd_all_case_true:n #1 { \exp:w \__cdcmd_all_case_true:nTF {#1} { } { } } |
| 525 |
\cs_new:Npn \cdcmd_any_case_false:nTF { \exp:w \__cdcmd_any_case_false:nTF } |
| 526 |
\cs_new:Npn \cdcmd_any_case_false:n #1 { \exp:w \__cdcmd_any_case_false:nTF {#1} { } { } } |
| 527 |
\cs_new:Npn \cdcmd_all_case_false:nTF { \exp:w \__cdcmd_all_case_false:nTF } |
| 528 |
\cs_new:Npn \cdcmd_all_case_false:n #1 { \exp:w \__cdcmd_all_case_false:nTF {#1} { } { } } |
| 529 |
\cs_new:Npn \__cdcmd_any_case_true:nTF #1#2#3 |
| 530 |
{ |
| 531 |
\__cdcmd_case:Nw \cdcmd_any_if:nTF #1 { * } { } |
| 532 |
\s__cdcmd_mark {#2} \s__cdcmd_mark {#3} \s__cdcmd_stop |
| 533 |
} |
| 534 |
\cs_new:Npn \__cdcmd_all_case_true:nTF #1#2#3 |
| 535 |
{ |
| 536 |
\__cdcmd_case:Nw \cdcmd_all_if:nTF #1 { * } { } |
| 537 |
\s__cdcmd_mark {#2} \s__cdcmd_mark {#3} \s__cdcmd_stop |
| 538 |
} |
| 539 |
\cs_new:Npn \__cdcmd_any_case_false:nTF #1#2#3 |
| 540 |
{ |
| 541 |
\__cdcmd_case:Nw \cdcmd_any_if:nFT #1 { * } { } |
| 542 |
\s__cdcmd_mark {#2} \s__cdcmd_mark {#3} \s__cdcmd_stop |
| 543 |
} |
| 544 |
\cs_new:Npn \__cdcmd_all_case_false:nTF #1#2#3 |
| 545 |
{ |
| 546 |
\__cdcmd_case:Nw \cdcmd_all_if:nFT #1 { * } { } |
| 547 |
\s__cdcmd_mark {#2} \s__cdcmd_mark {#3} \s__cdcmd_stop |
| 548 |
} |
| 549 |
\cs_new:Npn \__cdcmd_case:Nw #1#2#3 |
| 550 |
{ #1 {#2} { \__cdcmd_case_end:nw {#3} } { \__cdcmd_case:Nw #1 } } |
| 551 |
\cs_new:Npn \__cdcmd_case_end:nw #1#2#3 \s__cdcmd_mark #4#5 \s__cdcmd_stop |
| 552 |
{ \exp_end: #1 #4 } |
| 553 |
% \end{macrocode} |
| 554 |
% \end{macro} |
| 555 |
% \begin{macro}{\newcondition,\setcondition,\clearcondition} |
| 556 |
% Conditional setting command for document. |
| 557 |
% \begin{macrocode} |
| 558 |
\NewDocumentCommand \newcondition { >{ \TrimSpaces } m } { \cdcmd_new:nn {#1} } |
| 559 |
\NewDocumentCommand \setcondition { t+ } |
| 560 |
{ \IfBooleanTF {#1} { \cdcmd_set:n } { \cdcmd_clear_set:n } } |
| 561 |
\NewDocumentCommand \clearcondition { !O{*} } |
| 562 |
{ |
| 563 |
\clist_map_inline:nn {#1} |
| 564 |
{ |
| 565 |
\str_if_eq:eeTF {##1} { \c_cdcmd_all_str } |
| 566 |
{ |
| 567 |
\clist_map_break:n |
| 568 |
{ \exp_after:wN \clearcondition \exp_after:wN [ \g__cdcmd_clist ] } |
| 569 |
} |
| 570 |
{ |
| 571 |
\cdcmd_if_exist:nTF {##1} |
| 572 |
{ \clist_clear:c { l__cdcmd_curr_condition@ ##1 _clist } } |
| 573 |
{ \msg_warning:nnn { cdcmd } { condition-not-exist } {##1} } |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
% \end{macrocode} |
| 578 |
% \end{macro} |
| 579 |
% \begin{macrocode} |
| 580 |
\NewExpandableDocumentCommand \econditionif { s O{*} +m +m } |
| 581 |
{ |
| 582 |
\IfBooleanTF {#1} |
| 583 |
{ \cdcmd_all_if:nTF } |
| 584 |
{ \cdcmd_any_if:nTF } |
| 585 |
{#2} {#3} {#4} |
| 586 |
} |
| 587 |
\NewExpandableDocumentCommand \econditioncmd { s O{*} +m } |
| 588 |
{ |
| 589 |
\IfBooleanTF {#1} |
| 590 |
{ \cdcmd_all_if:nTF } |
| 591 |
{ \cdcmd_any_if:nTF } |
| 592 |
{#2} {#3} { } |
| 593 |
} |
| 594 |
\NewExpandableDocumentCommand \econditioncase { s +m } |
| 595 |
{ |
| 596 |
\IfBooleanTF {#1} |
| 597 |
{ \cdcmd_all_case:n {#2} } |
| 598 |
{ \cdcmd_any_case:n {#2} } |
| 599 |
} |
| 600 |
\NewExpandableDocumentCommand \econditioncaseTF { s +m } |
| 601 |
{ |
| 602 |
\IfBooleanTF {#1} |
| 603 |
{ \cdcmd_all_case:nTF {#2} } |
| 604 |
{ \cdcmd_any_case:nTF {#2} } |
| 605 |
} |
| 606 |
\NewDocumentCommand \conditionif { s O{*} +m +m } |
| 607 |
{ |
| 608 |
\IfBooleanTF {#1} |
| 609 |
{ \cdcmd_all_if:nTF } |
| 610 |
{ \cdcmd_any_if:nTF } |
| 611 |
{#2} {#3} {#4} |
| 612 |
} |
| 613 |
\NewDocumentCommand \conditioncmd { s O{*} +m } |
| 614 |
{ |
| 615 |
\IfBooleanTF {#1} |
| 616 |
{ \cdcmd_all_if:nTF } |
| 617 |
{ \cdcmd_any_if:nTF } |
| 618 |
{#2} {#3} { } |
| 619 |
} |
| 620 |
\NewDocumentCommand \conditioncase { s t! +m } |
| 621 |
{ |
| 622 |
\IfBooleanTF {#2} |
| 623 |
{ |
| 624 |
\IfBooleanTF {#1} |
| 625 |
{ \cdcmd_all_case_false:n {#3} } |
| 626 |
{ \cdcmd_any_case_false:n {#3} } |
| 627 |
} |
| 628 |
{ |
| 629 |
\IfBooleanTF {#1} |
| 630 |
{ \cdcmd_all_case_true:n {#3} } |
| 631 |
{ \cdcmd_any_case_true:n {#3} } |
| 632 |
} |
| 633 |
} |
| 634 |
\NewDocumentCommand \conditioncaseTF { s t! +m } |
| 635 |
{ |
| 636 |
\IfBooleanTF {#2} |
| 637 |
{ |
| 638 |
\IfBooleanTF {#1} |
| 639 |
{ \cdcmd_all_case_false:nTF {#3} } |
| 640 |
{ \cdcmd_any_case_false:nTF {#3} } |
| 641 |
} |
| 642 |
{ |
| 643 |
\IfBooleanTF {#1} |
| 644 |
{ \cdcmd_all_case_true:nTF {#3} } |
| 645 |
{ \cdcmd_any_case_true:nTF {#3} } |
| 646 |
} |
| 647 |
} |
| 648 |
% \end{macrocode} |
| 649 |
% \begin{macro}{} |
| 650 |
% Define new \pkg{xparse} like conditional command. |
| 651 |
% \begin{macrocode} |
| 652 |
\str_const:Nn \c_cdcmd_pair_u_str { cdcmd@u@ } |
| 653 |
\str_const:Nn \c_cdcmd_pair_n_str { cdcmd@n@ } |
| 654 |
\cs_new_nopar:Npn \__cdcmd_cs_pair_u:N #1 |
| 655 |
{ \c_cdcmd_pair_u_str \cs_to_str:N #1 } |
| 656 |
\cs_new_nopar:Npn \__cdcmd_cs_pair_n:N #1 |
| 657 |
{ \c_cdcmd_pair_n_str \cs_to_str:N #1 } |
| 658 |
\cs_new:Npn \__cdcmd_arg_spec_from_num:nn #1#2 |
| 659 |
{ |
| 660 |
\if_case:w 0#1 \exp_stop_f: |
| 661 |
\or: #2 \or: #2#2 \or: #2#2#2 \or: #2#2#2#2 \or: #2#2#2#2#2 \or: #2#2#2#2#2#2 |
| 662 |
\or: #2#2#2#2#2#2#2 \or: #2#2#2#2#2#2#2#2 \else: #2#2#2#2#2#2#2#2#2 \fi: |
| 663 |
} |
| 664 |
\cs_new_nopar:Npn \__cdcmd_cs_pair_u:Nn #1#2 |
| 665 |
{ |
| 666 |
\c_cdcmd_pair_u_str |
| 667 |
\cs_to_str:N #1 : |
| 668 |
\__cdcmd_arg_spec_from_num:nn {#2} { n } |
| 669 |
} |
| 670 |
\cs_new_nopar:Npn \__cdcmd_cs_pair_n:Nn #1#2 |
| 671 |
{ |
| 672 |
\c_cdcmd_pair_n_str |
| 673 |
\cs_to_str:N #1 : |
| 674 |
\__cdcmd_arg_spec_from_num:nn {#2} { n } |
| 675 |
} |
| 676 |
% do not check cs_if_free, let xparse do it |
| 677 |
\cs_new:Npn \__cdcmd_new_cdcmd_command:NN #1#2 |
| 678 |
{ |
| 679 |
\cs_new_protected:Npn #1 ##1##2##3 |
| 680 |
{ |
| 681 |
#2 ##1 { t+ m } |
| 682 |
{ |
| 683 |
\IfBooleanTF {####1} |
| 684 |
{ \cdcmd_all_if:nTF } |
| 685 |
{ \cdcmd_any_if:nTF } |
| 686 |
{####2} |
| 687 |
{ \use:c { \__cdcmd_cs_pair_u:N ##1 } } |
| 688 |
{ \use:c { \__cdcmd_cs_pair_n:N ##1 } } |
| 689 |
} |
| 690 |
\exp_args:Nc #2 |
| 691 |
{ \__cdcmd_cs_pair_u:N ##1 } {##2} {##3} |
| 692 |
\exp_args:Nc #2 |
| 693 |
{ \__cdcmd_cs_pair_n:N ##1 } {##2} { } |
| 694 |
} |
| 695 |
} |
| 696 |
\seq_const_from_clist:Nn \c__cdcmd_Command_seq |
| 697 |
{ |
| 698 |
\NewDocumentCommand , |
| 699 |
\RenewDocumentCommand , |
| 700 |
\ProvideDocumentCommand , |
| 701 |
\DeclareDocumentCommand , |
| 702 |
\NewExpandableDocumentCommand , |
| 703 |
\RenewExpandableDocumentCommand , |
| 704 |
\ProvideExpandableDocumentCommand , |
| 705 |
\DeclareExpandableDocumentCommand , |
| 706 |
} |
| 707 |
\seq_const_from_clist:Nn \c__cdcmd_COMMAND_seq |
| 708 |
{ |
| 709 |
\NewConditionCommand , |
| 710 |
\RenewConditionCommand , |
| 711 |
\ProvideConditionCommand , |
| 712 |
\DeclareConditionCommand , |
| 713 |
\NewExpandableConditionCommand , |
| 714 |
\RenewExpandableConditionCommand , |
| 715 |
\ProvideExpandableConditionCommand , |
| 716 |
\DeclareExpandableConditionCommand , |
| 717 |
} |
| 718 |
\seq_mapthread_function:NNN |
| 719 |
\c__cdcmd_COMMAND_seq |
| 720 |
\c__cdcmd_Command_seq |
| 721 |
\__cdcmd_new_cdcmd_command:NN |
| 722 |
% \end{macrocode} |
| 723 |
% \end{macro} |
| 724 |
% \begin{macro}{} |
| 725 |
% Define \LaTeX{} like command. |
| 726 |
% \begin{macrocode} |
| 727 |
% do not check cs_if_free, let xparse do it |
| 728 |
\cs_new:Npn \__cdcmd_new_cdcmd_cmd_no:nnn #1#2#3 |
| 729 |
{ |
| 730 |
\cs_new_protected:Npn #1 ##1##2##3 |
| 731 |
{ |
| 732 |
#3 ##1 { t+ m } |
| 733 |
{ |
| 734 |
\IfBooleanTF {####1} |
| 735 |
{ \cdcmd_all_if:nTF } |
| 736 |
{ \cdcmd_any_if:nTF } |
| 737 |
{ ####2 } |
| 738 |
{ \use:c { \__cdcmd_cs_pair_u:Nn ##1 {##2} } } |
| 739 |
{ \use:c { \__cdcmd_cs_pair_n:Nn ##1 {##2} } } |
| 740 |
} |
| 741 |
#2 { \__cdcmd_cs_pair_u:Nn ##1 {##2} } {##3} |
| 742 |
#2 { \__cdcmd_cs_pair_n:Nn ##1 {##2} } { } |
| 743 |
} |
| 744 |
} |
| 745 |
\cs_generate_variant:Nn \__cdcmd_new_cdcmd_cmd_no:nnn { xxx } |
| 746 |
\seq_const_from_clist:Nn \c__cdcmd_cmd_no_seq |
| 747 |
{ |
| 748 |
\cs_set_protected:cn , \cs_set_protected_nopar:cn , |
| 749 |
\cs_set_protected:cn , \cs_set_protected_nopar:cn , |
| 750 |
\cs_set_protected:cn , \cs_set_protected_nopar:cn , |
| 751 |
\cs_set:cn , \cs_set_nopar:cn , |
| 752 |
\cs_set:cn , \cs_set_nopar:cn , |
| 753 |
\cs_set:cn , \cs_set_nopar:cn , |
| 754 |
} |
| 755 |
\seq_const_from_clist:Nn \c__cdcmd_Cmd_no_seq |
| 756 |
{ |
| 757 |
\NewDocumentCommand , \NewDocumentCommand , |
| 758 |
\RenewDocumentCommand , \RenewDocumentCommand , |
| 759 |
\DeclareDocumentCommand , \DeclareDocumentCommand , |
| 760 |
\NewExpandableDocumentCommand , \NewExpandableDocumentCommand , |
| 761 |
\RenewExpandableDocumentCommand , \RenewExpandableDocumentCommand , |
| 762 |
\DeclareExpandableDocumentCommand , \DeclareExpandableDocumentCommand , |
| 763 |
} |
| 764 |
\seq_const_from_clist:Nn \c__cdcmd_CMD_no_seq |
| 765 |
{ |
| 766 |
\__cdcmd_new_cdcmd_p_l_num:Nnn , \__cdcmd_new_cdcmd_p_nl_num:Nnn , |
| 767 |
\__cdcmd_renew_cdcmd_p_l_num:Nnn , \__cdcmd_renew_cdcmd_p_nl_num:Nnn , |
| 768 |
\__cdcmd_declare_cdcmd_p_l_num:Nnn , \__cdcmd_declare_cdcmd_p_nl_num:Nnn , |
| 769 |
\__cdcmd_new_cdcmd_np_l_num:Nnn , \__cdcmd_new_cdcmd_np_nl_num:Nnn , |
| 770 |
\__cdcmd_renew_cdcmd_np_l_num:Nnn , \__cdcmd_renew_cdcmd_np_nl_num:Nnn , |
| 771 |
\__cdcmd_declare_cdcmd_np_l_num:Nnn , \__cdcmd_declare_cdcmd_np_nl_num:Nnn , |
| 772 |
} |
| 773 |
\int_step_inline:nn { 6 } |
| 774 |
{ |
| 775 |
\__cdcmd_new_cdcmd_cmd_no:xxx |
| 776 |
{ \seq_item:Nn \c__cdcmd_CMD_no_seq {#1} } |
| 777 |
{ \seq_item:Nn \c__cdcmd_cmd_no_seq {#1} } |
| 778 |
{ \seq_item:Nn \c__cdcmd_Cmd_no_seq {#1} } |
| 779 |
} |
| 780 |
\tl_new:N \l__cdcmd_arg_spec_tl |
| 781 |
\cs_new:Npn \__cdcmd_generate_arg_spec:nnn #1#2#3 |
| 782 |
{ |
| 783 |
\tl_set:Nn \l__cdcmd_arg_spec_tl { O{#2} } |
| 784 |
\if_int_compare:w #1 > 1 \exp_stop_f: |
| 785 |
\int_step_inline:nn {#1-1} { \tl_put_right:Nn \l__cdcmd_arg_spec_tl {#3} } |
| 786 |
\fi: |
| 787 |
} |
| 788 |
\cs_new:Npn \__cdcmd_new_cdcmd_cmd_o_aux:nn #1#2 |
| 789 |
{ |
| 790 |
\cs_new_protected:Npn #1 ##1##2##3##4##5 |
| 791 |
{ |
| 792 |
#2 ##1 { t+ m } |
| 793 |
{ |
| 794 |
\IfBooleanTF{####1} |
| 795 |
{ \cdcmd_all_if:nTF } |
| 796 |
{ \cdcmd_any_if:nTF } |
| 797 |
{####2} |
| 798 |
{ \use:c { \__cdcmd_cs_pair_u:N ##1 } } |
| 799 |
{ \use:c { \__cdcmd_cs_pair_n:N ##1 } } |
| 800 |
} |
| 801 |
\__cdcmd_generate_arg_spec:nnn {##2} {##3} {##5} |
| 802 |
\exp_args:NcV #2 { \__cdcmd_cs_pair_u:N ##1 } \l__cdcmd_arg_spec_tl {##4} |
| 803 |
\exp_args:NcV #2 { \__cdcmd_cs_pair_n:N ##1 } \l__cdcmd_arg_spec_tl { } |
| 804 |
} |
| 805 |
} |
| 806 |
\seq_const_from_clist:Nn \c__cdcmd_CMD_o_seq |
| 807 |
{ \NewDocumentCommand , \RenewDocumentCommand , \DeclareDocumentCommand } |
| 808 |
\seq_const_from_clist:Nn \c__cdcmd_cmd_o_seq |
| 809 |
{ |
| 810 |
\__cdcmd_new_cdcmd_o_num:Nnnnn , |
| 811 |
\__cdcmd_renew_cdcmd_o_num:Nnnnn , |
| 812 |
\__cdcmd_declare_cdcmd_o_num:Nnnnn , |
| 813 |
} |
| 814 |
\seq_mapthread_function:NNN |
| 815 |
\c__cdcmd_cmd_o_seq |
| 816 |
\c__cdcmd_CMD_o_seq |
| 817 |
\__cdcmd_new_cdcmd_cmd_o_aux:nn |
| 818 |
\cs_new_protected:Npn \__cdcmd_new_cdcmd_cmd_ne_aux:n #1 |
| 819 |
{ |
| 820 |
\exp_args:Nc \NewDocumentCommand { #1 conditioncommand } { s m O{0} o +m } |
| 821 |
{ |
| 822 |
\IfBooleanTF{##1} |
| 823 |
{ |
| 824 |
\IfNoValueTF{##4} |
| 825 |
{ \use:c { __cdcmd_ #1 _cdcmd_p_nl_num:Nnn } ##2 {##3} {##5} } |
| 826 |
{ \use:c { __cdcmd_ #1 _cdcmd_o_num:Nnnnn } ##2 {##3} {##4} {##5} { m } } |
| 827 |
} |
| 828 |
{ |
| 829 |
\IfNoValueTF{##4} |
| 830 |
{ \use:c { __cdcmd_ #1 _cdcmd_p_l_num:Nnn } ##2 {##3} {##5} } |
| 831 |
{ \use:c { __cdcmd_ #1 _cdcmd_o_num:Nnnnn } ##2 {##3} {##4} {##5} { +m } } |
| 832 |
} |
| 833 |
} |
| 834 |
} |
| 835 |
\clist_map_function:nN { new, renew, declare } \__cdcmd_new_cdcmd_cmd_ne_aux:n |
| 836 |
\NewDocumentCommand \provideconditioncommand { s m O{0} o +m } |
| 837 |
{ |
| 838 |
\cs_if_free:NT #2 |
| 839 |
{ |
| 840 |
\IfBooleanTF{#1} |
| 841 |
{ |
| 842 |
\IfNoValueTF{#4} |
| 843 |
{ \newconditioncommand * #2 [#3] {#5} } |
| 844 |
{ \newconditioncommand * #2 [#3] [#4] {#5} } |
| 845 |
} |
| 846 |
{ |
| 847 |
\IfNoValueTF{#4} |
| 848 |
{ \newconditioncommand #2 [#3] {#5} } |
| 849 |
{ \newconditioncommand #2 [#3] [#4] {#5} } |
| 850 |
} |
| 851 |
} |
| 852 |
} |
| 853 |
|
| 854 |
\int_step_inline:nnnn { 7 } { 1 } { 12 } |
| 855 |
{ |
| 856 |
\__cdcmd_new_cdcmd_cmd_no:xxx |
| 857 |
{ \seq_item:Nn \c__cdcmd_CMD_no_seq {#1} } |
| 858 |
{ \seq_item:Nn \c__cdcmd_cmd_no_seq {#1} } |
| 859 |
{ \seq_item:Nn \c__cdcmd_Cmd_no_seq {#1} } |
| 860 |
} |
| 861 |
|
| 862 |
\cs_new_protected:Npn \__cdcmd_new_cdcmd_cmd_e_no_aux:n #1 |
| 863 |
{ |
| 864 |
\exp_args:Nc \NewDocumentCommand { #1 econditioncommand } { s m O{0} +m } |
| 865 |
{ |
| 866 |
\IfBooleanTF{##1} |
| 867 |
{ \use:c { __cdcmd_ #1 _cdcmd_np_nl_num:Nnn } ##2 {##3} {##4} } |
| 868 |
{ \use:c { __cdcmd_ #1 _cdcmd_np_l_num:Nnn } ##2 {##3} {##4} } |
| 869 |
} |
| 870 |
} |
| 871 |
\clist_map_function:nN { new, renew, declare } \__cdcmd_new_cdcmd_cmd_e_no_aux:n |
| 872 |
\NewDocumentCommand \provideeconditioncommand { s m O{0} +m } |
| 873 |
{ |
| 874 |
\cs_if_free:NT #2 |
| 875 |
{ |
| 876 |
\IfBooleanTF{#1} |
| 877 |
{ \neweconditioncommand * #2 [#3] {#4} } |
| 878 |
{ \neweconditioncommand #2 [#2] {#4} } |
| 879 |
} |
| 880 |
} |
| 881 |
% \end{macrocode} |
| 882 |
% \end{macro} |
| 883 |
% \begin{macrocode} |
| 884 |
%</package> |
| 885 |
% \end{macrocode} |
| 886 |
% |
| 887 |
% \end{implementation} |
| 888 |
% |
| 889 |
% \endinput |
| 890 |
% |
| 891 |
%<*test> |
| 892 |
{\color{red!90!black} |
| 893 |
\begin{verbatim} |
| 894 |
\newcondition{defined}{} |
| 895 |
\newcondition{paper}{a4,a5,b5} |
| 896 |
\setcondition{paper={a5,b5}} |
| 897 |
\end{verbatim} |
| 898 |
} |
| 899 |
|
| 900 |
{ |
| 901 |
\newcondition{defined}{} |
| 902 |
\newcondition{paper}{a4,a5,b5} |
| 903 |
\setcondition{paper={a5,b5}} |
| 904 |
\def\cdcmdtest#1->#2 /{\textcolor{red!90!black}{\detokenize{#1}}:~ #1 \newline} |
| 905 |
\parindent=0pt\ttfamily |
| 906 |
\cdcmdtest\conditionif[*]{t}{f}->t / |
| 907 |
\cdcmdtest\conditionif[defined]{t}{f}->t / |
| 908 |
\cdcmdtest\conditionif[defined=]{t}{f}->f / |
| 909 |
\cdcmdtest\conditionif[defined=*]{t}{f}->t / |
| 910 |
\cdcmdtest\conditionif[defined=a]{t}{f}->f / |
| 911 |
\cdcmdtest\conditionif[paper={a5,a0},undefined]{t}{f}->t / |
| 912 |
|
| 913 |
\cdcmdtest\conditionif*[*]{t}{f}->t / |
| 914 |
\cdcmdtest\conditionif*[defined]{t}{f}->t / |
| 915 |
\cdcmdtest\conditionif*[defined={,,}]{t}{f}->f / |
| 916 |
\cdcmdtest\conditionif*[defined=*]{t}{f}->t / |
| 917 |
\cdcmdtest\conditionif*[defined=a]{t}{f}->f / |
| 918 |
\cdcmdtest\conditionif*[paper={a5,a0},undefined]{t}{f}->f / |
| 919 |
\cdcmdtest\conditionif*[*,undefined]{t}{f}->f / |
| 920 |
\cdcmdtest\conditionif*[paper={a5,b5}]{t}{f}->t / |
| 921 |
\cdcmdtest\conditionif*[paper={a5,,b5}]{t}{f}->t / |
| 922 |
\cdcmdtest\conditionif*[paper={a5,b6,a5}]{t}{f}->f / |
| 923 |
\cdcmdtest\conditionif*[paper={a5,{ },45}]{t}{f}->f / |
| 924 |
\cdcmdtest\conditionif*[*,defined,paper={a5,b5}]{t}{f}->t / |
| 925 |
} |
| 926 |
|
| 927 |
{\color{red!90!black} |
| 928 |
\begin{verbatim} |
| 929 |
\def\truetext{true} \def\falsetext{false} |
| 930 |
\edef\testa{\econditionif[*]{true}{false}} |
| 931 |
\ifx\testa\truetext t\else f\fi |
| 932 |
\ifx\testa\falsetext t\else f\fi |
| 933 |
\strcmp {\econditionif[*]{true}{false}} {true} |
| 934 |
\strcmp {\econditionif[*]{true}{false}} {false} |
| 935 |
\strcmp {\testa} {\truetext} |
| 936 |
\strcmp {\testa} {\falsetext} |
| 937 |
\end{verbatim} |
| 938 |
} |
| 939 |
\def\truetext{true} \def\falsetext{false} |
| 940 |
\edef\testa{\econditionif[*]{true}{false}} |
| 941 |
\ifx\testa\truetext t\else f\fi |
| 942 |
\ifx\testa\falsetext t\else f\fi |
| 943 |
\strcmp{\econditionif[*]{true}{false}}{true} |
| 944 |
\strcmp{\econditionif[*]{true}{false}}{false} |
| 945 |
\strcmp{\testa}{\truetext} |
| 946 |
\strcmp{\testa}{\falsetext} |
| 947 |
|
| 948 |
{\color{red!90!black} |
| 949 |
\begin{verbatim} |
| 950 |
\conditioncase{ |
| 951 |
{paper=a3} {a3} |
| 952 |
{paper=a4} {a4} |
| 953 |
{paper,defined} {pd} |
| 954 |
} |
| 955 |
\end{verbatim} |
| 956 |
} |
| 957 |
\conditioncase{ |
| 958 |
{paper=a3} {a3} |
| 959 |
{paper=a4} {a4} |
| 960 |
{paper,defined} {pd} |
| 961 |
} |
| 962 |
|
| 963 |
{\color{red!90!black} |
| 964 |
\begin{verbatim} |
| 965 |
\conditioncaseTF{ |
| 966 |
{paper=a3} {a3} |
| 967 |
{paper=a4} {a4} |
| 968 |
{paper,defined} {pd} |
| 969 |
}{true}{false} |
| 970 |
\end{verbatim} |
| 971 |
} |
| 972 |
\conditioncaseTF{ |
| 973 |
{paper=a3} {a3} |
| 974 |
{paper=a4} {a4} |
| 975 |
{paper,defined} {pd} |
| 976 |
}{true}{false} |
| 977 |
|
| 978 |
{\color{red!90!black} |
| 979 |
\begin{verbatim} |
| 980 |
\conditioncase!{ |
| 981 |
{paper=a3} {a3} |
| 982 |
{paper=a4} {a4} |
| 983 |
{paper,defined} {pd} |
| 984 |
} |
| 985 |
\end{verbatim} |
| 986 |
} |
| 987 |
\conditioncase!{ |
| 988 |
{paper=a3} {a3} |
| 989 |
{paper=a4} {a4} |
| 990 |
{paper,defined} {pd} |
| 991 |
} |
| 992 |
|
| 993 |
{\color{red!90!black} |
| 994 |
\begin{verbatim} |
| 995 |
\conditioncaseTF!{ |
| 996 |
{paper=a3} {a3} |
| 997 |
{paper=a4} {a4} |
| 998 |
{paper,defined} {pd} |
| 999 |
}{true}{false} |
| 1000 |
\end{verbatim} |
| 1001 |
} |
| 1002 |
\conditioncaseTF!{ |
| 1003 |
{paper=a3} {a3} |
| 1004 |
{paper=a4} {a4} |
| 1005 |
{paper,defined} {pd} |
| 1006 |
}{true}{false} |
| 1007 |
|
| 1008 |
{\color{red!90!black} |
| 1009 |
\begin{verbatim} |
| 1010 |
\newconditioncommand\longprotectedcdcmd{longprotectedcdcmd} |
| 1011 |
\newconditioncommand\longprotectedcdcmdi[1]{longprotectedcdcmdi<#1>} |
| 1012 |
\newconditioncommand\longprotectedcdcmdio[1][DFT]{longprotectedcdcmdio<#1>} |
| 1013 |
\newconditioncommand*\shortprotectedcdcmd{shortprotectedcdcmd} |
| 1014 |
\newconditioncommand*\shortprotectedcdcmdi[1]{shortprotectedcdcmdi<#1>} |
| 1015 |
\newconditioncommand*\shortprotectedcdcmdio[1][DFT]{shortprotectedcdcmdio<#1>} |
| 1016 |
|
| 1017 |
\setcondition{paper={a4,a5}} |
| 1018 |
\longprotectedcdcmd{*} |
| 1019 |
\longprotectedcdcmdi{*}{1\par arg} |
| 1020 |
\longprotectedcdcmdio{*} |
| 1021 |
\longprotectedcdcmdio{*}[1opt] |
| 1022 |
\longprotectedcdcmdio{paper=a4}[1opt a4] |
| 1023 |
\longprotectedcdcmdio+{paper={a4,a7}}[1opt a4a7] |
| 1024 |
\shortprotectedcdcmd{*} |
| 1025 |
\shortprotectedcdcmdi{*}{1\par arg} |
| 1026 |
\shortprotectedcdcmdio{*} |
| 1027 |
\shortprotectedcdcmdio{*}[1opt] |
| 1028 |
\shortprotectedcdcmdio{paper=a4}[1opt a4] |
| 1029 |
\shortprotectedcdcmdio+{paper={a4,a7}}[1opt a4a7] |
| 1030 |
\end{verbatim} |
| 1031 |
} |
| 1032 |
\newconditioncommand\longprotectedcdcmd{longprotectedcdcmd} |
| 1033 |
\newconditioncommand\longprotectedcdcmdi[1]{longprotectedcdcmdi<#1>} |
| 1034 |
\newconditioncommand\longprotectedcdcmdio[1][DFT]{longprotectedcdcmdio<#1>} |
| 1035 |
\newconditioncommand*\shortprotectedcdcmd{shortprotectedcdcmd} |
| 1036 |
\newconditioncommand*\shortprotectedcdcmdi[1]{shortprotectedcdcmdi<#1>} |
| 1037 |
\newconditioncommand*\shortprotectedcdcmdio[1][DFT]{shortprotectedcdcmdio<#1>} |
| 1038 |
|
| 1039 |
{\ttfamily\setcondition{paper={a4,a5}}\obeylines |
| 1040 |
\longprotectedcdcmd{*} |
| 1041 |
\longprotectedcdcmdi{*}{1\par arg} |
| 1042 |
\longprotectedcdcmdio{*} |
| 1043 |
\longprotectedcdcmdio{*}[1opt] |
| 1044 |
\longprotectedcdcmdio{paper=a4}[1opt a4] |
| 1045 |
\longprotectedcdcmdio+{paper={a4,a7}}[1opt a4a7] |
| 1046 |
\shortprotectedcdcmd{*} |
| 1047 |
\shortprotectedcdcmdi{*}{1arg} |
| 1048 |
\shortprotectedcdcmdio{*} |
| 1049 |
\shortprotectedcdcmdio{*}[1opt] |
| 1050 |
\shortprotectedcdcmdio{paper=a4}[1opt a4] |
| 1051 |
\shortprotectedcdcmdio+{paper={a4,a7}}[1opt a4a7] |
| 1052 |
} |
| 1053 |
%</test> |