%%
%% This is file `realscripts.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% realscripts.dtx  (with options: `package')
%%   ____________________________
%%   The REALSCRIPTS package
%%   (C) 2010 Will Robertson
%%   License information appended
%% 
\ProvidesPackage{realscripts}
  [2010/09/30 v0.3 Access OpenType subscripts and superscripts]
\RequirePackage{fontspec}
\ExplSyntaxOn
\DeclareDocumentCommand \fakesubscript {m} {
  \@textsubscript{\selectfont#1}
}
\DeclareDocumentCommand \fakesuperscript {m} {
  \@textsuperscript{\selectfont#1}
}
\RenewDocumentCommand \textsubscript {s} {
    \IfBooleanTF #1 \fakesubscript \realsubscript
}
\RenewDocumentCommand \textsuperscript {s} {
    \IfBooleanTF #1 \fakesuperscript \realsuperscript
}
\DeclareDocumentCommand \realsubscript {m} {
  \fontspec_if_fontspec_font:TF {
    \fontspec_if_opentype:TF
    { \fontspec_if_feature:nTF {+subs}
        { {\addfontfeature{VerticalPosition=Inferior}#1} }
        { \fontspec_if_feature:nTF {+sinf}
            { {\addfontfeature{VerticalPosition=ScientificInferior}#1} }
            { \fakesubscript{#1} }
        }
    }
    { \fontspec_if_aat_feature:nnTF {10} {2}
        { {\addfontfeature{VerticalPosition=Inferior}#1} }
        { \fakesubscript{#1} }
    }
  }
  { \fakesubscript{#1} }
}
\DeclareDocumentCommand \realsuperscript {m} {
  \fontspec_if_fontspec_font:TF
  {
    \fontspec_if_opentype:TF
    { \fontspec_if_feature:nTF {+sups}
      { {\addfontfeature{VerticalPosition=Superior}#1} }
      { \fakesuperscript{#1} }
    }
    { \fontspec_if_aat_feature:nnTF {10} {1}
      { {\addfontfeature{VerticalPosition=Superior}#1} }
      { \fakesuperscript{#1} }
    }
  }
  { \fakesuperscript{#1} }
}
\cs_set:Npn \@makefnmark {
  \mbox{\footnotemarkfont\textsuperscript{\@thefnmark}}
}
\cs_if_exist:NTF \ftntm@font
{
  \cs_new:Npn \footnotemarkfont {\ftntm@font}
}
{
  \cs_new:Npn \footnotemarkfont {\normalfont}
}
\DeclareDocumentCommand \textsubsuperscript {s O{l} mm} {
  \group_begin:
  \IfBooleanTF #1
  {
    \hbox_set:Nn \l_tmpa_box {\textsubscript*{#3}}
    \hbox_set:Nn \l_tmpb_box {\textsuperscript*{#4}}
  }
  {
    \hbox_set:Nn \l_tmpa_box {\textsubscript{#3}}
    \hbox_set:Nn \l_tmpb_box {\textsuperscript{#4}}
  }
  \hbox_set:Nn \l_tmpa_box
    { \box_move_down:nn \subsupersep {\box_use:N \l_tmpa_box} }
  \hbox_set:Nn \l_tmpb_box
    { \box_move_up:nn \subsupersep {\box_use:N \l_tmpb_box} }
  \prg_case_str:nnn {#2}
  {
    {l}{\use_i:nnn}
    {c}{\use_ii:nnn}
    {r}{\use_iii:nnn}
  }
  {
    \PackageWarning{realscripts}{
      Unknown~alignment~option~`#2'. \MessageBreak
      One~ of~ `l',~ `c',~ `r',~ only
    }
    \use_i:nnn
  }
  {
    \hbox_overlap_right:n { \box_use:N \l_tmpa_box }
    \hbox_overlap_right:n { \box_use:N \l_tmpb_box }
    \skip_horizontal:n {
      \dim_max:nn {\box_wd:N \l_tmpa_box} {\box_wd:N \l_tmpb_box}
    }
  }
  {
    \dim_compare:nTF { \box_wd:N \l_tmpa_box > \box_wd:N \l_tmpb_box }
    {
      \skip_horizontal:n {
        0.5\box_wd:N \l_tmpa_box-0.5\box_wd:N \l_tmpb_box
      }
      \box_use:N \l_tmpb_box
      \skip_horizontal:n {
        -0.5\box_wd:N \l_tmpa_box-0.5\box_wd:N \l_tmpb_box
      }
      \box_use:N \l_tmpa_box
    }
    {
      \skip_horizontal:n {
        0.5\box_wd:N \l_tmpb_box-0.5\box_wd:N \l_tmpa_box
      }
      \box_use:N \l_tmpa_box
      \skip_horizontal:n {
        -0.5\box_wd:N \l_tmpb_box-0.5\box_wd:N \l_tmpa_box
      }
      \box_use:N \l_tmpb_box
    }
  }
  {
    \skip_horizontal:n {
      \dim_max:nn {\box_wd:N \l_tmpa_box} {\box_wd:N \l_tmpb_box}
    }
    \hbox_overlap_left:n { \box_use:N \l_tmpa_box }
    \hbox_overlap_left:n { \box_use:N \l_tmpb_box }
  }
  \group_end:
}
\DeclareDocumentCommand \textsupersubscript {s O{l} mm} {
  \textsubsuperscript #1 [#2] {#3} {#2}
}
\dim_new:N \subsupersep
\cs_set:Nn \dim_max:nn {
  \dim_compare:nTF {#1>#2} {#1} {#2}
}
\cs_set:Nn \dim_min:nn {
  \dim_compare:nTF {#2>#1} {#1} {#2}
}
%% 
%% Copyright (C) 2010 by Will Robertson <will.robertson@latex-project.org>
%% 
%% Distributable under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status)
%% by Will Robertson.
%% 
%% This work consists of the file  realscripts.dtx
%%           and the derived files realscripts.sty,
%%                                 realscripts.ins, and
%%                                 realscripts.pdf.
%% 
%%
%% End of file `realscripts.sty'.
