It seem that if macro \IfSubStr from package xstring is used as parameter it is not expanded like other macros are.
Here is minimal demonstration:
\usepackage{xstring}
\newcommand{\copyArg}[1]{#1}
\newcommand{\test}[1]{%
\if#1W
in then%
\else
in else%
\fi
}
\begin{document}
\test{\copyArg{W}}
\test{\IfSubStr{WKS}{W}{W}{N}}
\end{document}
I would expect this to print in then in then. Instead \test{\IfSubStr{WKS}{W}{W}{N}} behaves differently to previous macro and the output is in then in else. Why is that? How can I tweak my code or replace \IfSubStr by another macro so that I get expected result?
Edit
Here I should explain what I need do. There is a macro like the \test macro shown in minimal example above. This macro has optional argument that works like switch - in very similar way it is shown in example above. If optional argument is W some actions are taken, it is unset or anything else then W some other actions are taken. It uses the same \if \else condition that I have used in demo.
I am creating new macro that uses this existing macro. My macro has also first argument optional that may contain number of switches. One of them is that W switch. This switch is to be delegated existing macro. I thought I might code like this in my macro would do the trick \theExistingMacro[\IfSubStr{#1}{W}{W}{}]{...}{...} but it does not work. So how do I make it work?
Edit 2
To clarify here is real life example.
There is a macro like this (simplified code)
\newcommand{\addLabelAbove}[4][]{%
\if#1W%
\saveToNewBox{#2}{\vbox{\noindent#4\\*\noindent#3}}%
\else%
\saveToNewBox{#2}{\pbox{\textwidth}{\noindent#4\\*\noindent#3}}%
\fi%
}%
I am creating new macro that calls different other macros one of which is \addLabelAbove
\newcommand{\block}[6][]{
\uppercase{\IfSubStr{#1}}{A}{%then
\uppercase{\IfSubStr{#1}}{L}{%then
\doSomething{#2}{#3}{#4}{#5}{#6}
}{%else
\stepcounter{BoxCount}%
\addLabelAbove[\IfSubStr{#1}{W}{W}{}]{\theBoxCount}{#2}{#3}%
\someMoreMacrosSkiped
}%
}{%else
\someOtherUnimportantCommands
}%
}
The line \addLabelAbove[\IfSubStr{#1}{W}{W}{}]{\theBoxCount}{#2}{#3}% intends to call macro \addLabelAbove with switch W if there is W among switches given to macro \block or with without that switch if there is no W switch among switches given to \block. It does not work this way and I'd like to know how to make it work.

\ifxwould compare\IfSubStrto{, which is surely not what's wanted. ;-) – egreg Jan 17 at 18:57AWK? And in this case, should the macro take theWbranch? – egreg Jan 17 at 22:46AWK(multiple swithes). But the existing macro that I cannot alter is only expecting one switch - that isW. I'm not sure I understand your second question... The predefined macro (that I cannot alter) should get theWswitch if and only ifWwas one of switches given to macro that I am creating. – drasto Jan 17 at 23:03\addLabelAboveis definitely wrong. If you call\addLabelAbove[aa]{X}{Y}{Z}it will follow the true branch and you'll have aWin the output. And if you call it with an empty optional argument you'll be in big trouble, because the first token of the expansion of\saveToNewBoxwill be eaten up. – egreg Jan 17 at 23:42\addLabelAbovecommand. What should the correct definition look like? – drasto Jan 17 at 23:47