I know three macros that test two fully expanded character strings for equality:
\ifthenelse{\equal{<op1>}{<op2>}}{<true>}{<false>}
(ifthen
package)\IfStrEq{<op1>}{<op2>}{<true>}{<false>}
(xstring
package)\ifstr{<op1>}{<op2>}{<true>}{<false>}
(scrbase
package)
Interestingly, they share one drawback: They are fragile, which means that
- we have to
\protect
them in moving arguments (e.g. in the argument of\section
). - they don’t properly work in the context of PDF string expansion (e.g. for PDF outlines) as implemented by the
hyperref
package.
Minimal example:
\documentclass{article}
\usepackage{xstring}
\usepackage{hyperref}
\newcommand*{\juhu}{%
juhu%
}
\newcommand*{\test}[1]{%
\IfStrEq{#1}{juhu}{Juhu!}{Oje!}%
}
\begin{document}
\tableofcontents
\section{\test{\juhu}}
%% \section{\protect\test{\juhu}}
\end{document}
Hence my question: Is it possible to implement an equality test that fully expands its operands, but removes the restrictions listed above?