[XeTeX] vertically aligned sub and superscript

Alan Munn amunn at msu.edu
Thu Jul 26 21:18:03 CEST 2007


At 8:10 PM +0200 7/26/07, Manuel Souto Pico wrote:
>
>
>I was surprised to see that, if I compile the file using those five 
>lines and nothing else, I can get aligned scripts by simply typing 
>$x^a_b$. However, in my document, this is not so.
>
>So I run a few tests and it seems there's an incompatibility with 
>the package gb4e, which is used for glosses and examples in 
>linguistics. If I remove it, the scripts a and b are aligned in 
>$x^a_b$.
>

Hi Manuel, in the thread that you mentioned I posted some code from 
Alexis Dimitriadis which solves this problem.  Here it is again. 
After loading gb4e etc., put the following in your preamble.  Now the 
super/subscripts should align properly inside examples.  -Alan


\makeatletter
%% Activate super- and sub-scripts outside of math mode.

% \automath make _, ^ work outside math mode
% \noautomath restore normal sub/superscript behavior

{ % Temporarily change catcodes
   \catcode`\_=\active
   \catcode`\^=\active

   \global\def\automath{%
     \catcode`\_=\active
     \catcode`\^=\active
     \def_##1{\@ifnextchar^{\automath at two_{##1}}{\ensuremath{\sb{##1}}}}%
     \def^##1{\@ifnextchar_{\automath at two^{##1}}{\ensuremath{\sp{##1}}}}%
   }
   \def\automath at two#1#2#3#4{\ensuremath{#1{#2}\relax #3{#4}}
}
% Restore default categories for ^, _
\def\noautomath{\catcode`\_=8 \catcode`\^=7 }

% Turn the feature on by default
\automath

\makeatother

-- 
Alan Munn 
amunn at msu.edu
Department of Linguistics                             
and Germanic, Slavic, Asian and African Languages   Fax.  +1-517-432-2736
Michigan State University, East Lansing MI 48824       Tel.  +1-517-355-7491


More information about the XeTeX mailing list