w23-logic-3/jrpie-yaref.sty
2023-10-13 23:33:24 +02:00

50 lines
1.5 KiB
TeX

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{jrpie-yaref}[2023/07/28 - yet another ref]
\RequirePackage{hyperref}
\RequirePackage{amstext}
\newcommand{\yaref@text@large}[1]{%
\ifcsname yaref@longlabel@#1\endcsname%
\hyperref[#1]{\csname yaref@longlabel@#1\endcsname\ (\ref*{#1})}%
\else%
\autoref{#1}%
\fi%
}
\newcommand{\yaref@text@small}[1]{%
\ifcsname yaref@shortlabel@#1\endcsname%
\hyperref[#1]{\csname yaref@shortlabel@#1\endcsname}%
\else%
(\ref{#1})%
\fi%
}
\newcommand{\yaref@math@large}[1]{%
\text{\yaref@text@large{#1}}%
}
\newcommand{\yaref@math@small}[1]{%
\text{\yaref@text@small{#1}}%
}
\newcommand{\yaref@math@verysmall}[1]{%
\yaref@math@small{#1}%
}
\newcommand{\yalabel}[3]{%
\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname yaref@longlabel@#3\noexpand\endcsname{#1}}%
\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname yaref@shortlabel@#3\noexpand\endcsname{#2}}%
\expandafter\gdef\csname yaref@longlabel@#3\endcsname{#1}%
\expandafter\gdef\csname yaref@shortlabel@#3\endcsname{#2}%
\label{#3}%
}
\newcommand{\yaref}[1]{%
\relax\ifmmode%
\mathchoice
{\yaref@math@large{#1}} % display style
{\yaref@math@large{#1}} % text style
{\yaref@math@small{#1}} % script style
{\yaref@math@verysmall{#1}} % scriptscript style
\else%
\yaref@text@large{#1}%
\fi%
}