siunitx를 사용하여 변수를 단위로 선언하는 방법은 무엇입니까?

siunitx를 사용하여 변수를 단위로 선언하는 방법은 무엇입니까?

천문학에서 허블 상수의 값은 여전히 ​​다소 불확실합니다. 따라서 관례적으로 로 표기하는데 $H = h \SI{100}{\kilo\meter\per\second\per\mega\parsec}$, 여기서는 $h$이제 단위의 일부로 간주됩니다. 길이의 단위는 이며 $h^{-1} \si{\mega\parsec}$, 이를 로 조판하고 싶습니다 $\si{\per\h\mega\parsec}$. 'h'가 변수처럼 이탤릭체로 조판되도록 라텍스에서 이것을 어떻게 달성합니까? 아래는 최소한의 예입니다.

\documentclass{article}

\usepackage{siunitx}

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


\begin{document}

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

\end{document}

오류가 발생하여 보석금이 발생합니다.

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

?

답변1

나는 천문학에서 단위의 조판에 대해 알지 못하므로 "h"를 어떻게 조판해야 하는지 말할 수 없지만 수학 이탤릭체로 된 "h"는 쉽습니다.

\documentclass{article}

\usepackage{siunitx}

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

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

결과

답변2

텍스트 모드에서 탈출한 다음 수학 모드를 사용하세요.

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}

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

\begin{document}

\unit{\per\h\mega\parsec} \unit[per-mode=fraction]{\per\h\mega\parsec}

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보