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 '13 at 18:57AWK? And in this case, should the macro take theWbranch? – egreg Jan 17 '13 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. – Rasto Jan 17 '13 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 '13 at 23:42\addLabelAbovecommand. What should the correct definition look like? – Rasto Jan 17 '13 at 23:47\addLabelAboveis this: If optional argument is not set then the "else branch" is executed. If optional argument is set and it is stringWthen the "then branch" is executed. If optional argument is set and it contains more then one letter or it does not containWthen the "else branch" is executed. – Rasto Jan 17 '13 at 23:57\addLabelAbovewill not do that. However, the final code in my answer should fix this. – egreg Jan 18 '13 at 00:00\addLabelAboveshould create and save a hbox. Its #2 is name of the box to be saved, #3 argument takes main content of that hbox, while #4 argument is some additional content (label) that is placed one line above the main content. TheWswitch cause resulting hbox to contain nested vbox - which means it will occupy all the page width. Macro\blockcreates and saves many hboxes containg same content but with different layout.\addLabelAbovecreates and saves one of those layouts. User can control which layouts are included... – Rasto Jan 18 '13 at 00:10Wswitch that influences layout created and stored by\addLabelAbovemacro. – Rasto Jan 18 '13 at 00:13