I am trying to shorten down on writing math with variables, and therefore one of the steps needed is to split the equation string at the first = sign and put a & sign in front of it for alignment. This works great except for when I put the actual ampersand in before the second part of the string. It works with the ampersand if I manually add the second string. See my example, with the commented-out code. How do I make sense of this?
\documentclass[11pt]{article}
\usepackage{xstring,amsmath}
\newcommand{\splitEquals}[1]{%
\StrCut{#1}{=}{\macroA}{\macroB}%
%enable only one at a time:
%\macroA&=3+4 %works
%\macroA&=\macroB %doesn't work
\macroA=\macroB %works
}
\begin{document}
%\splitEquals{d=3+4}
\begin{align*}
\splitEquals{d=3+4}
\end{align*}
\end{document}
Edit: The result of splitEquals should be: d&=3+4, which would align it nicely. I do not require any lineending.
&inserted before the&character, or do you also require a line break, or something else altogether? – Mico Dec 18 '15 at 18:45&before the=sign, but it doesn't work when I add the\macroBafter it – Runar Dec 18 '15 at 19:05