I am trying to create an easier way to write math-formulas in tex for multiple assignments. At the current time, I am almost there. This example might not seem very intuitive, but I had to leave out a great deal to make it small enough.
What I am trying to accomplish in this example, is simply some string replacement. For every occurrence of string defined in \allvars, replace them with whatever \varprint{string for \allvars} outputs. However, I have messed up the expansion here, and have tried a few other ways, but I just don't quite understand really. The string-replacement works as expected, but I need StrSubstitute to rerun with its own output on the next index in allvars. Any help on this is greatly appreciated.
\documentclass[11pt]{article}
\usepackage{xinttools, xstring}
\newcommand{\allvars}{sideA,sideB,sideC}
\newcommand{\varPrint}[1]{%
great(#1)
} % just a command used in this example. in real document, a more advanced output is to be expected from this.
\newcommand{\matte}[1]{%
\edef\mattetempB{#1}
\xintFor ##1 in {\allvars}\do%
{\def\mattetempB{%
\StrSubstitute{\mattetempB}{##1}%
{\varPrint{##1}}%
}%
}%
\mattetemp
}%
\begin{document}
\matte{sideA+sideB=sideC},\\
Would like to see something like the following:\\
great(sideA)+great(sideB)=great(sideC)\\
But only sees:\\
sideA+sideB=great(sideC) ,
\end{document}
\StrSubstitute
definitely doesn't work in\edef
.\StrSubstitute
, you'll need to use the optional output parameter; something like\StrSubstitute{}{}{}[\OutputMacro]
. Then afterwards you can use\def\mattetemp{\OutputMacro}
.