Using MakeLowercase and StrSubstitute together

\MakeLowercase expands its argument to get the string to lowercase, but the string replace you are using does not work by expansion. Here though you don't really need a string replace, just locally make \_ expand to nothing.

\documentclass{article}

\begin{document}

{\renewcommand\_{}\MakeLowercase{AB\_CD}}

\end{document}

Do it in two separate steps:

\documentclass{article}
\usepackage{xstring}

\begin{document}

\StrSubstitute{AB\_CD}{\_}{}[\SUBtemp]\MakeLowercase{\SUBtemp}

\end{document}

enter image description here


With an up-to-date expl3:

\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\cs_new_eq:NN \LowerCase \text_lowercase:n
\ExplSyntaxOff
\usepackage{xstring}
\begin{document}
\StrSubstitute{\LowerCase{AB\_CD}}{\_}{}
\end{document}

This works because \text_lowercase:n in expl3 does not use \lowercase and so is expandable (contrast with the comment on egreg's answer).

Tags:

Macros

Xstring