[XeTeX] Combined sub- and superscript

Michiel Kamermans pomax at nihongoresources.com
Sat Aug 7 22:45:18 CEST 2010

Since this has to do with the box alignment of sub/super script, I'm 
fairly certain this has nothing to do with fontspec at all. Instead, 
let's just write our own macro for isotopes:

\setmainfont{Linux Libertine O}

% align by adding phantom text and moving the entire block left
\newbox\aweight% atomic weight
\newbox\anumber% atomic number
% write isotope with phantom weight in number, and phantom number in weight,
% moved left by whichever is the least wide
{\ifdim \the\wd\aweight>\the\wd\anumber \hskip-\the\wd\anumber \fi%
\ifdim \the\wd\aweight<\the\wd\anumber \hskip-\the\wd\aweight \fi%
\ifdim \the\wd\aweight=\the\wd\anumber \hskip-\the\wd\anumber \fi%

% and of course we need a simple test text for this macro
Let's look at our standard mildly radioactive \isotope{14}{6}{C} 
isotope, and figure out where it goes. We could use something like 
\isotope{228}{88}{Ra} but that would be overkill...

(there might be a more efficient way to do the dimension comparison, but 
if there's one TeX topic that you're never going to find a normal, 
simple explanation page for using google, it's working with plain box 
dimensions and mathematical operations on dimensions for things like 
if/then. It's all infuriatingly hidden in the TeX book and TeX by Topic, 
and the minds of a handful of really good TeX/LaTeX/XeTeX package authors)

- Mike "Pomax" Kamermans

More information about the XeTeX mailing list