# Validating command with in command

I have planed to create SIunits based macro to support SIunits package in my XML conversion process.

In this process i have found few issues while handing the \per command i have tried the following

\documentclass{book}

\def\cubed{\ifx N\cbicperon\ensuremath{^3}\fi\let\cbicperon=Y}%
\def\cubic{\ifx N\cbicperon\ensuremath{^3}\fi\let\cbicperon=Y}%
\def\per{\let\peron=Y}%
\def\placesupscript{\ifx Y\cbicperon\ensuremath{^{-3}}\else\ifx Y\sqperon\ensuremath{^{-2}}\else\ifx Y\peron\ensuremath{^{-1}}\fi\fi\fi\let\peron=N\let\cbicperon=N\let\sqperon=N}%
\def\meter{\textrm{m}\placesupscript}%
\def\kelvin{\textrm{K}\placesupscript}%
\def\mole{\textrm{mol}\placesupscript}%
\def\kilo{\textrm{k}}%
\def\gram{\textrm{g}\placesupscript}%
\def\joule{\textrm{J}\placesupscript}%

\begin{document}

$v_{1}=\frac{RT_{1}}{p_{1}}=\SI{0,7876}{\metre\cubed\per\kilo\gram}$

$\rho=\SI{1000}{\kilo\gram\cubic\metre\mole\per\metre\cubed}$

$c_{p}=\SI{4,18}{\kilo\joule\per\kilogram\per\cubic\kelvin\joule}$

$\dot{m}_{\text{total}}=\SI{20e3}{\kilo\gram\per\second}$

$\SI{20}{\metre\per\second}$

\end{document}


any idea for handing such instance? required output is attached

• What are all these commands for? Do you want to reimplement siunitx? And what exactly is your issue? – TeXnician May 22 at 5:55
• yes i want the re-implement in the SIunitx. without using the package – Saravanan.O May 22 at 5:56
• @Saravanan.O The unit processor in siunitx is several hundred lines of code: I'm guessing you don't want to do all of that. Could you elaborate on what your wider aim is: I have a feeling this is an 'xy' question. – Joseph Wright May 22 at 6:43
• In siunitx, I collect up all of the information about units and their superscripts, etc., before creating the output in a second step. You could take the same code and alter the output approach if you want to make XML. Although it's not yet finalised, I'd look at the v3 code here: the unit processor is pretty similar to v2 but a lot clearer. – Joseph Wright May 22 at 6:49
• github.com/josephwright/siunitx/blob/master/siunitx-unit.dtx extracts to around 1000 lines. If you don't want all the fancy stuff you could cut that down, but really you are going to struggle in half a dozen lines to cover the same ideas. For superscripts, you have to apply them after the end of the unit, so at the start of the next unit or at the very end of the input. – Joseph Wright May 22 at 7:40