When I write units in math mode, I separate them using \,
eg: $3 \; kg \, m^2$
I want to create a macro that does this for me, so I used xparse
like this:
\usepackage{xparse}
\NewDocumentCommand \units{O{}O{}O{}}{\;#1 \,#2 \,#3}
The problem is that if I only specify one argument, I still get 2 extra spaces because my macro skips the arguments but not the \,
.
What I would like is that my macro skips the extra \,
commands if I only specify 1 or 2 arguments.
siunitx
package. But, in general to accomplish what you want you can either detect that an empty paramater was given and only add the\,
spacing if the paramater is not empty, or switch to using theo
org
paramter type (and then use\IfNoValueTF
to detect missing parameters).