Accoring to Joseph Wright's answer at Optional Parameters in xparse: \IfBooleanTF vs \IfNoValueTF
The
k
-type argument has recently been adjusted: you now wante
-type
Questions:
-
What is the functionality of the new
e
-type argument and how does it differ from the previousk
-type argument? -
The 2016-11-21 version of the xparse documentation does not mention the
k
-type argument at all. Is the plan to leave the earlierk
functionality intact (but deprecated so no documentation) or will it eventually be removed and any usage of that should eliminated? If the plan is for it to be removed, how long will the olderk
-type argument functionality be kept inxparse
.
Code:
Example of the k
-type argument from
Xparse t argument type (underscore with optional parameter). Would be useful to see how this would be modified to use the new e
-type argument.
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\usepackage{xcolor}
\NewDocumentCommand\MyMacro{k_}{%
\IfNoValueTF{#1}{%
\mathbf{A}
}{%
A_{\textcolor{red}{#1}}
}%
}
\begin{document}
With a subscript: $\MyMacro_{\pi}$
Without any subscript: $\MyMacro$
\end{document}
Best Answer
The
k
argument type is not available any longer.There is a big difference between the old
k
and the newe
type. With(here
A
,B
andC
represent any three distinct tokens) the macro will look for any sequence of tokens in the formA{x}B{y}C{z}
, but the order is arbitrary, sowill result in the same token list to be passed in the macro replacement text as
#<n>
. Repeating one of the stated tokens will result in stopping the search for the next, sowill be the same as passing just
A
with argument{x}
and nothing for the other two tokens.The argument is normalized with respect to the order and
#<n>
will represent a sequence of braced token lists, with-NoValue-
for the missing ones. For instancewith the input
will result in showing
The consequence is that you should pass
#1
to another macro for subsequent processing, even if there is only one embellishment prefix token; such a macro must have the required number of mandatory arguments.Note that no braces should surround
#1
in the code for\MyMacro
. This is the normal procedure for “processed arguments”.Update June 2017
The newer versions of
xparse
made a breaking change related to thee
andE
argument types. Nowe<tokens>
returns one argument in the replacement text for each token in<tokens>
, so the code for this case must becomeThe argument(s) will contain
-NoValue-
(testable with\IfNoValueTF
) if the corresponding token is not found.