In the following example,
\documentclass{article}
\usepackage{xstring}
\newcommand\foo[1]{\StrSubstitute{#1}{love}{hate}}
\begin{document}
\section*{\foo{I love Mondays}}
\end{document}
if I remove the * from \section* the code stops compiling.
- What is the trick that makes
\section*work ok with\StrSubstitutebut not\section? - Is there a workaround to include the command
\fooin a\sectionheader too?
\section*doesn't create a table of contents entry, that's why id doesn't expand\foowriting it to the .toc file which causes the problem. You can make it robust by\DeclareRobustCommand. I'll edit my answer to add that. – Stefan Kottwitz Jan 19 '11 at 21:09