# Why is \str_if_eq_p:nn not evaluating to true?

In the following MWE, \str_if_eq_p:nn is not evaluating to true when \l_aepoly_presentation_style_tl is set to ABC. Why?

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_aepoly_presentation_style_tl
\NewDocumentCommand{\mqpoly}{ D(){ABC} m }
{\aepoly_parse_polynomial:nn {#1} {#2} }
\cs_new:Npn \aepoly_parse_polynomial:nn #1#2 {
\tl_set:Nn \l_aepoly_presentation_style_tl {#1}
\bool_if:nTF {
%% other possible boolean expressions to evaluate
\str_if_eq_p:nn { \tl_to_str:N \l_aepoly_presentation_style_tl } { ABC }
}
{ \iow_term:n { string ~ is ~ "ABC" } }
{ \iow_term:x { NOT ~ EQUAL -> ~ "\l_aepoly_presentation_style_tl" } }
}

\ExplSyntaxOff
\pagestyle{empty}
\begin{document}

\mqpoly(MNP){hello}

\mqpoly{hello}

\end{document}

-
Ah ha! I need to be using \str_if_eq_x_p:nn to get the expansion of the token list. –  A.Ellett Mar 29 '14 at 5:31
I guess then either a self-answer or delete –  Joseph Wright Mar 29 '14 at 6:59
Or \str_if_eq_p:Vn \l_aepoly_..._tl {ABC} (after defining the variant). –  egreg Mar 29 '14 at 9:17

You have two workarounds:

1. use \str_if_eq_x_p:nn in order to force full expansion
2. use \str_if_eq_p:Vn in order to access the value of the token list variable

Which one is just a matter of preferences, but I'd go with the second, because it avoids expansion in the second argument.

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\NewDocumentCommand{\mqpoly}{ D(){ABC} m }
{\aepoly_parse_polynomial:nn {#1} {#2} }

\tl_new:N \l_aepoly_presentation_style_tl

\cs_new_protected:Npn \aepoly_parse_polynomial:nn #1#2
{
\tl_set:Nn \l_aepoly_presentation_style_tl {#1}
\bool_if:nTF
{
%% other possible boolean expressions to evaluate
\str_if_eq_p:Vn \l_aepoly_presentation_style_tl { ABC }
}
{ \iow_term:n { string ~ is ~ "ABC" } }
{ \iow_term:x { NOT ~ EQUAL ~ -> ~ "\l_aepoly_presentation_style_tl" } }
}

\ExplSyntaxOff

\pagestyle{empty}

\begin{document}

\mqpoly(MNP){hello}

\mqpoly{hello}

\end{document}


Don't forget to use \cs_new_protected:Npn, as you're doing an assignment in the function.

The output is

NOT EQUAL -> "MNP"
string is "ABC"

-
I'm not sure I understand you're recommendation to use \cs_new_protected:Npn. Are assignments not expandable? –  A.Ellett Mar 29 '14 at 14:10
@A.Ellett Right so: assignments are the main cause for misfunction of \edef. This macro is, of course, a stripped down version of something more complex; in the present function, the assignment is redundant, as you can directly pass #1 to \str_if_eq_p:nn. –  egreg Mar 29 '14 at 14:21
@A.Ellett I can't see it. –  egreg Mar 29 '14 at 16:20