I am using a \protected\def as that solved an earlier issue of mine. I need to compare this value of the token to see if it is initialized to the same value as the \protected\def in different ways.
The MWE below checks the cases I need.
I really would prefer to not make any changes to how the variables are declared, but rather define a custom version of \MyIfStrEq to perform the comparison as required.
Notes:
- The MWE below yields the correct results if I simply remove
\protected, but I need to use the\protectedin another case as per the referenced question below. - I normally would not use magical text such as "special" beyond the premable, but in this case the text I need to compare to is coming from the file system.
References:
Code:
\documentclass{article}
\usepackage{xstring}
\usepackage{xparse}
\NewDocumentCommand{\MyIfStrEq}{m m m m}
{%
\IfStrEq{#1}{#2}{#3}{#4}%
}
%\NewDocumentCommand{\MyIfStrEq}{m m m m}
% {%
% \ifx#1#2%
% #3%
% \else%
% #4%
% \fi%
% }
%% -------------------------------------------------------------
%% Would prefer to NOT change code from here to \begin{document}
\protected\def\SpecialValue{special}
\newtoks{\MyToken}
\MyToken={\SpecialValue}
%% -------------------------------------------------------------
\begin{document}
\MyIfStrEq{\SpecialValue}{special}{Pass 1}{Fail 1}%
\MyIfStrEq{\the\MyToken}{special}{Pass 2}{Fail 2}%
\MyIfStrEq{\the\MyToken}{\SpecialValue}{Pass 3}{Fail 3}%
\end{document}
\MyToken={\SpecialValue}stores '\SpecialValue' in\MyToken. The most 'obvious' solution to me is to do\MyToken=\expandafter{\SpecialValue}, i.e. to expand the marker exactly once before assignment. However, I'm not clear that this is allowed. Are we permitted to make assumptions abut the input, for example that the second argument to\MyIfStrEqmay be either a literal or a macro which may be expanded exactly once? – Joseph Wright May 15 '13 at 06:04\MyTokenbut anything that is localized to\MyStrEqwould be fine. The second parameter will be a value of a\deffrom a modified version ofGetShellOutputfrom Specify file name shell access via @@input. If it makes a difference I can add that to the MWE. – Peter Grill May 15 '13 at 06:34