1

I am using a self defined command to typeset isotopes with charges. It is as follows:

\newcommand{\elem}[3]{\ensuremath{{\vphantom{#2}}#1\mathrm{#2}#3}}

Example:

\elem{^{16}_{8}}{O}{^{2-}_{2}}

What I would like to achieve, is that the sub- and superscript on the left side are aligned to the O. The right sub- and superscript are of course aligned to the O by default. Does anyone have a (preferrably simple) solution?

Enno
  • 606

1 Answers1

1

I have tried the following code:

\def\elem#1#2#3#4#5{{%
   \phantom{{}^{#2}_{#3}}% space for left indexes
   {\vphantom{\rm#1}}^{\llapscr{#2}}_{\llapscr{#3}}% llaped left indexes
   {\rm#1}^{#4}_{#5}% base + right indexes
}}
\def\llapscr#1{\llap{$\scriptstyle#1$}}

Test: $ \elem O {16}{8}{2-}{2} $

\bye
wipet
  • 74,238
  • This code works perfectly. As written in the comment above, mhchem also sets the charge a bit more to the right, which is good. But as I did not think of this before asking, so it was not part of the question, I accepted your answer nevertheless. Thank you. – Enno Jun 19 '16 at 21:18