Very often, I will have a macro that is one expansion away from a string that I would like to compare against a constant string. Now yes, obviously, I could simply define a macro that expands to the string I want to test against and use \ifx but that is very annoying to have define needless macros. I am also aware that one could use stringstrings or xstring to do this, but it seems unfortunate to have to import packages for something so conceptually simple. Here's an MWE illustrating what I'm referring to
\documentclass{article}
\def\teststring{xyz}
\begin{document}
\expandafter\ifx\expandafter{xyz}\textstring%
TRUE%
\else%
FALSE%
\fi%
\end{document}
This non-working solution is based off the first answer to this question but it does not appear to work in the way the author claims.
\(pdf)strcmp(it's called with different names). – egreg Jun 26 '19 at 15:04ifxin your question is comparing{withxso will always be false (the\expandafterare expandingxwhich is not expandable so do nothing. – David Carlisle Jun 26 '19 at 15:20{xyz}together would get it to be treated as a single token. – junius Jun 26 '19 at 15:23{xyz}is 5 tokens – David Carlisle Jun 26 '19 at 15:24\ifxusing a macro\teststring. – Werner Jun 26 '19 at 15:35