%%
%% This is file `xfrac.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xfrac.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2004, 2008-2010 by Morten Hoegholm <mh.ctan@gmail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% This Current Maintainer of this work is Morten Hoegholm.
%% 
%% This work consists of the main source file xfrac.dtx
%% and the derived files
%%    xfrac.sty, xfrac.pdf, xfrac.ins, xfrac.drv.
%% 
\RequirePackage{expl3}[2009/08/05]
\ProvidesExplPackage{xfrac}{2010/02/02}{0.3}{Text fractions}
\RequirePackage { amstext , graphicx , l3keys2e , textcomp , xtemplate }
\keys_define:nn { xfrac } {
  cm-recommended .choice:,
  cm-recommended /
    false        .code:n     =
      { \bool_set_true:N \l_xfrac_cm_std_bool },
  cm-recommended /
    true         .code:n     =
      { \bool_set_false:N \l_xfrac_cm_std_bool },
  cm-recommended .default:n  = { true },
  cm-standard    .bool_set:N = \l_xfrac_cm_std_bool
}
\ProcessKeysOptions { xfrac }
\box_new:N \l_xfrac_slash_box
\box_new:N \l_xfrac_tmp_box
\cs_new:Npn \xfrac_tmp:w { }
\dim_new:N \l_xfrac_denominator_bot_sep_dim
\dim_new:N \l_xfrac_numerator_bot_sep_dim
\dim_new:N \l_xfrac_numerator_top_sep_dim
\dim_new:N \l_xfrac_slash_left_sep_dim
\dim_new:N \l_xfrac_slash_right_sep_dim
\tl_new:N \l_xfrac_denominator_font_tl
\tl_new:N \l_xfrac_hscale_tl
\tl_new:N \l_xfrac_numerator_font_tl
\tl_new:N \l_xfrac_phantom_tl
\tl_new:N \l_xfrac_scale_factor_tl
\tl_new:N \l_xfrac_slash_left_msep_tl
\tl_new:N \l_xfrac_slash_right_msep_tl
\tl_new:N \l_xfrac_slash_symbol_tl
\tl_new:N \l_xfrac_slash_symbol_font_tl
\tl_new:N \l_xfrac_vscale_tl
\cs_new_nopar:Npn \xfrac_fontscale:
\cs_new:Npn \xfrac_math:n #1 { }
\cs_new_nopar:Npn \xfrac_denominator_font_change: { }
\cs_new:Npn \xfrac_denominator_format:n #1 { }
\cs_new_nopar:Npn \xfrac_numerator_font_change: { }
\cs_new:Npn \xfrac_numerator_format:n #1 { }
\cs_new_nopar:Npn \xfrac_relscale: { }
\cs_new_nopar:Npn \xfrac_slash_symbol_font_change: { }
\cs_new:Npn \xfrac_slash_symbol_format:n #1 { }
\cs_new:Npn \xfrac_text_or_math:n #1 { }
\DeclareObjectType { xfrac } { 3 }
\DeclareTemplateInterface { xfrac } { text } { 3 } {
  denominator-bot-sep : length     = \c_max_dim           ,
  denominator-font    : tokenlist  = \f@family            ,
  denominator-format  : function 1 = #1                   ,
  h-scale             : tokenlist  = 1                    ,
  math-mode           : choice { false , true }
                                   = false                ,
  numerator-font      : tokenlist  = \f@family            ,
  numerator-format    : function 1 = #1                   ,
  numerator-bot-sep   : length     = \c_max_dim           ,
  numerator-top-sep   : length     = \c_max_dim           ,
  phantom             : tokenlist  = 8                    ,
  scale-factor        : tokenlist  = 0.83333              ,
  scale-relative      : choice { false , true }
                                   = true                 ,
  scaling             : choice { false , true }
                                   = true                 ,
  slash-left-kern     : length     = 0 pt                 ,
  slash-left-mkern    : tokenlist  = -2 mu                ,
  slash-right-kern    : length     = 0 pt                 ,
  slash-right-mkern   : tokenlist  = -1 mu                ,
  slash-symbol        : tokenlist  = \textfractionsolidus ,
  slash-symbol-font   : tokenlist  = \f@family            ,
  slash-symbol-format : function 1 = #1                   ,
  v-scale             : tokenlist  = 1                    ,
}
\DeclareTemplateCode { xfrac } { text } { 3 }
  {
    denominator-bot-sep = \l_xfrac_denominator_bot_sep_dim ,
    denominator-font    = \l_xfrac_denominator_font_tl     ,
    denominator-format  = \xfrac_denominator_format:n      ,
    h-scale             = \l_xfrac_hscale_tl               ,
    math-mode           =
      {
        false = \cs_set_eq:NN \xfrac_math:n \use:n,
        true  = \cs_set_eq:NN \xfrac_math:n \ensuremath
      },
    numerator-font      = \l_xfrac_numerator_font_tl       ,
    numerator-format    = \xfrac_numerator_format:n        ,
    numerator-bot-sep   = \l_xfrac_numerator_bot_sep_dim   ,
    numerator-top-sep   = \l_xfrac_numerator_top_sep_dim   ,
    phantom             = \l_xfrac_phantom_tl              ,
    scale-factor        = \l_xfrac_scale_factor_tl         ,
    scale-relative      =
      {
        false =
          \cs_set_nopar:Npn \xfrac_relscale:
            {
              \dim_eval:n
                {
                    \box_ht:N \l_xfrac_tmp_box
                  + \box_dp:N \l_xfrac_tmp_box
                }
            },
        true  =
          \cs_set_nopar:Npn \xfrac_relscale:
            { \box_ht:N \l_xfrac_slash_box }
      },
    scaling             =
      {
        false = \cs_set_eq:NN \xfrac_fontscale: \prg_do_nothing:,
        true  =
          \cs_set_nopar:Npn \xfrac_fontscale:
            {
              \fontsize { \l_xfrac_scale_factor_tl \xfrac_relscale: }
                { \c_zero_dim }
              \selectfont
            }
      },
    slash-left-kern     = \l_xfrac_slash_left_sep_dim      ,
    slash-left-mkern    = \l_xfrac_slash_left_msep_tl      ,
    slash-right-kern    = \l_xfrac_slash_right_sep_dim     ,
    slash-right-mkern   = \l_xfrac_slash_right_msep_tl     ,
    slash-symbol        = \l_xfrac_slash_symbol_tl         ,
    slash-symbol-font   = \l_xfrac_slash_symbol_font_tl    ,
    slash-symbol-format = \xfrac_slash_symbol_format:n     ,
    v-scale             = \l_xfrac_vscale_tl
  }
  {
    \AssignTemplateKeys
    \mode_if_math:TF
      {
        \cs_set_eq:NN \xfrac_text_or_math:n \text
        \cs_set_nopar:Npx \xfrac_denominator_font_change:
          { \tex_fam:D \l_xfrac_denominator_font_tl }
        \cs_set_nopar:Npx \xfrac_numerator_font_change:
          { \tex_fam:D \l_xfrac_numerator_font_tl }
        \cs_set_nopar:Npx \xfrac_slash_symbol_font_change:
          { \tex_fam:D \l_xfrac_slash_symbol_font_tl }
      }
      {
        \cs_set_eq:NN \xfrac_text_or_math:n \mbox
        \cs_set_nopar:Npn \xfrac_denominator_font_change:
          {
            \fontfamily { \l_xfrac_denominator_font_tl }
            \selectfont
          }
        \cs_set_nopar:Npn \xfrac_numerator_font_change:
          {
            \fontfamily { \l_xfrac_numerator_font_tl }
            \selectfont
          }
        \cs_set_nopar:Npn \xfrac_slash_symbol_font_change:
          {
            \fontfamily { \l_xfrac_slash_symbol_font_tl }
            \selectfont
          }
      }
    \xfrac_text_or_math:n
      {
        \m@th
        \hbox_set:Nn \l_xfrac_tmp_box
          { \xfrac_math:n { \vphantom { ( ) } } }
        \hbox_set:Nn \l_xfrac_slash_box
          {
            \xfrac_math:n
              {
                \xfrac_slash_symbol_format:n
                  {
                    \xfrac_math:n
                      {
                        \xfrac_slash_symbol_font_change:
                        \IfNoValueTF {#2}
                          { \l_xfrac_slash_symbol_tl } {#2}
                      }
                  }
              }
          }
        \cs_set_nopar:Npn \xfrac_tmp:w
          {
            \raisebox
              {
                  \box_ht:N \l_xfrac_slash_box
                - \box_dp:N \l_xfrac_slash_box
                - \height
              }
          }
        \dim_compare:nNnTF
          { \l_xfrac_numerator_top_sep_dim } = { \c_max_dim }
          {
            \dim_compare:nNnF
              { \l_xfrac_numerator_bot_sep_dim } = { \c_max_dim }
              {
                \cs_set_nopar:Npn \xfrac_tmp:w
                  {
                    \raisebox
                      { \dim_use:N \l_xfrac_numerator_bot_sep_dim }
                  }
              }
          }
          {
            \dim_compare:nNnTF
              { \l_xfrac_numerator_bot_sep_dim } = { \c_max_dim }
                {
                  \cs_set_nopar:Npn \xfrac_tmp:w
                    {
                      \raisebox
                        {
                            \box_ht:N \l_xfrac_slash_box
                          - \dim_use:N \l_xfrac_numerator_top_sep_dim
                          - \height
                        }
                    }
                }
                {
                  \msg_error:nn { xfrac }
                    { over-specified-numerator-sep }
                }
          }
        \xfrac_tmp:w
          {
            \xfrac_fontscale:
            \xfrac_numerator_format:n
              {
                \scalebox { \l_xfrac_hscale_tl } [ \l_xfrac_vscale_tl ]
                  {
                    \xfrac_math:n
                      {
                        \xfrac_numerator_font_change:
                        {
                          \vphantom { \l_xfrac_phantom_tl }
                          #1
                        }
                      }
                  }
              }
          }
        \xfrac_math:n
          { % THIS IS JUST WRONG!
            \mode_if_math:TF
              { \tex_mskip:D \l_xfrac_slash_right_msep_tl }
              { \tex_hskip:D \l_xfrac_slash_right_sep_dim }
          }
        \box_use:N \l_xfrac_slash_box
        \xfrac_math:n
          {
            \mode_if_math:TF
              { \tex_mskip:D \l_xfrac_slash_left_msep_tl }
              { \tex_hskip:D \l_xfrac_slash_left_sep_dim }
          }
        \dim_compare:nNnTF
          { \l_xfrac_denominator_bot_sep_dim } = { \c_max_dim }
          {
            \cs_set_nopar:Npn \xfrac_tmp:w
              { \raisebox { - \box_dp:N \l_xfrac_slash_box } }
          }
          {
            \cs_set_nopar:Npn \xfrac_tmp:w
              {
                \raisebox
                  { \dim_use:N \l_xfrac_denominator_bot_sep_dim }
              }
          }
        \xfrac_tmp:w
          {
            \xfrac_fontscale:
            \xfrac_denominator_format:n
              {
                \scalebox { \l_xfrac_hscale_tl } [ \l_xfrac_vscale_tl ]
                  {
                    \xfrac_math:n
                      {
                        \xfrac_denominator_font_change:
                        {
                          \vphantom { \l_xfrac_phantom_tl }
                          #3
                        }
                      }
                  }
              }
          }
      }
  }
\DeclareRestrictedTemplate { xfrac } { text } { math } {
  numerator-font      = \number \fam ,
  slash-symbol        = /            ,
  slash-symbol-font   = \number \fam ,
  denominator-font    = \number \fam ,
  scale-factor        = 0.7          ,
  scale-relative      = false        ,
  scaling             = true         ,
  numerator-top-sep   = 0 pt         ,
  denominator-bot-sep = 0 pt         ,
  math-mode           = true         ,
  phantom             = (
}
\DeclareInstance { xfrac } { default } { text } { }
\DeclareInstance { xfrac } { mathdefault } { math } { }
\DeclareCollectionInstance { plainmath } { xfrac } { mathdefault }
  { math }{
  denominator-bot-sep = 0 pt       ,
  numerator-bot-sep   = 0 pt       ,
  numerator-top-sep   = \c_max_dim ,
  scale-factor        = 1          ,
  scale-relative      = false      ,
  scaling             = true       ,
  slash-right-mkern   = 0mu        ,
  slash-left-mkern    = 0mu
}
\DeclareInstance { xfrac } { cmr } { text } {
  denominator-bot-sep = 0 pt    ,
  numerator-top-sep   = 0.2 ex  ,
  slash-left-kern     = -0.1 em ,
  slash-right-kern    = -0.1 em
}
\DeclareInstance { xfrac } { cmss } { text } {
  denominator-bot-sep = 0 pt    ,
  numerator-top-sep   = 0.2 ex  ,
  slash-left-kern     = -0.1 em ,
  slash-right-kern    = -0.1 em
}
\DeclareInstance { xfrac } { cmtt } { text } {
  denominator-bot-sep = 0 pt    ,
  numerator-top-sep   = 0.2 ex  ,
  slash-left-kern     = -0.1 em ,
  slash-right-kern    = -0.1 em
}
\bool_if:NF \l_xfrac_cm_std_bool
  {
    \DeclareInstance { xfrac } { cmr } { text }
      { slash-symbol-font = ptm }
    \DeclareInstance { xfrac } { cmss } { text }
      { slash-symbol-font = ptm }
    \DeclareInstance { xfrac } { cmtt } { text }
      { slash-symbol-font = ppl }
  }
\DeclareInstance { xfrac } { lmr } { text } {
  denominator-bot-sep = 0 pt     ,
  numerator-top-sep   = 0.1 ex   ,
  slash-left-kern     = -0.15 em ,
  slash-right-kern    = -0.15 em
}
\DeclareInstance { xfrac } { lmss } { text } {
  denominator-bot-sep = 0 pt     ,
  numerator-top-sep   = 0 pt     ,
  slash-left-kern     = -0.15 em ,
  slash-right-kern    = -0.15 em
}
\DeclareInstance { xfrac } { lmtt } { text } {
  denominator-bot-sep = 0 pt     ,
  numerator-top-sep   = 0 pt     ,
  slash-left-kern     = -0.15 em ,
  slash-right-kern    = -0.15 em
}
\msg_new:nnnn { xfrac } { over-specified-numerator-sep }
  {You have specified both numerator-top-sep and numerator-bot-sep}
  {I will pretend that you didn't specify either of them}
\NewDocumentCommand \sfrac { o m o m } {
  \mode_if_math:TF
    {
      \IfInstanceExistTF { xfrac } { mathfam \number \fam }
        { \UseInstance { xfrac } { mathfam \number \fam } }
        { \UseInstance { xfrac } { mathdefault } }
      {#2} {#3} {#4}
    }
    {
      \IfInstanceExistTF { xfrac } {#1}
        { \UseInstance { xfrac } {#1} }
        {
          \IfInstanceExistTF { xfrac } { \f@family }
            { \UseInstance { xfrac } { \f@family } }
            { \UseInstance { xfrac } { default } }
        }
      {#2} {#3} {#4}
    }
}
\endinput
%%
%% End of file `xfrac.sty'.
