3

This must be a really dumb question, but what am i doing wrong here? As far as I can see, the strings are equal, so the test should be successful, instead i get not successful.

\documentclass{article}

\ExplSyntaxOn

\str_new:N \g_test_str

\NewDocumentCommand{\Test}{m}
 {
  \str_set:Nn \g_test_str { #1 }
  
  \noindent
  Input is #1 \newline
  String is \g_test_str \newline
  \str_if_eq:nnTF { \g_test_str }{test}{test successful}{test not successful}
 }
 
 \ExplSyntaxOff

 \begin{document}
 
 \Test{test}
 
 \end{document}

Thanks for any help

7

You need the V variant to receive the contents of a variable:

\documentclass{article}

\ExplSyntaxOn

\str_new:N \l_test_str

\NewDocumentCommand {\Test} {m} {
  \str_set:Nn \l_test_str {#1}
  \noindent
  Input~ is~ #1 \newline
  String~ is~ \l_test_str \newline
  \str_if_eq:VnTF \l_test_str {test} {test~ successful} {test~ not~ successful}
}
\ExplSyntaxOff

\begin{document}
 
\Test{test}
 
\end{document}

enter image description here

Otherwise the unexpanded strings “\l_test_str” and “test” are compared which are not equal.

I also renamed your variable as it is a local one here and not a global one.

1
  • Thank you very much.
    – Stephen
    Jan 31 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.