I'm trying to define a macro to typeset Eulers complex e-power with or without a minus sign in its argument. I would like the macro to automatically detect if its argument starts with a -
. I have the following MWE which uses and optional argument:
\documentclass[a4paper,12pt,fleqn]{article}
\def\imaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
\def\imunit{\mathrm{\imaginaryunit}} % ... in upright math
\def\ce{\mathrm{e}} % the constant e, upright of course
\makeatletter
\def\epowim{\@ifnextchar[{\epowimi}{\epowimi[]}} % e to-the-power-of imaginary unit
\def\epowimi[#1]#2{\ce^{#1\if\imaginaryunit j\relax\,\fi\imunit#2}} % e to-the-power-of imaginary unit
\makeatother
\begin{document}
\begin{equation}
\epowim{\alpha}\qquad \epowim[-]{\alpha} \qquad \ce^{-\imunit\alpha}
\end{equation}
\end{document}
So I would like a macro that detects if its argument starts with a -
:
\epowim{-\alpha}
should detect the -
and place it before the imaginary unit instead of placing it after the imaginary unit.
So the question is if it can be done and how.