summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/stex/sref/sref.sty
blob: 52f4b1c7d12742c51724148b413fbac50802fcdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
%%
%% This is file `sref.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% sref.dtx  (with options: `package')
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{sref}[2010/06/25 v0.9 Semantic Cross-References]
\newif\ifextrefs\extrefsfalse
\DeclareOption{extrefs}{\extrefstrue}
\ProcessOptions
\RequirePackage{omd}
\newcommand{\sref}[2][]{%
\@ifundefined{sref@part}{\sref@hlink[#1]{#2}}{\sref@hlink[#1]{\sref@part @#2}}}
\newcommand{\srefs}[3][]{%
\def\@test{#1}\ifx\@test\@empty\sref{#2} and \sref{#3}\else #1\fi}
\newcommand{\srefl}[3][]{%
\def\@test{#1}\ifx\@test\@empty\sref{#2} to \sref{#3}\else #1\fi}
\newcommand{\spageref}[2][]{%
\@ifundefined{sref@part}{\sref@hlink[#1]{#2}}{\sref@hlink[#1]{\sref@part @#2}}}
\newif\ifhref\hreffalse
\AtBeginDocument{\@ifpackageloaded{hyperref}{\hreftrue}{\hreffalse}}
\def\sref@href@ifh#1#2{\ifhref\href{#1}{#2}\else#2\fi}
\def\sref@hlink@ifh#1#2{\ifhref\hyperlink{#1}{#2}\else#2\fi}
\def\sref@target@ifh#1#2{\ifhref\hypertarget{#1}{#2}\else#2\fi}
\def\sref@target%
{\ifx\sref@id\@empty\else%
\expandafter\sref@target@ifh%
{sref@\@ifundefined{sref@part}{}{\sref@part @}\sref@id @target}{}\fi}
\def\@sref@def#1#2#3{\expandafter\gdef\csname sref@#1@#2\endcsname{#3}}
\ifextrefs\newwrite\refs@file\else\def\refs@file{\@auxout}\fi
\def\sref@def#1#2#3{%\@sref@def{#1}{#2}{#3}%
\protected@write\refs@file{}{\string\@sref@def{#1}{#2}{#3}}}
\omdaddkey{srefaddidkey}{prefix}
\newcommand\srefaddidkey[2][]{\omdsetkeys{srefaddidkey}{#1}%
\@omd@ext@clear@keys{#2}{sref@id}{}% id cannot have a default
\define@key{#2}{id}{\edef\sref@id{\srefaddidkey@prefix ##1}}}
\def\makeextrefs#1{\gdef\sref@part{#1}%
\makeatletter
\IfFileExists{\jobname.refs}{\input{\jobname.refs}}{}%
\immediate\openout\refs@file=\jobname.refs
\makeatother}
\def\sref@label#1#2{%
\sref@def{\@ifundefined{sref@part}{}{\sref@part @}#2}{page}{\thepage}
\sref@def{\@ifundefined{sref@part}{}{\sref@part @}#2}{label}{#1}}
\def\sref@label@id#1{\ifx\sref@id\@empty\else\sref@label{#1}{\sref@id}\fi}
\newcommand{\sref@hlink}[2][]{\def\@test{#1}%
\@ifundefined{sref@#2@label}%
{\protect\G@refundefinedtrue\@latex@warning{reference #2 undefined}??}%
{\sref@hlink@ifh{sref@#2@target}{\ifx\@test\@empty\@nameuse{sref@#2@label}\else #1\fi}}}
\newcommand{\sref@page@label}[1]{p.~{#1}}
\newcommand{\sref@pageref}[1]{\@ifundefined{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][]{\def\@test{#1}%
\@ifundefined{sref@#2@label}%
{\protect\G@refundefinedtrue\@latex@warning{reference #2 undefined}??}%
{\@ifundefined{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\@test\@empty\@nameuse{sref@#2@label}\else #1\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
\def\extrefstyle#1#2{\expandafter\gdef\csname doextref@#1\endcsname{#2}}
\newcommand{\inputrefs}[2]{%
\@namedef{sref@#1@URI}{#2}
\makeatletter%
\IfFileExists{#2.refs}{\input{#2.refs}}
             {\PackageError{sref}{Reference file #1.refs does not exist}
                                 {Maybe you have to run LaTeX on #2.tex first}}
\makeatother}
\srefaddidkey{sequation}
\def\sref@sequation@heading{equation}
\newenvironment{sequation}[1][]{\omdsetkeys{sequation}{#1}%
\ifx\sref@id\@empty\begin{displaymath}\else% no id, using equation*
\begin{equation}\sref@target\sref@label@id{\sref@sequation@heading~(\theequation)}\fi}
{\ifx\sref@id\@empty\end{displaymath}\else\end{equation}\fi}
\newenvironment{seqnarray}[1][]%
{\omdsetkeys{sequation}{#1}\begin{eqnarray*}\sref@target%
\sref@label@id{\sref@sequation@heading~(\theequation)}}
{\end{eqnarray*}}
\endinput
%%
%% End of file `sref.sty'.