5

What would the best way to typeset HI to designate molecular gas as in the title of this article, with a capital H and a slightly smaller numeral I ? I am using the scrbook class.

I tried to define

\newcommand{\HI}{H {\uppercase{\romannumeral 1}} }

but this results in H i, with a lowercase i.

I also tried

\newcommand*{\HI}{\textsc{Hi}}

but this doesn't behave properly when I use it in \section{}, resulting in "H i" rather than "H I".

I also haven't found anything like this in chemmacros, which is more geared towards chemists.


This is a standard way of writing molecules in astrophysics, so I'm surprised there isn't a package that does this easily.

  • it's a tex generated file on arxiv, can't you just download the tex source and see, there is no need to use \uppercase and \romannumeral they would just generate a normal I anyway so you could simply use HI – David Carlisle Mar 8 at 9:24
  • 4
    perhaps \textsc{Hi} – David Carlisle Mar 8 at 9:29
  • 1
    I would not recommand the way it seems in this article... The distance between H and I makes it difficult in reading as one "thing" and possibly the author would try to use another way of defining a command in future edition of this article. @DavidCarlisle's above comment would give a better result I suppose. – koleygr Mar 8 at 9:42
  • 2
    The article you linked to uses H\,{\footnotesize I} - however I don't think this is the best way to go (you can download the tex source of the article from arxiv.org/format/1608.02601) – user36296 Mar 11 at 10:55
  • 2
    Personally I would use the \ion macro from the "Astronomy & Astrophysics" journal class: fits.gsfc.nasa.gov/standard30/aa.cls – user36296 Mar 11 at 12:55
8
+50

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.

  • The spacing is off when HI is in the middle of a sentence. \HI is cool ends up in the document as HIis cool. – usernumber Jun 5 at 17:27
  • @usernumber That's a well known fact; just add {} at the end: \HI{}. It is discussed in tex.stackexchange.com/q/31091/4427, but adding {} is the most effective way, notwithstanding what others suggest. – egreg Jun 5 at 17:29
4

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

1

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.