I wish to have a dedicated command for printing physical dimension. Something like \phydimen{M2L-3T-1}. This should output the same as $\textrm{M}^2\textrm{L}^{-3}\textrm{T}^{-1}$.
I find that the \ce command of mhchem package is quite suitable. So I hack it to do \newcommand{\phydimen}[1]{\ce{#1}} and then issue a command \phydimen{ML^2T^{-2}} to print the dimension. However I still have to use the pesky ^ and { }. The default \ce behavior is to push the numbers as subscript.
I want \phydimen to automatically detect when a (positive or negative) integer is in the argument and push it to "power". Also \phydimen should be able to accept more characters than M,L,T. Also if lowercase is supplied, it should automatically convert it to uppercase.
How do I parse the arguments character by character and decide whether it is a letter or positive integer or negative integer?
MWE:
\documentclass{article} \usepackage{mhchem} \newcommand{\phydimen}[1]{\ce{#1}} \begin{document} $\textrm{M}^2\textrm{L}^{-3}\textrm{T}^{-1}$ \phydimen{ML^2T^{-2}} % instead I want \phydimen{ML2T-2} \end{document} 
