1

I don't understand how \IfStrEq from xstring works.

Why this code doesn't show "This is text" ?

\documentclass[10pt,a4paper,twoside]{article}
\usepackage{xparse}
\usepackage{xstring}
    
\DeclareDocumentCommand \field {} {text}
    
\begin{document}
  \IfStrEq{\field}{text}{This is text}{Why this is not text?}
\end{document}
5
  • But the manual says "The command \fullexpandarg is called by default, so all the arguments are fully expanded" Mar 15, 2021 at 11:29
  • 1
    But \field is defined with \DeclareDocumentCommand and so is very non-expandable. Try with \newcommand\field{text}. Mar 15, 2021 at 11:35
  • without xparse you are seeing the effect of \protected\def\field{text} and text Mar 15, 2021 at 11:39
  • ok, this is because \field is protected (normal behavior of \DeclareDocumentCommand) using \def solves the problem. Thank you very much David and Ulrike Mar 15, 2021 at 11:47
  • \field is not a string, but something eventually printing text. Using \IfStrEq is wrong.
    – egreg
    Mar 15, 2021 at 13:19

1 Answer 1

1

This is because \field is protected (normal behavior of \DeclareDocumentCommand). Using \def solves the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .