[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:

\documentclass{minimal}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}

% align by adding phantom text and moving the entire block left
\newcommand{\isotope}[3]{%
\newbox\aweight% atomic weight
\setbox\aweight=\hbox{#1}%
\newbox\anumber% atomic number
\setbox\anumber=\hbox{#2}%
% 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%
\mbox{$^{\hphantom{#2}#1}_{\hphantom{#1}#2}$}${#3}$}}

% and of course we need a simple test text for this macro
\begin{document}
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...
\end{document}

(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
nihongoresources.com


More information about the XeTeX mailing list