[Tex/LaTex] Defining a new unit in siunitx that has a subscript

siunitx

I would like to define a new unit, analogous to \electronmass, in the siunitx package but this time for the proton mass. So I just copy/pasted the definition of \electronmass from the style file and modified it. See MWE below.

\documentclass{article}

\usepackage{siunitx}


\DeclareSIUnit[]\protonmass
{ \text { \ensuremath { m _ { \textup { p } } } } }

\begin{document}

electron mass = \si{\electronmass}

proton mass = \si{\protonmass}

\end{document}

If I look at the output, there is a small space between the 'm' and the 'p'. enter image description here.

How should I define the \protonmass unit so that the space is gone?

Best Answer

Remove the spaces from the definition. The reason why the space doesn't occur for \electronmass is I'd think that siunitx is an expl3 package, and in the environment defined by expl3 spaces in the input are all ignored. Your new definition is not written in that environment.

\documentclass{article}

\usepackage{siunitx}


\DeclareSIUnit[]\protonmass
{\text{\ensuremath{m_{\textup{p}}}}}

\begin{document}

electron mass = \si{\electronmass}

proton mass = \si{\protonmass}

\end{document}

Here's the output.

enter image description here

Related Question