newer sref.sty
This commit is contained in:
parent
f4c375d073
commit
c9bc9d6b82
299
etc/sref.sty
299
etc/sref.sty
@ -7,99 +7,238 @@
|
|||||||
%% sref.dtx (with options: `package')
|
%% sref.dtx (with options: `package')
|
||||||
%%
|
%%
|
||||||
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
|
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
|
||||||
\ProvidesPackage{sref}[2011/12/20 v1.0 Semantic Cross-References]
|
\ProvidesPackage{sref}[2016/04/07 v1.2 Semantic Cross-References]
|
||||||
\DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}}
|
|
||||||
\newif\ifextrefs\extrefsfalse
|
\newif\ifextrefs\extrefsfalse
|
||||||
\DeclareOption{extrefs}{\extrefstrue}
|
\DeclareOption{extrefs}{\extrefstrue}
|
||||||
\ProcessOptions
|
\ProcessOptions
|
||||||
\RequirePackage{metakeys}
|
\RequirePackage{metakeys}
|
||||||
\newcommand{\sref}[2][]{%
|
\RequirePackage{xspace}
|
||||||
\@ifundefined{sref@part}{\sref@hlink[#1]{#2}}{\sref@hlink[#1]{\sref@part @#2}}}
|
\RequirePackage{etoolbox}
|
||||||
\newcommand{\srefs}[3][]{%
|
\addmetakey{sref}{linktext}
|
||||||
\def\@test{#1}\ifx\@test\@empty\sref{#2} and \sref{#3}\else #1\fi}
|
\addmetakey{sref}{fallback}
|
||||||
\newcommand{\srefl}[3][]{%
|
\addmetakey{sref}{pre}
|
||||||
\def\@test{#1}\ifx\@test\@empty\sref{#2} to \sref{#3}\else #1\fi}
|
\addmetakey{sref}{post}
|
||||||
\newcommand{\spageref}[1]{%
|
\newcommand\sref[2][]{%
|
||||||
\@ifundefined{sref@part}{\sref@pageref{#1}}{\sref@pageref{\sref@part @#1}}}
|
\metasetkeys{sref}{#1}%
|
||||||
\newif\ifhref\hreffalse
|
\ifcsundef{sref@part}{%
|
||||||
\AtBeginDocument{\@ifpackageloaded{hyperref}{\hreftrue}{\hreffalse}}
|
\sref@hlink[\sref@linktext]{#2}{\sref@fallback}{\sref@pre}{\sref@post}%
|
||||||
\newcommand\sref@href@ifh[2]{\ifhref\href{#1}{#2}\else#2\fi}
|
}{%
|
||||||
\newcommand\sref@hlink@ifh[2]{\ifhref\hyperlink{#1}{#2}\else#2\fi}
|
\sref@hlink[\sref@linktext]{\sref@part @#2}{\sref@fallback}{\sref@pre}{\sref@post}%
|
||||||
\newcommand\sref@target@ifh[2]{\ifhref\hypertarget{#1}{#2}\else#2\fi}
|
}%
|
||||||
\def\sref@target%
|
\xspace%
|
||||||
{\ifx\sref@id\@empty\else%
|
}%
|
||||||
\edef\@target{sref@\@ifundefined{sref@part}{}{\sref@part @}\sref@id @target}
|
\newcommand\srefs[3][]{%
|
||||||
\sref@target@ifh\@target{}\fi}
|
\def\@test{#1}%
|
||||||
\newcommand\@sref@def[3]{\expandafter\gdef\csname sref@#1@#2\endcsname{#3}}
|
\ifx\@test\@empty%
|
||||||
\ifextrefs\newwrite\refs@file\else\def\refs@file{\@auxout}\fi
|
\sref{#2} and \sref{#3}%
|
||||||
\newcommand\sref@def[3]{%\@sref@def{#1}{#2}{#3}%
|
\else%
|
||||||
\protected@write\refs@file{}{\string\@sref@def{#1}{#2}{#3}}}
|
#1%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
\newcommand\srefl[3][]{%
|
||||||
|
\def\@test{#1}%
|
||||||
|
\ifx\@test\@empty%
|
||||||
|
\sref{#2} to \sref{#3}%
|
||||||
|
\else%
|
||||||
|
#1%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
\newcommand\spageref[1]{%
|
||||||
|
\ifcsundef{sref@part}{%
|
||||||
|
\sref@pageref{#1}%
|
||||||
|
}{%
|
||||||
|
\sref@pageref{\sref@part @#1}%
|
||||||
|
}%
|
||||||
|
}%
|
||||||
|
\newif\ifhref\hreffalse%
|
||||||
|
\AtBeginDocument{%
|
||||||
|
\@ifpackageloaded{hyperref}{%
|
||||||
|
\hreftrue%
|
||||||
|
}{%
|
||||||
|
\hreffalse%
|
||||||
|
}%
|
||||||
|
}%
|
||||||
|
\newcommand\sref@href@ifh[2]{%
|
||||||
|
\ifhref%
|
||||||
|
\href{#1}{#2}%
|
||||||
|
\else%
|
||||||
|
#2%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
\newcommand\sref@hlink@ifh[2]{%
|
||||||
|
\ifhref%
|
||||||
|
\hyperlink{#1}{#2}%
|
||||||
|
\else%
|
||||||
|
#2%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
\newcommand\sref@target@ifh[2]{%
|
||||||
|
\ifhref%
|
||||||
|
\hypertarget{#1}{#2}%
|
||||||
|
\else%
|
||||||
|
#2%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
\def\sref@target{%
|
||||||
|
\ifx\sref@id\@empty%
|
||||||
|
\relax%
|
||||||
|
\else%
|
||||||
|
\edef\@target{sref@\ifcsundef{sref@part}{}{\sref@part @}\sref@id @target}%
|
||||||
|
\sref@target@ifh\@target{}%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
\newcommand\@sref@def[3]{\csgdef{sref@#1@#2}{#3}}
|
||||||
|
\ifextrefs%
|
||||||
|
\newwrite\refs@file%
|
||||||
|
\else%
|
||||||
|
\def\refs@file{\@auxout}%
|
||||||
|
\fi%
|
||||||
|
\newcommand\sref@def[3]{%
|
||||||
|
%\@sref@def{#1}{#2}{#3}%
|
||||||
|
\protected@write\refs@file{}{\string\@sref@def{#1}{#2}{#3}}%
|
||||||
|
}%
|
||||||
\addmetakey{srefaddidkey}{prefix}
|
\addmetakey{srefaddidkey}{prefix}
|
||||||
\newcommand\srefaddidkey[2][]{\metasetkeys{srefaddidkey}{#1}%
|
\newcommand\srefaddidkey[2][]{%
|
||||||
|
\metasetkeys{srefaddidkey}{#1}%
|
||||||
\@metakeys@ext@clear@keys{#2}{sref@id}{}% id cannot have a default
|
\@metakeys@ext@clear@keys{#2}{sref@id}{}% id cannot have a default
|
||||||
\metakeys@ext@clear@keys{#2}{id}{}%
|
\metakeys@ext@clear@keys{#2}{id}{}%
|
||||||
\metakeys@ext@showkeys{#2}{id}%
|
\metakeys@ext@showkeys{#2}{id}%
|
||||||
\define@key{#2}{id}{\edef\sref@id{\srefaddidkey@prefix ##1}%
|
\define@key{#2}{id}{%
|
||||||
\expandafter\edef\csname #2@id\endcsname{\srefaddidkey@prefix ##1}}}
|
\edef\sref@id{\srefaddidkey@prefix ##1}%
|
||||||
\newcommand\makeextrefs[1]{\gdef\sref@part{#1}%
|
%\expandafter\edef\csname #2@id\endcsname{\srefaddidkey@prefix ##1}%
|
||||||
\makeatletter
|
\csedef{#2@id}{\srefaddidkey@prefix ##1}%
|
||||||
|
}%
|
||||||
|
}%
|
||||||
|
\newcommand\makeextrefs[1]{%
|
||||||
|
\gdef\sref@part{#1}%
|
||||||
|
\makeatletter%
|
||||||
\IfFileExists{\jobname.refs}{\input{\jobname.refs}}{}%
|
\IfFileExists{\jobname.refs}{\input{\jobname.refs}}{}%
|
||||||
\immediate\openout\refs@file=\jobname.refs
|
\immediate\openout\refs@file=\jobname.refs
|
||||||
\makeatother}
|
\makeatother%
|
||||||
|
}%
|
||||||
\newcommand\sref@label[2]{%
|
\newcommand\sref@label[2]{%
|
||||||
\sref@def{\@ifundefined{sref@part}{}{\sref@part @}#2}{page}{\thepage}%
|
\sref@def{\ifcsundef{sref@part}{}{\sref@part @}#2}{page}{\thepage}%
|
||||||
\sref@def{\@ifundefined{sref@part}{}{\sref@part @}#2}{label}{#1}}
|
\sref@def{\ifcsundef{sref@part}{}{\sref@part @}#2}{label}{#1}%
|
||||||
\newcommand\sreflabel[2]{\message{sreflabel: #1, #2}\sref@label{#1 \@currentlabel}{#2}}
|
}%
|
||||||
\newcommand\sref@label@id[1]{\ifx\sref@id\@empty\else\sref@label{#1}{\sref@id}\fi}
|
\newcommand\sreflabel[2]{\sref@label{#1 \@currentlabel}{#2}}
|
||||||
\newcommand{\sref@hlink}[2][]{\def\@test{#1}%
|
\newcommand\sref@label@id[1]{%
|
||||||
\@ifundefined{sref@#2@label}%
|
\ifx\sref@id\@empty%
|
||||||
{\protect\G@refundefinedtrue\@latex@warning{reference #2 undefined}??}%
|
\relax%
|
||||||
{\sref@hlink@ifh{sref@#2@target}{\ifx\@test\@empty\@nameuse{sref@#2@label}\else #1\fi}}}
|
\else%
|
||||||
\newcommand{\sref@page@label}[1]{p.~{#1}}
|
\sref@label{#1}{\sref@id}%
|
||||||
\newcommand{\sref@pageref}[1]{\@ifundefined{sref@#1@page}%
|
\fi%
|
||||||
{\protect\G@refundefinedtrue\@latex@warning{reference #1 undefined}\sref@page@label{??}}%
|
}%
|
||||||
{\sref@hlink@ifh{sref@#1@target}{\sref@page@label{\@nameuse{sref@#1@page}}}}}
|
\newcommand\sref@label@id@arg[2]{%
|
||||||
\newcommand{\sref@href}[3][]{\def\@test{#1}%
|
\def\@@id{#2}
|
||||||
\@ifundefined{sref@#2@label}%
|
\ifx\@@id\@empty%
|
||||||
{\protect\G@refundefinedtrue\@latex@warning{reference #2 undefined}??}%
|
\relax%
|
||||||
{\@ifundefined{sref@#3@URI}%
|
\else%
|
||||||
{\protect\G@refundefinedtrue\@latex@warning{external refs of type #3 undefined}??}%
|
\sref@label{#1}{\@@id}%
|
||||||
{\edef\@uri{\@nameuse{sref@#3@URI}.pdf\#sref@#2@target}
|
\fi%
|
||||||
\edef\@label{\ifx\@test\@empty\@nameuse{sref@#2@label}\else #1\fi}
|
}%
|
||||||
\sref@href@ifh\@uri\@label}}}
|
\newcommand\sref@hlink[5][]{%
|
||||||
\ifextrefs
|
\edef\@linktext{#1}%
|
||||||
\newcommand{\extref}[3][]{\def\theextref{\sref@href[#1]{#2@#3}{#2}}%
|
\edef\@fallback{#3}%
|
||||||
\csname doextref@#2\endcsname}
|
\ifcsundef{sref@#2@label}{%
|
||||||
\else
|
\ifx\@fallback\@empty% warn about undefined links and show a substitute
|
||||||
\newcommand{\extref}[3][]{\sref[#1]{#3}}
|
\protect\G@refundefinedtrue\@latex@warning{reference #2 undefined}%
|
||||||
|
\ifx\@linktext\@empty%
|
||||||
|
?#2?%
|
||||||
|
\else%
|
||||||
|
\@linktext%
|
||||||
|
\fi%
|
||||||
|
\else%
|
||||||
|
\protect\G@refundefinedtrue\@latex@warning{using fallback for undefined reference #2}%
|
||||||
|
\@fallback%
|
||||||
\fi
|
\fi
|
||||||
\ifextrefs
|
}{%
|
||||||
\newcommand{\extpageref}[3][]{\def\thepageextref{\sref@pageref[#1]{#2@#3}{#2}}%
|
\edef\@link{#4\@nameuse{sref@#2@label}#5}% retrieve the reference label and prepost it
|
||||||
\csname doextpageref@#2\endcsname}
|
\ifx\@linktext\@empty%
|
||||||
\else
|
\sref@hlink@ifh{sref@#2@target}{\@link}%
|
||||||
\newcommand{\extpageref}[3][]{\spageref[#1]{#3}}
|
\else%
|
||||||
\fi
|
\sref@hlink@ifh{sref@#2@target}{\@linktext}%
|
||||||
\newcommand\extrefstyle[2]{\expandafter\gdef\csname doextref@#1\endcsname{#2}}
|
\fi%
|
||||||
\newcommand\extpagerefstyle[2]{\expandafter\gdef\csname doextpageref@#1\endcsname{#2}}
|
}%
|
||||||
\newcommand{\inputrefs}[2]{%
|
}%
|
||||||
\@namedef{sref@#1@URI}{#2}
|
\newcommand\sref@page@label[1]{p.~{#1}}
|
||||||
|
\newcommand\sref@pageref[1]{%
|
||||||
|
\ifcsundef{sref@#1@page}{%
|
||||||
|
\protect\G@refundefinedtrue\@latex@warning{reference #1 undefined}\sref@page@label{??}%
|
||||||
|
}{%
|
||||||
|
\sref@hlink@ifh{sref@#1@target}{\sref@page@label{\@nameuse{sref@#1@page}}}%
|
||||||
|
}%
|
||||||
|
}%
|
||||||
|
\newcommand\sref@href[3][]{%
|
||||||
|
\edef\@linktext{#1}%
|
||||||
|
\ifcsundef{sref@#2@label}{%
|
||||||
|
\protect\G@refundefinedtrue\@latex@warning{reference #2 undefined}??%
|
||||||
|
}{%
|
||||||
|
\ifcsundef{sref@#3@URI}{%
|
||||||
|
\protect\G@refundefinedtrue\@latex@warning{external refs of type #3 undefined}??%
|
||||||
|
}{%
|
||||||
|
\edef\@uri{\@nameuse{sref@#3@URI}.pdf\#sref@#2@target}%
|
||||||
|
\edef\@label{\ifx\@linktext\@empty\@nameuse{sref@#2@label}\else\@linktext\fi}%
|
||||||
|
\sref@href@ifh\@uri\@label%
|
||||||
|
}%
|
||||||
|
}%
|
||||||
|
}%
|
||||||
|
\ifextrefs%
|
||||||
|
\newcommand\extref[3][]{%
|
||||||
|
\def\theextref{\sref@href[#1]{#2@#3}{#2}}%
|
||||||
|
\csname doextref@#2\endcsname%
|
||||||
|
}%
|
||||||
|
\else%
|
||||||
|
\newcommand\extref[3][]{\sref[#1]{#3}}%
|
||||||
|
\fi%
|
||||||
|
\ifextrefs%
|
||||||
|
\newcommand\extpageref[3][]{%
|
||||||
|
\def\theextref{\sref@pageref{#2@#3}}%
|
||||||
|
\csname doextpageref@#2\endcsname%
|
||||||
|
}%
|
||||||
|
\else%
|
||||||
|
\newcommand\extpageref[3][]{\spageref{#3}}%
|
||||||
|
\fi%
|
||||||
|
\newcommand\extrefstyle[2]{\csgdef{doextref@#1}{#2}}%
|
||||||
|
\newcommand\extpagerefstyle[2]{\csgdef{doextpageref@#1}{#2}}%
|
||||||
|
\newcommand\inputrefs[2]{%
|
||||||
|
%\@namedef{sref@#1@URI}{#2}%
|
||||||
|
\csdef{sref@#1@URI}{#2}%
|
||||||
|
\extrefstyle{#1}{\theextref}\extpagerefstyle{#1}{\theextref}%
|
||||||
\makeatletter%
|
\makeatletter%
|
||||||
\IfFileExists{#2.refs}{\input{#2.refs}}
|
\IfFileExists{#2.refs}{%
|
||||||
{\PackageError{sref}{Reference file #1.refs does not exist}
|
\message{Reading external references: #2.refs}\input{#2.refs}%
|
||||||
{Maybe you have to run LaTeX on #2.tex first}}
|
}{%
|
||||||
\makeatother}
|
\PackageError{sref}{Reference file #2.refs does not exist}%
|
||||||
\srefaddidkey{sequation}
|
{Maybe you have to run LaTeX on #2.tex first}}%
|
||||||
\def\sref@sequation@heading{equation}
|
\makeatother%
|
||||||
\newenvironment{sequation}[1][]{\metasetkeys{sequation}{#1}%
|
}%
|
||||||
\ifx\sref@id\@empty\begin{displaymath}\else% no id, using equation*
|
\srefaddidkey{sequation}%
|
||||||
\begin{equation}\sref@target\sref@label@id{\sref@sequation@heading~(\theequation)}\fi}
|
\def\sref@sequation@heading{equation}%
|
||||||
{\ifx\sref@id\@empty\end{displaymath}\else\end{equation}\fi}
|
\newenvironment{sequation}[1][]{%
|
||||||
\newenvironment{seqnarray}[1][]%
|
\metasetkeys{sequation}{#1}%
|
||||||
{\metasetkeys{sequation}{#1}\begin{eqnarray*}\sref@target%
|
\ifx\sref@id\@empty%
|
||||||
\sref@label@id{\sref@sequation@heading~(\theequation)}}
|
\begin{displaymath}%
|
||||||
{\end{eqnarray*}}
|
\else% no id, using equation*
|
||||||
\newcommand\withcite[2]{#2~\cite{#1}}
|
\begin{equation}%
|
||||||
\newenvironment{withcitation}[1]{\def\citeit{\cite{#1}}}{}
|
\sref@target\sref@label@id{\sref@sequation@heading~(\theequation)}%
|
||||||
|
\fi%
|
||||||
|
}{%
|
||||||
|
\ifx\sref@id\@empty%
|
||||||
|
\end{displaymath}%
|
||||||
|
\else%
|
||||||
|
\end{equation}%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
\newenvironment{seqnarray}[1][]{%
|
||||||
|
\metasetkeys{sequation}{#1}%
|
||||||
|
\begin{eqnarray*}%
|
||||||
|
\sref@target%
|
||||||
|
\sref@label@id{\sref@sequation@heading~(\theequation)}%
|
||||||
|
}{%
|
||||||
|
\end{eqnarray*}%
|
||||||
|
}%
|
||||||
|
\newcommand\withcite[2]{#2~\cite{#1}}%
|
||||||
|
\newenvironment{withcitation}[1]{\def\citeit{\cite{#1}}}{}%
|
||||||
\endinput
|
\endinput
|
||||||
%%
|
%%
|
||||||
%% End of file `sref.sty'.
|
%% End of file `sref.sty'.
|
||||||
|
Loading…
Reference in New Issue
Block a user