I want to expand a macro argument into a string, remove all the spaces, then append and prepend the string inside a \NewDocumentCommand macro definition.
Here's my MWE using LuaLaTeX.
\documentclass[oneside,DIV=12]{scrbook}
\usepackage{scrhack}
\usepackage{mathtools, amssymb}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
\setmathfont{Latin Modern Math}
\usepackage{xparse}
\usepackage{xpatch}
% \ExpandArg (https://tex.stackexchange.com/a/515425)
\ExplSyntaxOn
\cs_new_protected:Nn \__user_expand_arg:n
{
\tl_set:No \ProcessedArgument { #1 }
}
\cs_set_eq:NN \ExpandArg \__user_expand_arg:n
\ExplSyntaxOff
% \RemoveSpaces (https://tex.stackexchange.com/a/87510)
\makeatletter
\def\RemoveSpaces#1{\zap@space#1 \@empty}
\makeatother
% \foo, \foobar, and \xy
\NewDocumentCommand{\foo}{>{\ExpandArg} m}{%
\renewcommand{\foobar}{+\RemoveSpaces{#1}.}
\xpatchcmd{\foobar}{+x-y.}{++xx--yy..}{}{} % check if there's a '+x-y.' w/o any spaces, then replace it with '++xx--yy..'
\foobar % print the output
}
\newcommand{\foobar}{}
\newcommand{\xy}{ x - y }
\begin{document}\KOMAoptions{DIV=current}\Large%
\[\foo{\xy}\] % if all the spaces are removed, it should print the output as '++xx--yy..' and not '+x-y.'
\end{document}
Why does this not work? I think the problem might be that I don't really understand how \RemoveSpaces
works.
Thank you.