%%
%% This is file `tablefootnote.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tablefootnote.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Project: tablefootnote
%% Version: 2014/01/26 v1.1c
%% 
%% Copyright (C) 2011 - 2014 by
%%     H.-Martin M"unch <Martin dot Muench at Uni-Bonn dot de>
%% 
%% The usual disclaimer applies:
%% If it doesn't work right that's your problem.
%% (Nevertheless, send an e-mail to the maintainer
%%  when you find an error in this package.)
%% 
%% 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. This version of this license is in
%%    http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is H.-Martin Muench.
%% 
%% This work consists of the main source file tablefootnote.dtx,
%% the README, and the derived files
%%    tablefootnote.sty, tablefootnote.pdf,
%%    tablefootnote.ins, tablefootnote.drv,
%%    tablefootnote-example.tex, tablefootnote-example.pdf.
%% 
%% In memoriam Tommy Muench + 2014/01/02.
%% 
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\ProvidesPackage{tablefootnote}[2014/01/26 v1.1c
              Table foot notes (HMM)]
%% Provides the \tablefootnote[...]{...} command
%% for footnotes in (sideways)tables.

\RequirePackage{ltxcmds}[2011/11/09]%     v1.22
\RequirePackage{letltxmacro}[2010/09/02]% v1.4
\RequirePackage{xifthen}[2009/04/17]%     v1.3
%% tablefootnote may work with earlier versions of LaTeX and those
%% packages, but this was not tested. Please consider updating
%% your LaTeX and packages to the most recent version
%% (if they are not already the most recent version).

\@ifpackageloaded{rotating}{%
  \gdef\tfn@rotating{1}
  \@ifpackagelater{rotating}{2009/03/28}% v2.16a
   {% >= 2009/03/28, OK
   }{% else
     \PackageWarningNoLine{tablefootnote}{%
       It is required version\MessageBreak%
       2009/03/28 v2.16a (or later) of package rotating,\MessageBreak%
       but only version\MessageBreak%
      `\csname ver@rotating.sty\endcsname'\MessageBreak%
      is available}%
   }%
 }{% else
   \gdef\tfn@rotating{0}%
 }

\def\tfn@footnotetablecount{0}
\def\tfn@footnotetableprint{0}
\def\tfn@footnotezero{0}
\def\tfn@fnt{0}
\def\tfn@swt{0}%       _s_ide_w_ays_t_able
\def\tfn@fmpw{\relax}% f_oot_m_isc_p_ara_w_arn-switch
\def\tfn@fnbr{0}%      f_oot_n_ote_b_ack_r_ef(erence package)

\DeclareRobustCommand{\tfn@hyperfootnotes}[2]{%
  \ifHy@hyperfootnotes%
    #1%
  \else%
    #2%
  \fi%
  }

\ltx@ifpackageloaded{footnotebackref}{%
  \gdef\tfn@fnbr{1}%
  \ifx\FootnoteBackref@symbol\empty%
    \ifFootnoteBackref@numberlinked%
      \newcommand\tablemakefntext[1]{%
        \noindent\makebox[1.634em][r]{%
         \mbox{\textsuperscript{\normalfont%
           \hyperlink{tfn:m\theHfootnote}{\@thefnmark}%
        }}}%
        \ #1%
      }
    \else
      \newcommand\tablemakefntext[1]{%
        \noindent\makebox[1.8em][r]{%
          \mbox{\textsuperscript{\normalfont%
            \@thefnmark%
        }}}%
        #1%
      }
    \fi
  \else
    \newcommand\tablemakefntext[1]{%
      \noindent\makebox[1.8em][r]{%
        \mbox{\textsuperscript{\normalfont%
          \ifFootnoteBackref@numberlinked%
            \hyperlink{tfn:m\theHfootnote}{\@thefnmark}\ %
          \else%
            \@thefnmark%
          \fi%
      }}}%
      \hyperlink{tfn:m\theHfootnote}{\FootnoteBackref@symbol}%
      #1%
    }
  \fi
}{%
  \newcommand\tablemakefntext[1]{%
    \noindent\makebox[1.8em][r]{%
      \mbox{\textsuperscript{\normalfont%
        \@thefnmark%
    }}}%
    #1%
  }
}

\newcommand\swtablemakefntext[1]{\noindent\ #1}

\newcommand{\tfn@footnotemarks}[1][]{%
  \hbox{%
    \ifthenelse{\isempty{#1}}%
      {\footnotemark%
       \ltx@ifpackageloaded{footnotebackref}%
         {\raisebox{\ht\strutbox}{\hypertarget{tfn:m\theHfootnote}{}}}%
         {% footnotebackref not loaded
         }%
      }%
      {\ltx@ifpackageloaded{hyperref}%
        {\tfn@hyperfootnotes{%
            \hyperlink{tfn:#1}{\footnotemark[#1]}%
          }{\footnotemark[#1]}}%
        {\footnotemark[#1]}%
       \ltx@ifpackageloaded{footnotebackref}%
        {\raisebox{\ht\strutbox}{\hypertarget{tfn:m#1}{}}}{}%
      }%
   }%
  \@tempcnta=\tfn@footnotetablecount\relax%
  \advance\@tempcnta by -1\relax%
  \xdef\tfn@footnotetablecount{\the\@tempcnta}%
}

\newcommand{\tfn@footmiscparawarn}{%
  \ifFN@para%
    \PackageWarning{tablefootnote}{%
      Package footmisc with option para used.\MessageBreak%
      Unfortunately package tablefootnote is not yet\MessageBreak%
      able to regard this in sidewaystables.\MessageBreak%
      Here the footnotes are printed one below\MessageBreak%
      the other. Sorry!\MessageBreak%
     }%
  \fi%
  }

\newcommand{\tfn@updateHyper}{%
  % The code of this command is partly from the
  % hyperref package by Heiko Oberdiek, 2011/10/01, v6.82j.
  % Newer versions of that package are available at CTAN.org.
  \global\let\Hy@saved@currentHref\@currentHref%
  \tfn@hyperfootnotes{\hyper@makecurrent{Hfootnote}}{}%
  \global\let\Hy@footnote@currentHref\@currentHref%
  \global\let\@currentHref\Hy@saved@currentHref%
  }

\newcommand{\tfn@footnotetext}[2][]{%
  \ifx\tfn@footnotetableprint\tfn@footnotezero%
    % This is the first footnotetext after the (sideways)table.
    \addtocounter{footnote}{\tfn@footnotetablecount}%
    \ltx@ifpackageloaded{hyperref}{%
      \tfn@hyperfootnotes{%
        \addtocounter{Hfootnote}{\tfn@footnotetablecount}}{}%
      \tfn@updateHyper%
     }{}%
  \fi%
  \addtocounter{footnote}{+1}%
  \ltx@ifpackageloaded{hyperref}{%
    \tfn@hyperfootnotes{\addtocounter{Hfootnote}{+1}}{}%
    \tfn@updateHyper%
   }{}%
  \ifx\tfn@swt\tfn@footnotezero%
    \ifthenelse{\isempty{#1}}%
      {\footnotetext{#2}}%
      {\ltx@ifpackageloaded{hyperref}%
         {\tfn@hyperfootnotes{%
             \footnotetext[#1]{%
               \raisebox{\ht\strutbox}{\hypertarget{tfn:#1}{}}#2}%
           }{\footnotetext[#1]{#2}%
           }%
         }{\footnotetext[#1]{#2}}%
      }%
  \else%
    \ifx\tfn@footnotetableprint\tfn@footnotezero%
      \gdef\tfn@fmpw{\tfn@footmiscparawarn}%
    \else%
      \ltx@ifpackageloaded{footmisc}{\tfn@fmpw}{\relax}%
      \gdef\tfn@fmpw{\relax}%
    \fi%
    \ltx@ifpackageloaded{footnotebackref}{%
      \LetLtxMacro{\tfncurrentmft}{\@makefntext}%
      \LetLtxMacro{\@makefntext}{\swtablemakefntext}%
      \ifthenelse{\isempty{#1}}%
        {\footnotetext{%
           \raisebox{\ht\strutbox}{\hypertarget{tfn:\theHfootnote}{}}%
           \hbox{\@textsuperscript{\normalfont%
              \hyperlink{tfn:m\theHfootnote}{\thefootnote}}}\thinspace%
         \ifx\FootnoteBackref@symbol\empty%
         \else\hyperlink{tfn:m\theHfootnote}{\FootnoteBackref@symbol}%
         \fi%
         #2}%
       }{\edef\tfn@tfn{\arabic{footnote}}%
         \edef\tfn@thn{\arabic{Hfootnote}}%
         \setcounter{footnote}{#1}%
         \setcounter{Hfootnote}{#1}%
         \tfn@updateHyper%
         \footnotetext{%
           \raisebox{\ht\strutbox}{\hypertarget{tfn:#1}{}}%
           \hbox{\@textsuperscript{\normalfont%
                  \hyperlink{tfn:m#1}{#1}}}%
           \thinspace%
           \ifx\FootnoteBackref@symbol\empty%
           \else%
             \raisebox{\ht\strutbox}{%
               \hyperlink{tfn:m#1}{\FootnoteBackref@symbol}}%
           \fi%
           #2%
          }%
         \setcounter{footnote}{\tfn@tfn}%
         \setcounter{Hfootnote}{\tfn@thn}%
         \tfn@updateHyper%
       }%
      \LetLtxMacro{\@makefntext}{\tfncurrentmft}%
     }{% footnotebackref not loaded
       \ifthenelse{\isempty{#1}}%
         {\footnotetext{%
            \hbox{\@textsuperscript{\normalfont\thefootnote}}%
            \ltx@ifpackageloaded{hyperref}%
              {\tfn@hyperfootnotes{%
                 \raisebox{\ht\strutbox}{%
                   \hypertarget{tfn:\theHfootnote}{}}}{}%
              }{}%
            \thinspace%
            #2}%
        }{%
          \edef\tfn@tfn{\arabic{footnote}}%
          \ltx@ifpackageloaded{hyperref}{%
            \tfn@hyperfootnotes{\xdef\tfn@thn{\arabic{Hfootnote}}}{}%
           }{}%
          \setcounter{footnote}{#1}
          \ltx@ifpackageloaded{hyperref}{%
            \tfn@hyperfootnotes{\setcounter{Hfootnote}{#1}}{}%
            \tfn@updateHyper%
           }{}%
          \footnotetext{%
            \hbox{\@textsuperscript{\normalfont #1}}%
            \ltx@ifpackageloaded{hyperref}{%
              \tfn@hyperfootnotes{\raisebox{\ht\strutbox}{%
                                         \hypertarget{tfn:#1}{}}}{}%
             }{}%
            \thinspace%
            #2}%
          \setcounter{footnote}{\tfn@tfn}%
          \ltx@ifpackageloaded{hyperref}{%
            \tfn@hyperfootnotes{\setcounter{Hfootnote}{\tfn@thn}}{}%
            \tfn@updateHyper%
           }{}%
        }%
     }%
  \fi%
  \gdef\tfn@footnotetableprint{1}%
  \@tempcnta=\tfn@footnotetablecount\relax%
  \advance\@tempcnta by +1\relax%
  \xdef\tfn@footnotetablecount{\the\@tempcnta}%
  \ifx\tfn@footnotetablecount\tfn@footnotezero% all footnotes placed
    \gdef\tfn@footnotetableprint{0}%
    \global\let\tfn@tablefootnoteprintout\relax% brute force
 %\else there is at least one \footnotemark which needs \footnotetext
  \fi
}

\newcommand{\tfn@tablefootnoteprintout}{\relax}

\newcommand{\tablefootnote}[2][]{%
  \tfn@footnotemarks[#1]%
  \ifthenelse{\isempty{#1}}{\relax}{%
    \ltx@GlobalPrependToMacro{\tfn@tablefootnoteprintout}{%
      \addtocounter{footnote}{+1}%
      \ltx@ifpackageloaded{hyperref}{%
        \tfn@hyperfootnotes{\addtocounter{Hfootnote}{+1}}{}%
        \tfn@updateHyper%
       }{}%
     }%
   }%
  \ltx@GlobalAppendToMacro{\tfn@tablefootnoteprintout}{%
    \tfn@footnotetext[#1]{#2}%
    \ifthenelse{\isempty{#1}}{\relax}{%
      \addtocounter{footnote}{-1}%
      \ltx@ifpackageloaded{hyperref}{%
        \tfn@hyperfootnotes{\addtocounter{Hfootnote}{-1}}{}%
        \tfn@updateHyper%
       }{}%
     }%
   }%
  \gdef\tfn@fnt{1}%
  }

\newcommand{\tfn@swtbox}{%
\ifvoid \footins%
\vskip 2\baselineskip%
\else%
\vskip \skip\footins%
\fi%
\parbox[b][][t]{\linewidth}{\raggedright\tfn@tablefootnoteprintout}%
}

\IfFileExists{etoolbox.sty}{%
  \RequirePackage{etoolbox}[2011/01/03]%   v2.1
  \AfterEndEnvironment{table}{%
    \ltx@ifpackageloaded{footnotebackref}{%
      \LetLtxMacro{\tfncurrentmft}{\@makefntext}%
      \LetLtxMacro{\@makefntext}{\tablemakefntext}%
       \tfn@tablefootnoteprintout%
      \LetLtxMacro{\@makefntext}{\tfncurrentmft}%
     }{% footnotebackref not loaded
      \tfn@tablefootnoteprintout%
     }%
      \gdef\tfn@fnt{0}%
   }%
  \ltx@ifpackageloaded{rotating}{%
    \AtBeginEnvironment{sidewaystable}{%
      \gdef\tfn@swt{1}%
    }
    \AtEndEnvironment{sidewaystable}{%
      \ifx\tfn@fnt\tfn@footnotezero% \relax
      \else%
        \ltx@ifpackageloaded{footnotebackref}{%
          \LetLtxMacro{\tfncurrentmft}{\@makefntext}%
          \LetLtxMacro{\@makefntext}{\tablemakefntext}%
           \tfn@swtbox%
          \LetLtxMacro{\@makefntext}{\tfncurrentmft}%
         }{% footnotebackref not loaded
          \tfn@swtbox%
          }%
      \fi%
      \gdef\tfn@swt{0}%
      \gdef\tfn@fnt{0}%
     }%
   }{}% else \relax
}{%
  \PackageWarning{tablefootnote}{%
    Package etoolbox not available, therefore\MessageBreak%
    substituting commands \string\AtEndEnvironment\space %
    and\MessageBreak%
    \string\AfterEndEnvironment\space for tablefootnotes%
    \MessageBreak%
   }%
  \@ifpackagelater{letltxmacro}{2010/09/02}%
   {% >= 2010/09/02, OK
    \GlobalLetLtxMacro{\tfnorigtable}{\table}
    \GlobalLetLtxMacro{\tfnendorigtable}{\endtable}
   }{% else
     \PackageError{tablefootnote}{%
       Outdated version of letltxmacro package used%
      }{Version 2010/09/02 v1.4 or newer needed but not found!%
        \MessageBreak%
        Update the used letltxmacro package.}
        \LetLtxMacro{\tfnorigtable}{\table}
        \LetLtxMacro{\tfnendorigtable}{\endtable}
    }%
  \ltx@ifpackageloaded{float}{%
    \@ifpackagelater{float}{2001/11/08}%   v1.3d
     {% >= 2001/11/08, OK
     }{% else
       \PackageWarningNoLine{tablefootnote}{%
         It is required version\MessageBreak
         2001/11/08 v1.3d (or later) of package float,\MessageBreak
         but only version\MessageBreak
        `\csname ver@float.sty\endcsname'\MessageBreak
        is available}%
     }%
   }{\relax}
  \renewenvironment{table}{%
    \ltx@ifpackageloaded{float}{%
      \ltx@LocalAppendToMacro{\float@endH}{%
        \ltx@ifpackageloaded{footnotebackref}{%
          \LetLtxMacro{\tfncurrentmft}{\@makefntext}%
          \LetLtxMacro{\@makefntext}{\tablemakefntext}%
           \tfn@tablefootnoteprintout%
          \LetLtxMacro{\@makefntext}{\tfncurrentmft}%
         }{% footnotebackref not loaded
          \tfn@tablefootnoteprintout%
         }%
          \gdef\tfn@fnt{0}%
       }%
     }{\relax}
    \tfnorigtable%
   }{%
     \tfnendorigtable%
     \ltx@ifpackageloaded{footnotebackref}{%
       \LetLtxMacro{\tfncurrentmft}{\@makefntext}%
       \LetLtxMacro{\@makefntext}{\tablemakefntext}%
        \tfn@tablefootnoteprintout%
       \LetLtxMacro{\@makefntext}{\tfncurrentmft}%
      }{% footnotebackref not loaded
       \tfn@tablefootnoteprintout%
      }%
     \gdef\tfn@fnt{0}%
    }%
  \ltx@ifpackageloaded{rotating}{%
    \let\tfnorigsidewaystable\sidewaystable
    \let\tfnendorigsidewaystable\endsidewaystable
    \renewenvironment{sidewaystable}{%
      \gdef\tfn@swt{1}%
      \tfnorigsidewaystable%
    }{%
      \ifx\tfn@fnt\tfn@footnotezero% \relax
      \else%
        \ltx@ifpackageloaded{footnotebackref}{%
          \LetLtxMacro{\tfncurrentmft}{\@makefntext}%
          \LetLtxMacro{\@makefntext}{\tablemakefntext}%
           \tfn@swtbox%
          \LetLtxMacro{\@makefntext}{\tfncurrentmft}%
         }{% footnotebackref not loaded
          \tfn@swtbox%
         }%
      \fi%
      \gdef\tfn@swt{0}%
      \gdef\tfn@fnt{0}%
      \tfnendorigsidewaystable%
     }%
   }{}%
}

\AtBeginDocument{%
  \ltx@ifpackageloaded{footnotebackref}{%
    \ifx\tfn@fnbr\tfn@footnotezero%
      \PackageError{tablefootnote}{%
        Package footnotebackref loaded after tablefootnote}{%
        When using both the footnotebackref and the tablefootnote %
        package,\MessageBreak%
        the footnotebackref package MUST be loaded before the %
        tablefootnote package!\MessageBreak%
       }%
    \fi%
   }{% else \relax
   }
  \ltx@ifpackageloaded{rotating}{%
    \ifx\tfn@rotating\tfn@footnotezero%
      \PackageError{tablefootnote}{%
        Package rotating loaded after tablefootnote}{%
        When using both the rotating and the tablefootnote package,%
        \MessageBreak%
        the rotating package MUST be loaded before the tablefootnote%
        \space package!\MessageBreak%
       }%
    \fi%
   }{% else \relax
   }
  \ltx@ifpackageloaded{hyperref}{%
    \tfn@hyperfootnotes{
      \ifluatex%
        \PackageWarningNoLine{tablefootnote}{%
          LuaTeX and hyperref package used:\MessageBreak%
          Hyperreferences in rotated content\MessageBreak%
          will be misplaced\MessageBreak%
          regardless of tablefootnote package.\MessageBreak%
          The text to be printed will be OK%
         }%
      \fi%
     }{% else \relax
     }%
   }{% else \relax
   }%
  \ltx@ifpackageloaded{footnotebackref}{%
     \ltx@ifpackageloaded{hyperref}{%
        \tfn@hyperfootnotes{\relax}{% else
          \PackageError{tablefootnote}{%
             footnotebackref but not hyperfootnotes}{%
             The footnotebackref package is used\MessageBreak%
             but the hyperfootnotes option of the hyperref package%
             \MessageBreak%
             was set to false.\MessageBreak%
             Either enable hyperfootnotes or do not use footnotebackref.%
             \MessageBreak%
             Loading of the tablefootnote package will be aborted.%
           }%
          \endinput%
      }%
    }{\PackageError{tablefootnote}{footnotebackref but not hyperref}{%
        The footnotebackref package is used\MessageBreak%
        but not the hyperref package.\MessageBreak%
        Either load hyperref or do not use footnotebackref.%
        \MessageBreak%
        Loading of the tablefootnote package will be aborted.%
        }%
      \endinput%
    }%
  }{}
}

\endinput
%%
%% End of file `tablefootnote.sty'.
