[Tex/LaTex] How to declare a variable as a unit with siunitx

siunitx

In astronomy the value of the Hubble constant is still somewhat uncertain. Therefore, it is customarily written as $H = h \SI{100}{\kilo\meter\per\second\per\mega\parsec}$, where $h$ is now considered part of the unit. The unit for length is $h^{-1} \si{\mega\parsec}$, which I want to typeset as $\si{\per\h\mega\parsec}$. How do I achieve this in latex so that 'h' is typeset in italics like a variable? Below is a minimal example.

\documentclass{article}

\usepackage{siunitx}

\DeclareSIUnit \h {$h$}
\DeclareSIUnit \parsec {pc}


\begin{document}

\si{\per\h\mega\parsec}

\end{document}

This bails with an error:

! Missing } inserted.
<inserted text> 
            }
l.11 \si{\per\h\mega\parsec}

?

Best Answer

I do not know about the typesetting of units in the astronomy, thus I cannot say, how the "h" should be typeset, but an "h" in math italics is easy:

\documentclass{article}

\usepackage{siunitx}

\DeclareSIUnit \h {\ensuremath{\mathit{h}}}
\DeclareSIUnit \parsec {pc}

\begin{document}
  \si{\per\h\mega\parsec} 
\end{document}

Result