Astrophysical notation : typeset HI

Use the size of subscripts linked to the current font size.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\DeclareRobustCommand{\HI}{%
  \mbox{H\check@mathfonts\fontsize\sf@size\z@\selectfont I}%
}
\makeatother

\textheight=3cm % just to shorten the image

\begin{document}

\section{About \HI}

Here we talk about \HI.\footnote{Yes, about \HI.}

\end{document}

enter image description here

The kernel command \check@mathfonts computes \sf@size and \ssf@size starting from the current font size, either with the parameters stored with \DeclareMathSizes or with a heuristic otherwise.


Adjust 1.2ex to suit.

\documentclass{article}
\usepackage{scalerel}
\newcommand\HI{H\protect\scaleto{$I$}{1.2ex}}
\begin{document}
\tableofcontents

\section{This is \HI}

And in text: \HI{} and \LARGE \HI
\end{document}

enter image description here

Because scalerel operates, by default, in math mode, the $I$ is actually an escape out of math mode. If that is too confusing, you could always just operate in math mode as: \newcommand\HI{H\protect\scaleto{\textrm{I}}{1.2ex}}


If you wanted a version without packages, you could do this, but it requires a separate macro for bold style:

\documentclass{article}
\newcommand\HI{$\textrm{H}\scriptstyle\mathrm{I}$}
\newcommand\HIbold{$\textbf{H}\scriptstyle\mathbf{I}$}
\begin{document}
\tableofcontents

\section{This is \HIbold}

And in text: \HI{} and \LARGE \HI
\end{document}

enter image description here


Another way to do it is the way it is implemented by the Astronomy & Astrophysics class.

Add this declaration to the header :

\DeclareRobustCommand{\ion}[2]{%
\relax\ifmmode
\ifx\testbx\f@series
{\mathbf{#1\,\mathsc{#2}}}\else
{\mathrm{#1\,\mathsc{#2}}}\fi
\else\textup{#1\,{\mdseries\textsc{#2}}}%
\fi}

Then in the body of the document, use

\ion{H}{I}