%%
%% This is file `nameref.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% nameref.dtx  (with options: `package')
%% 
%% Copyright
%% 1995-2001 Sebastian Rahtz, with portions written by David Carlisle and Heiko Oberdiek,
%% 2001-2015 Heiko Oberdiek.
%% 2016-2019 Oberdiek Package Support Group
%% 2019-2022 LaTeX Project
%%      https://github.com/latex3/hyperref/issues
%% 
%% This file is part of the `Hyperref Bundle'.
%% -------------------------------------------
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% 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
%% and version 1.3 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 the LaTeX Project.
%% 
%% The list of all files belonging to the `Hyperref Bundle' is
%% given in the file `manifest.txt'.
%% 
%% File: nameref.dtx
%% Copyright (C) 1995-1999 Sebastian Rahtz
%%               2000 Sebastian Rahtz, Heiko Oberdiek
%%               2001-2012 Heiko Oberdiek
%%               2016-2019 Oberdiek Package Suport Group
%%               2019-2022 The LaTeX Project
%%      https://github.com/latex3/hyperref/issues
%%
%% This file is part of the `Hyperref Bundle'.
%% -------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% 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
%% and version 1.3 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 The LaTeX Project.
%%
%% The list of all files belonging to the `Hyperref Bundle' is
%% given in the file `manifest.txt'.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{nameref}
  [2022-05-13 v2.48 Cross-referencing by name of section]%
\RequirePackage{refcount}[2006/02/12]
\RequirePackage{gettitlestring}[2009/12/18]
\RequirePackage{ltxcmds}[2009/12/12]
\def\NR@strip@period#1.\ltx@empty#2\@nil{#1}
\def\strip@period#1.\relax#2\@@@{#1}
\def\NR@sanitize@labelname{%
  \@onelevel@sanitize\@currentlabelname
  \edef\@currentlabelname{%
    \expandafter\NR@strip@period\@currentlabelname
    \ltx@empty.\ltx@empty\@nil
  }%
}
\newif\ifNR@showkeys
\NR@showkeysfalse
\@ifpackageloaded{showkeys}{%
  \begingroup
    \@ifundefined{SK@@label}{%
    }{%
      \global\NR@showkeystrue
    }%
  \endgroup
}{}
\providecommand*{\label@hook}{}
\ltx@GlobalAppendToMacro{\label@hook}{%
  \NR@sanitize@labelname
}
\def\label#1{%
  \@bsphack
  \begingroup
    \def\label@name{#1}%
    \label@hook
    \protected@write\@auxout{}{%
      \string\newlabel{#1}{%
        {\@currentlabel}%
        {\thepage}%
        {\@currentlabelname}%
        {\@currentHref}{}%
      }%
    }%
  \endgroup
  \@esphack
}%
\ifNR@showkeys
  \def\label#1{%
    \@bsphack
    \SK@\SK@@label{#1}%
    \begingroup
      \def\label@name{#1}%
      \label@hook
      \protected@write\@auxout{}{%
        \string\newlabel{#1}{%
          {\@currentlabel}%
          {\thepage}%
          {\@currentlabelname}%
          {\@currentHref}{}%
        }%
      }%
    \endgroup
    \@esphack
  }%
\fi
\let\ltx@label\label
\@ifundefined{slabel}{}{%
  \def\slabel#1{%
    \@bsphack
    \if@filesw
      \begingroup
        \def\label@name{#1}%
        \label@hook
        \let\thepage\relax
        \def\protect{\noexpand\noexpand\noexpand}%
        \edef\@tempa{%
          \write\@auxout{%
            \string\newlabel{#1}{%
              {\thesubequation}%
              {\thepage}%
              {\@currentlabelname}%
              {\@currentHref}{}%
            }%
          }%
        }%
      \expandafter\endgroup
      \@tempa
      \if@nobreak\ifvmode\nobreak\fi\fi
    \fi
    \@esphack
  }%
}
\def\@writetocindents@{%
  \begingroup
  \@for\@tempa:=-1,0,1,2,3\do{%
    \immediate\write\@auxout{%
      \string\newlabel{tocindent\@tempa}{%
        \csname r@tocindent\@tempa\endcsname{}{}{}{}%
      }%
    }%
  }%
  \endgroup
}
\def\NR@gettitle#1{%
  \GetTitleString{#1}%
  \let\@currentlabelname\GetTitleStringResult
}
\let\NR@sect\@sect
\newcounter{section@level}
\@ifundefined{NR@nopatch@sectioning}
 {\def\@sect#1#2#3#4#5#6[#7]#8{%
   \setcounter{section@level}{#2}%
   \NR@gettitle{#7}%
   \NR@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{\Sectionformat{#8}{#2}}%
 }}{}
\let\NR@ssect\@ssect
\@ifundefined{NR@nopatch@sectioning}
 {\def\@ssect#1#2#3#4#5{%
   \NR@gettitle{#5}%
   \NR@ssect{#1}{#2}{#3}{#4}{\Sectionformat{#5}{#1}}%
 }}{}
\@ifundefined{NR@nopatch@sectioning}
 {\ltx@IfUndefined{ifheadnameref}{%
  }{%
    \ltx@IfUndefined{M@sect}{%
    }{%
      \let\NRorg@M@sect\M@sect
      \def\M@sect#1#2#3#4#5#6[#7][#8]{%
        \ifheadnameref
          \NR@gettitle{#8}%
        \else
          \NR@gettitle{#7}%
        \fi
        \NRorg@M@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}][{#8}]%
      }%
    }%
  }}{}
\let\NR@part\@part
\let\NR@spart\@spart
\let\NR@chapter\@chapter
\let\NR@schapter\@schapter
\@ifundefined{NR@nopatch@sectioning}
 {%
  \long\def\@part[#1]#2{%
    \NR@gettitle{#1}%
    \NR@part[{#1}]{#2}%
  }
  \long\def\@spart#1{%
    \NR@gettitle{#1}%
    \NR@spart{#1}%
  }
  \def\@chapter[#1]#2{%
    \NR@gettitle{#1}%
    \NR@chapter[{#1}]{#2}%
  }
  \@ifclassloaded{memoir}{%
    \ltx@IfUndefined{ifheadnameref}{%
    }{%
      \def\@chapter[#1]#2{%
        \ltx@IfUndefined{ch@pt@c}{%
          \NR@gettitle{#1}%
        }{%
          \ifx\ch@pt@c\ltx@empty
            \NR@gettitle{#2}%
          \else
            \def\NR@temp{#1}%
            \ifx\NR@temp\ltx@empty
              \expandafter\NR@gettitle\expandafter{\ch@pt@c}%
            \else
              \ifheadnameref
                \NR@gettitle{#1}%
              \else
                \expandafter\NR@gettitle\expandafter{\ch@pt@c}%
              \fi
            \fi
          \fi
        }%
        \NR@chapter[{#1}]{#2}%
      }%
    }%
  }{}
  \def\@schapter#1{%
    \NR@gettitle{#1}%
    \NR@schapter{#1}%
  }}{}
\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{}
  {%
    \@ifundefined{NR@nopatch@caption}
     {\let\NR@@caption\@caption
      \long\def\@caption#1[#2]{%
      \NR@gettitle{#2}%
      \NR@@caption{#1}[{#2}]%
       }}%
     {}%
  }%
  \@ifpackageloaded{longtable}{%
   \@ifundefined{NR@nopatch@longtable}
    {%
      \let\NRorg@LT@c@ption\LT@c@ption
      \def\LT@c@ption#1[#2]#3{%
       \NRorg@LT@c@ption{#1}[{#2}]{#3}%
       \def\@tempa{#2}%
       \ifx\@tempa\@empty
       \else
        \NR@gettitle{#2}%
       \fi
      }%
    }{}%
  }{}%
  \ltx@IfUndefined{descriptionlabel}{%
  }{%
    \@ifundefined{NR@nopatch@longtable}
     {\let\NRorg@descriptionlabel\descriptionlabel
      \def\descriptionlabel#1{%
       \NR@gettitle{#1}%
       \NRorg@descriptionlabel{#1}%
       }%
     }{}%
  }%
}
\AtBeginDocument{%
  \@ifpackageloaded{titlesec}{%
    \let\NRorg@ttl@sect@i\ttl@sect@i
    \@ifundefined{NR@nopatch@titlesec}
     {%
       \def\ttl@sect@i#1#2[#3]#4{%
         \NR@gettitle{#4}%
         \NRorg@ttl@sect@i{#1}{#2}[{#3}]{#4}%
         }%
      }{}%
  }{}%
}
\@ifclassloaded{beamer}{%
  \@ifundefined{NR@nopatch@beamer}
  {%
    \def\NR@PatchBeamer#1{%
      \expandafter\let\csname NRorg@beamer@#1\expandafter\endcsname
                      \csname beamer@#1\endcsname
      \begingroup
        \edef\x{\endgroup
          \long\def\expandafter\noexpand\csname beamer@#1\endcsname
              [####1]{% hash-ok
            \noexpand\NR@gettitle{####1}%
            \expandafter\noexpand\csname NRorg@beamer@#1\endcsname
            [{####1}]%
          }%
        }%
      \x
    }%
    \NR@PatchBeamer{section}%
    \NR@PatchBeamer{subsection}%
    \NR@PatchBeamer{subsubsection}%
    \addtobeamertemplate{theorem begin}{%
      \expandafter\NR@gettitle\expandafter{\inserttheoremaddition}%
    }{}%
    \@ifdefinable{\NRorg@beamer@descriptionitem}{%
      \let\NRorg@beamer@descriptionitem\beamer@descriptionitem
      \renewcommand{\beamer@descriptionitem}[1]{%
        \NR@gettitle{#1}%
        \NRorg@beamer@descriptionitem{#1}%
      }%
    }%
   }{}%
}{}
\ltx@IfUndefined{@opargbegintheorem}{}{%
  \let\NRorg@opargbegintheorem\@opargbegintheorem
  \def\@opargbegintheorem#1#2#3{%
    \NR@gettitle{#3}%
    \NRorg@opargbegintheorem{#1}{#2}{#3}%
  }%
}
\AtBeginDocument{%
  \@ifpackageloaded{amsthm}{%
    \let\NRorg@begintheorem\@begintheorem
    \begingroup
      \edef\x{macro:\string#1\string#2[\string#3]}%
      \@onelevel@sanitize\x
      \def\y#1->#2\@nil{#1}%
      \edef\z{\expandafter\y\meaning\@begintheorem->\@nil}%
      \@onelevel@sanitize\z
    \expandafter\endgroup
    \ifx\x\z
      \def\@begintheorem#1#2[#3]{%
        \NR@gettitle{#3}%
        \NRorg@begintheorem{#1}{#2}[{#3}]%
      }%
    \fi
  }{}%
}
\providecommand*{\@currentlabelname}{}
\providecommand*{\@currentHref}{}
\long\def\@firstoffive#1#2#3#4#5{#1}
\long\def\@secondoffive#1#2#3#4#5{#2}
\long\def\@thirdoffive#1#2#3#4#5{#3}
\long\def\@fourthoffive#1#2#3#4#5{#4}
\long\def\@fifthoffive#1#2#3#4#5{#5}
\providecommand*\@safe@activestrue{}%
\providecommand*\@safe@activesfalse{}%
\newcommand\NR@ref@showkeys[1]{}%
\def\NR@setref#1{%
  \begingroup
    \@safe@activestrue
    \expandafter
  \endgroup
  \expandafter\NR@@setref\csname r@#1\endcsname
}
\def\NR@@setref#1{%
  \ifx\@undefined#1%
    \let#1\relax
  \fi
  \@setref#1%
}
\def\T@ref#1{%
  \NR@ref@showkeys{#1}%
  \NR@setref{#1}\@firstoffive{#1}%
}%
\def\@refstar#1{%
  \NR@ref@showkeys{#1}%
  \NR@setref{#1}\@firstoffive{#1}%
}%
\def\T@pageref#1{%
  \NR@ref@showkeys{#1}%
  \NR@setref{#1}\@secondoffive{#1}%
}%
\def\@pagerefstar#1{%
  \NR@ref@showkeys{#1}%
  \NR@setref{#1}\@secondoffive{#1}%
}%
\def\T@Ref#1{%
    \NR@ref@showkeys{#1}%
    \NR@setref{#1}\NR@MakeUppercaseFirstOfFive{#1}%
  }%
\def\NR@MakeUppercaseFirstOfFive#1#2#3#4#5{%
    \MakeUppercase#1%
  }%
\def\@Refstar#1{%
    \NR@ref@showkeys{#1}%
    \NR@setref{#1}\NR@MakeUppercaseFirstOfFive{#1}%
  }%
\ifNR@showkeys
  \ifx\SK@ref\@empty
  \else
  \renewcommand\NR@ref@showkeys[1]{%
    \@safe@activestrue
    \SK@\SK@@ref{#1}%
    \@safe@activesfalse}
  \fi
\fi
\AddToHook{begindocument}{%
  \DeclareDocumentCommand\ref{s}
   {\IfBooleanTF{#1}{\@refstar}{\T@ref}}%
  \DeclareDocumentCommand\pageref{s}
   {\IfBooleanTF{#1}{\@pagerefstar}{\T@pageref}}%
  \DeclareDocumentCommand\Ref{s}
   {\IfBooleanTF{#1}{\@Refstar}{\T@Ref}}%
}
\DeclareHookRule{begindocument}{showkeys}{before}{nameref}
\def\T@nameref#1{%
  \NR@ref@showkeys{#1}%
  \begingroup
    \let\label\@gobble
    \NR@setref{#1}\@thirdoffive{#1}%
  \endgroup
}%
\def\@namerefstar#1{%
  \NR@ref@showkeys{#1}%
  \begingroup
    \let\label\@gobble
    \NR@setref{#1}\@thirdoffive{#1}%
  \endgroup
}%
\NewDocumentCommand\nameref{s}
   {\IfBooleanTF{#1}{\@namerefstar}{\T@nameref}}
\def\Nameref#1{`\nameref{#1}' on page~\pageref{#1}}
\providecommand\Sectionformat[2]{#1}
\@ifundefined{@kernel@pageref@exp}
   {\@ifpackageloaded{ifthen}{%
     \let\NROrg@ifthenelse\ifthenelse
     \def\ifthenelse{%
       \let\begingroup\NR@TE@begingroup
       \NROrg@ifthenelse
     }%
     \let\NROrg@begingroup\begingroup
     \def\NR@TE@begingroup{%
       \let\begingroup\NROrg@begingroup
       \begingroup
       \def\ref##1{\getrefbykeydefault{##1}{}{??}}%
       \def\pageref##1{\getrefbykeydefault{##1}{page}{0}}%
     }%
   }{}}{}
\AtBeginDocument{%
  \ifx\csname @@vpageref\endcsname\relax
  \else
   \let\NR@@vpageref\@@vpageref
   \def\@@vpageref#1[#2]#3{%
      \begingroup
        \csname @safe@activestrue\endcsname
        \edef\x{#3}%
        \@onelevel@sanitize\x
        \toks@{%
          \NR@@vpageref{#1}[{#2}]%
        }%
        \edef\x{\endgroup
          \the\toks@{\x}%
        }%
      \x
    }%
    \DeclareRobustCommand\vnameref[1]{%
      \unskip~\nameref{#1} %
      \@vpageref[\unskip]{#1}%
    }%
  \fi
}
\AtBeginDocument{%
  \@ifpackageloaded{listings}{%
    \@ifundefined{NR@nopatch@listings}
     {%
       \let\NROrg@lst@MakeCaption\lst@MakeCaption
       \def\lst@MakeCaption{%
         \ifx\lst@label\@empty
         \else
           \let\@currentlabelname\lst@@caption
         \fi
         \NROrg@lst@MakeCaption
       }%
      }{}%
  }{}%
}
\endinput
%%
%% End of file `nameref.sty'.
