diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/stex/sref/sref.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/stex/sref/sref.dtx | 602 |
1 files changed, 301 insertions, 301 deletions
diff --git a/Master/texmf-dist/source/latex/stex/sref/sref.dtx b/Master/texmf-dist/source/latex/stex/sref/sref.dtx index dca5ed8371e..e21e5beb2ca 100644 --- a/Master/texmf-dist/source/latex/stex/sref/sref.dtx +++ b/Master/texmf-dist/source/latex/stex/sref/sref.dtx @@ -4,42 +4,44 @@ % this file is released under the % LaTeX Project Public License (LPPL) % -% The development version of this file can be found at -% $HeadURL: https://svn.kwarc.info/repos/stex/trunk/sty/sref/sref.dtx $ +% The original of this file is in the public repository at +% http://github.com/KWARC/sTeX/ % \fi % % \iffalse %<*package> \NeedsTeXFormat{LaTeX2e}[1999/12/01] -\ProvidesPackage{sref}[2012/01/28 v1.0 Semantic Cross-References] +\ProvidesPackage{sref}[2016/04/07 v1.2 Semantic Cross-References] %</package> %<*driver> \documentclass{ltxdoc} \usepackage{url,array,float} \usepackage[show]{ed} \usepackage[hyperref=auto,style=alphabetic]{biblatex} -\bibliography{kwarc} +\addbibresource{kwarcpubs.bib} +\addbibresource{extpubs.bib} +\addbibresource{kwarccrossrefs.bib} +\addbibresource{extcrossrefs.bib} \usepackage{stex-logo,sref} -\usepackage{../ctansvn} +\usepackage{ctangit} \usepackage{hyperref} -\usepackage[eso-foot,today]{svninfo} -\svnInfo $Id: sref.dtx 1999 2012-01-28 07:32:11Z kohlhase $ -\svnKeyword $HeadURL: https://svn.kwarc.info/repos/stex/trunk/sty/sref/sref.dtx $ \makeindex \floatstyle{boxed} \newfloat{exfig}{thp}{lop} \floatname{exfig}{Example} -\newcommand\tracissue[1]{\cite{sTeX:online}, \hyperlink{http://trac.kwarc.info/sTeX/ticket/#1}{issue #1}} +\newrobustcmd\tracissue[1]{\cite{sTeX:online}, \hyperlink{http://trac.kwarc.info/sTeX/ticket/#1}{issue #1}} \begin{document}\DocInput{sref.dtx}\end{document} %</driver> % \fi % -%\CheckSum{316} +%\CheckSum{352} % % \changes{v0.5}{2008/03/28}{split off from omdoc.sty} % \changes{v0.6}{2009/12/07}{introducing sequation} % \changes{v0.9}{2009/07/14}{using omd for metadata} % \changes{v1.0}{2011/12/20}{adding \texttt{\textbackslash sreflabel}} +% \changes{v1.1}{2013/10/15}{adding fallback argument to \texttt{\textbackslash sref}} +% \changes{v1.2}{2015/10/27}{\texttt{pre} and \texttt{post} keys to \texttt{\textbackslash sref}} % % \GetFileInfo{sref.sty} % @@ -87,15 +89,15 @@ % \section{The User Interface}\label{sec:user} % % This package is currently mainly meaningful in the context of the {\sTeX} collection, -% since all cross-referencable macros and environments must be extended to know about their -% referencing mechanism. We explain the user interface in \sref{sucrossref}. To -% port the functionality to other {\LaTeX} classes and packages, they have to be upgraded -% via the API in \sref{supackage-authors}. +% since all cross-referencable macros and environments must be extended to know about +% their referencing mechanism. We explain the user interface in \sref{sucrossref}. To port +% the functionality to other {\LaTeX} classes and packages, they have to be upgraded via +% the API in \sref{supackage-authors}. % % \subsection{Package Options}\label{sec:user:options} % % The |sref| package has the \DescribeMacro{extrefs}|extrefs| package option, which can be -% set to activate multifile support (see \sref{suinterdoc}). If the +% set to activate multi-file support (see \sref{suinterdoc}). If the % \DescribeMacro{showmeta}|showmeta| is set, then the metadata keys are shown % (see~\cite{Kohlhase:metakeys:ctan} for details and customization options). % @@ -105,13 +107,21 @@ % see Figure~\ref{fig:mysection} for an example. Depending on the whether macro or % environment marking up the respective document fragment carries the key/value pair % |id=|\meta{id} the cross-reference will expand to ``Section 2.1'' or ``this remark'', -% both carrying hyper-references. The |\sref| macro takes an optional argument that allows -% to specify a link text that overrides the auto-generated one. +% both carrying hyper-references. The |\sref| macro takes an optional key/value argument +% that allows to customize its behavior: The |linktext| key can be used to specify a link +% text that overrides the auto-generated one and the |fallback| allows to give the +% fallback text when the label \meta{id} is not defined. The |pre| and |post| keys allow +% to specify text that is pre/postpended to the generated label. This is particularly +% useful if combined with the |fallback| option as in the last |\sref| in +% Figure~\ref{fig:mysection}, where the generated ``in Section\ldots'' is equivalent to +% the fallback ``above''. % % \begin{exfig} % \begin{verbatim} % \mysection[id=foo]{#2} % ... \sref{foo} ... +% ... \sref[linktext=this section]{foo} ... +% ... \sref[pre={in~},fallback=above]{foo} ... % \end{verbatim} % \vspace*{-1.5em} % \caption{Semantic Crossreferencing}\label{fig:mysection} @@ -138,7 +148,7 @@ % styling the page reference. Redefining this will allows to customize this. The default % setting is % \begin{verbatim} -% \newcommand{\sref@page@label}[1]{p.~{#1}} +% \newcommand\sref@page@label[1]{p.~{#1}} % \end{verbatim} % % \subsection{An API for Package Authors}\sreflabel{Section}{supackage-authors} @@ -163,7 +173,7 @@ % \addmetakey{sec}{short} % \addmetakey[black]{sec}{color} % \srefaddidkey[prefix=sec.]{sec} -% \newcommand{\mysection}[2][]{\metasetkeys{#1}\sref@target\color{\sec@color} +% \newcommand\mysection[2][]{\metasetkeys{#1}\sref@target\color{\sec@color} % \section[\sec@short]{#2}\sref@label@id{Section \thesection}} % \end{verbatim} % \vspace*{-1.5em} @@ -172,7 +182,7 @@ % % In this situation, the |\mysection| macro processes the optional argument with % |\metasetkeys| and then sets the color of the section. The -% \DescribeMacro{\sref@target}|\sref@target| sets up the hypertarget for the |hyperref| +% \DescribeMacro{\sref@target}|\sref@target| sets up the hyper-target for the |hyperref| % package to use. Then we use the regular |\section| command, and we use the % \DescribeMacro{\sref@label@id}|\sref@label@id| macro to define the label that the % |\sref| macro will use for cross-referencing. @@ -185,8 +195,8 @@ % % \begin{exfig} % \begin{verbatim} -% \newcommand{\my@section@label}[1]{Section~{#1}} -% \newcommand{\mysection}[2][]{\metasetkeys{#1}\sref@target\color{\sec@color} +% \newcommand\my@section@label[1]{Section~{#1}} +% \newcommand\mysection[2][]{\metasetkeys{#1}\sref@target\color{\sec@color} % \section[\sec@short]{#2}\sref@label@id{\my@section@label\thesection}} % \end{verbatim} % \vspace*{-1.5em} @@ -204,7 +214,7 @@ % up paper driver files |main.tex| like the one in Figure~\ref{fig:paper-driver} in the % two directories. These use the \DescribeMacro{\makeextrefs}|\makeextrefs| macro, which % causes the |sref| package to generate a {\emph{external references file}} -% |main.refs|. Note that the |\makeextrefs| macros reads the previous |main.refs| file so +% |main.refs|. Note that the |\makeextrefs| macro reads the previous |main.refs| file so % that forward-referencing is possible (in the pass after a reference was labeled). % % \begin{exfig} @@ -232,7 +242,7 @@ % she has added |\makeextrefs{scr}| in the preamble of her paper). Note that just as the % |\sref| macro |\extref| takes an optional first argument that allows to specify the link % text. Here, John Bull uses the \DescribeMacro{\extrefstyle}|\extrefstyle| macro to -% specify how the externa references are to be formatted, in this case he decided to use a +% specify how the external references are to be formatted, in this case he decided to use a % {\LaTeX} citation. Generally, first argument of the |\extrefstyle| macro is the % reference prefix which should be configured, and the second is the format, where the % \DescribeMacro{\theextref}|\theextref| macro expands to the cross-reference. In this @@ -288,7 +298,7 @@ % \begin{sequation} % e^{mc}=-1 % \end{sequation} -% now, we reference the first equation: {\sref{foo}} +% now, we reference the first equation: \sref{foo} % \end{verbatim} % \vspace*{-1.5em}\hrule % yields the result:\hrule @@ -300,7 +310,7 @@ % \begin{sequation} % e^{mc}=-1 % \end{sequation} -% now, we reference the first equation: {\sref{foo}} +% now, we reference the first equation: \sref{foo} % \caption{Semantic Equation}\label{fig:sequation} % \end{exfig} % @@ -339,9 +349,11 @@ % % In this section we document known limitations. If you want to help alleviate them, % please feel free to contact the package author. Some of them are currently discussed in -% the \sTeX TRAC~\cite{sTeX:online}. +% the \sTeX GitHub repository~\cite{sTeX:github:on}. % \begin{compactenum} -% \item none reported yet +% \item currently only the |\sref| macro has a fallback argument. The others |\srefs| and +% |\srefl| and their external variants should also have them, but I am not clear what +% the adequate invocation pattern would be. % \end{compactenum} % % \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\printbibliography} @@ -349,22 +361,6 @@ % % \section{Implementation}\label{sec:impl} % -% The |sref| package generates two files: the {\LaTeX} package (all the code between -% {\textsf{$\langle$*package$\rangle$}} and {\textsf{$\langle$/package$\rangle$}}) and the -% {\latexml} bindings (between {\textsf{$\langle$*ltxml$\rangle$ and -% $\langle$/ltxml$\rangle$}}). We keep the corresponding code fragments together, -% since the documentation applies to both of them and to prevent them from getting out of -% sync. -% -% We first set up header information for the {\latexml} binding file. -% \begin{macrocode} -%<*ltxml> -package LaTeXML::Package::Pool; -use strict; -use LaTeXML::Package; -%</ltxml> -% \end{macrocode} -% % \subsection{Package Options}\label{sec:impl:options} % % We declare some switches which will modify the behavior according to the package @@ -373,24 +369,19 @@ use LaTeXML::Package; % % \begin{macrocode} %<*package> -\DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}} \newif\ifextrefs\extrefsfalse \DeclareOption{extrefs}{\extrefstrue} +\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{metakeys}} \ProcessOptions -%</package> -%<*ltxml> -DeclareOption('extrefs',''); -%</ltxml> % \end{macrocode} % % Then we need to set up the packages by requiring the |metakeys| package~\ctancite{Kohlhase:metakeys} % to be loaded (in the right version). % % \begin{macrocode} -%<*package> \RequirePackage{metakeys} -%</package> -%<ltxml>RequirePackage('metakeys'); +\RequirePackage{xspace} +\RequirePackage{etoolbox} % \end{macrocode} % % \subsection{Crossreferencing}\label{sec:impl:crossref} @@ -400,55 +391,60 @@ DeclareOption('extrefs',''); % stubs to make the error messages shut up.} % % \begin{macro}{\sref} +% First we declare the keys for |\sref|. |\sref@part| will be globally defined when +% |\makeextrefs| is called. % \begin{macrocode} -%<*package> -\newcommand{\sref}[2][]{% -\@ifundefined{sref@part}{\sref@hlink[#1]{#2}}{\sref@hlink[#1]{\sref@part @#2}}} -%</package> -%<*ltxml> -sub withhash {'#';} -DefConstructor('\sref[]{}', - "<omdoc:oref href='&withhash()#2'/>"); -%</ltxml> +\addmetakey{sref}{linktext} +\addmetakey{sref}{fallback} +\addmetakey{sref}{pre} +\addmetakey{sref}{post} +\newcommand\sref[2][]{% + \metasetkeys{sref}{#1}% + \ifcsundef{sref@part}{% + \sref@hlink[\sref@linktext]{#2}{\sref@fallback}{\sref@pre}{\sref@post}% + }{% + \sref@hlink[\sref@linktext]{\sref@part @#2}{\sref@fallback}{\sref@pre}{\sref@post}% + }% + \xspace% +}% % \end{macrocode} % \end{macro} % % \begin{macro}{\srefs} % \begin{macrocode} -%<*package> -\newcommand{\srefs}[3][]{% -\def\@test{#1}\ifx\@test\@empty\sref{#2} and \sref{#3}\else #1\fi} -%</package> -%<*ltxml> -DefConstructor('\srefs[]{}', - "<omdoc:oref href='&withhash()#2'/>"); -%</ltxml> +\newcommand\srefs[3][]{% + \def\@test{#1}% + \ifx\@test\@empty% + \sref{#2} and \sref{#3}% + \else% + #1% + \fi% +}% % \end{macrocode} % \end{macro} % % \begin{macro}{\srefl} % \begin{macrocode} -%<*package> -\newcommand{\srefl}[3][]{% -\def\@test{#1}\ifx\@test\@empty\sref{#2} to \sref{#3}\else #1\fi} -%</package> -%<*ltxml> -DefConstructor('\srefl[]{}', - "<omdoc:oref href='&withhash()#2'/>"); -%</ltxml> +\newcommand\srefl[3][]{% + \def\@test{#1}% + \ifx\@test\@empty% + \sref{#2} to \sref{#3}% + \else% + #1% + \fi% +}% % \end{macrocode} % \end{macro} % \ednote{it is not clear what we want in the LaTeXML implementation of spageref} % \begin{macro}{\spageref} % \begin{macrocode} -%<*package> -\newcommand{\spageref}[1]{% -\@ifundefined{sref@part}{\sref@pageref{#1}}{\sref@pageref{\sref@part @#1}}} -%</package> -%<*ltxml> -DefConstructor('\spageref{}', - "<omdoc:oref href='&withhash()#1'/>"); -%</ltxml> +\newcommand\spageref[1]{% + \ifcsundef{sref@part}{% + \sref@pageref{#1}% + }{% + \sref@pageref{\sref@part @#1}% + }% +}% % \end{macrocode} % \end{macro} % @@ -460,12 +456,35 @@ DefConstructor('\spageref{}', % % \begin{macro}{\sref@*@ifh} % \begin{macrocode} -%<*package> -\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} +\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% +}% % \end{macrocode} % \end{macro} % @@ -475,10 +494,14 @@ DefConstructor('\spageref{}', % The next macro uses this and makes an target from the current |sref@id| declared by % a |id| key. % \begin{macrocode} -\def\sref@target% -{\ifx\sref@id\@empty\else% -\edef\@target{sref@\@ifundefined{sref@part}{}{\sref@part @}\sref@id @target} -\sref@target@ifh\@target{}\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% +}% % \end{macrocode} % \end{macro} % @@ -488,21 +511,28 @@ DefConstructor('\spageref{}', % \begin{macro}{\@sref@def} % This macro stores the value of its last argument in a custom macro for reference. % \begin{macrocode} -\newcommand\@sref@def[3]{\expandafter\gdef\csname sref@#1@#2\endcsname{#3}} +%\newcommand\@sref@def[3]{\expandafter\gdef\csname sref@#1@#2\endcsname{#3}} +\newcommand\@sref@def[3]{\csgdef{sref@#1@#2}{#3}} % \end{macrocode} % \end{macro} % % The next step is to set up a file to which the references are written, this is normally % the |.aux| file, but if the |extref| option is set, we have to use an |.ref| file. % \begin{macrocode} -\ifextrefs\newwrite\refs@file\else\def\refs@file{\@auxout}\fi +\ifextrefs% + \newwrite\refs@file% +\else% + \def\refs@file{\@auxout}% +\fi% % \end{macrocode} % % \begin{macro}{\sref@def} % This macro writes an |\@sref@def| command to the current aux file and also executes it. % \begin{macrocode} -\newcommand\sref@def[3]{%\@sref@def{#1}{#2}{#3}% -\protected@write\refs@file{}{\string\@sref@def{#1}{#2}{#3}}} +\newcommand\sref@def[3]{% + %\@sref@def{#1}{#2}{#3}% + \protected@write\refs@file{}{\string\@sref@def{#1}{#2}{#3}}% +}% % \end{macrocode} % \end{macro} % @@ -515,13 +545,17 @@ DefConstructor('\spageref{}', % used for showing metadata via the |showmeta| option of the |metakeys| package. % \begin{macrocode} \addmetakey{srefaddidkey}{prefix} -\newcommand\srefaddidkey[2][]{\metasetkeys{srefaddidkey}{#1}% -\@metakeys@ext@clear@keys{#2}{sref@id}{}% id cannot have a default -\metakeys@ext@clear@keys{#2}{id}{}% -\metakeys@ext@showkeys{#2}{id}% -\define@key{#2}{id}{\edef\sref@id{\srefaddidkey@prefix ##1}% -\expandafter\edef\csname #2@id\endcsname{\srefaddidkey@prefix ##1}}} -%</package> +\newcommand\srefaddidkey[2][]{% + \metasetkeys{srefaddidkey}{#1}% + \@metakeys@ext@clear@keys{#2}{sref@id}{}% id cannot have a default + \metakeys@ext@clear@keys{#2}{id}{}% + \metakeys@ext@showkeys{#2}{id}% + \define@key{#2}{id}{% + \edef\sref@id{\srefaddidkey@prefix ##1}% + %\expandafter\edef\csname #2@id\endcsname{\srefaddidkey@prefix ##1}% + \csedef{#2@id}{\srefaddidkey@prefix ##1}% + }% +}% % \end{macrocode} % \end{macro} % @@ -529,25 +563,23 @@ DefConstructor('\spageref{}', % % \begin{macro}{\makeextrefs} % \begin{macrocode} -%<*package> -\newcommand\makeextrefs[1]{\gdef\sref@part{#1}% -\makeatletter -\IfFileExists{\jobname.refs}{\input{\jobname.refs}}{}% -\immediate\openout\refs@file=\jobname.refs -\makeatother} -%</package> -%<ltxml>DefConstructor('\makeextrefs{}',''); +\newcommand\makeextrefs[1]{% + \gdef\sref@part{#1}% + \makeatletter% + \IfFileExists{\jobname.refs}{\input{\jobname.refs}}{}% + \immediate\openout\refs@file=\jobname.refs + \makeatother% +}% % \end{macrocode} % \end{macro} % % \begin{macro}{\sref@label} % The |\sref@label| macro writes a label definition to the auxfile. % \begin{macrocode} -%<*package> \newcommand\sref@label[2]{% -\sref@def{\@ifundefined{sref@part}{}{\sref@part @}#2}{page}{\thepage}% -\sref@def{\@ifundefined{sref@part}{}{\sref@part @}#2}{label}{#1}} -%</package> + \sref@def{\ifcsundef{sref@part}{}{\sref@part @}#2}{page}{\thepage}% + \sref@def{\ifcsundef{sref@part}{}{\sref@part @}#2}{label}{#1}% +}% % \end{macrocode} % \end{macro} % @@ -555,9 +587,7 @@ DefConstructor('\spageref{}', % The |\sreflabel| macro is a semantic version of |\label|, it combines the categorization % given in the first argument with {\LaTeX}'s |\@currentlabel|. % \begin{macrocode} -%<*package> -\newcommand\sreflabel[2]{\message{sreflabel: #1, #2}\sref@label{#1 \@currentlabel}{#2}} -%</package> +\newcommand\sreflabel[2]{\sref@label{#1 \@currentlabel}{#2}} % \end{macrocode} % \end{macro} % @@ -565,9 +595,13 @@ DefConstructor('\spageref{}', % The |\sref@label@id| writes a label definition for the current |\sref@id| if it is % defined. % \begin{macrocode} -%<*package> -\newcommand\sref@label@id[1]{\ifx\sref@id\@empty\else\sref@label{#1}{\sref@id}\fi} -%</package> +\newcommand\sref@label@id[1]{% + \ifx\sref@id\@empty% + \relax% + \else% + \sref@label{#1}{\sref@id}% + \fi% +}% % \end{macrocode} % \end{macro} % @@ -576,26 +610,43 @@ DefConstructor('\spageref{}', % yet.} % % \begin{macro}{\sref@hlink} -% |\sref@hlink[|\meta{alt}|]{|\meta{label}|}|creates an error message if the target -% specified by \meta{label} is not defined, and otherwise generates a hyperlinked -% reference whose link text is \meta{alt} (if the optional argument is given) and the -% label generated by object specified by \meta{label} otherwise. +% |\sref@hlink[|\meta{alt}|]{|\meta{label}|}{|\meta{fallback}|}{|\meta{pre}|}{|\meta{post}|}| +% creates an error message if the target specified by \meta{label} is not defined (but +% uses \meta{fallback} if provided), and otherwise generates a hyperlinked reference +% whose link text is \meta{alt} (if the optional argument is given) and the label +% generated by object specified by \meta{label} otherwise. % \begin{macrocode} -%<*package> -\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}}} -%</package> +\newcommand\sref@hlink[5][]{% + \edef\@linktext{#1}% + \edef\@fallback{#3}% + \ifcsundef{sref@#2@label}{% + \ifx\@fallback\@empty% warn about undefined links and show a substitute + \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 + }{% + \edef\@link{#4\@nameuse{sref@#2@label}#5}% retrieve the reference label and prepost it + \ifx\@linktext\@empty% + \sref@hlink@ifh{sref@#2@target}{\@link}% + \else% + \sref@hlink@ifh{sref@#2@target}{\@linktext}% + \fi% + }% +}% % \end{macrocode} % \end{macro} % % \begin{macro}{\sref@page@label} % This macro styles a page reference. % \begin{macrocode} -%<*package> -\newcommand{\sref@page@label}[1]{p.~{#1}} -%</package> +\newcommand\sref@page@label[1]{p.~{#1}} % \end{macrocode} % \end{macro} % @@ -603,11 +654,13 @@ DefConstructor('\spageref{}', % The next macro creates an error message if the target is not defined, and otherwise % generates a page reference. % \begin{macrocode} -%<*package> -\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}}}}} -%</package> +\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}}}% + }% +}% % \end{macrocode} % \end{macro} % @@ -615,60 +668,54 @@ DefConstructor('\spageref{}', % The next macro creates an error message if the target is not defined, and otherwise % generates a hyperlinked reference. % \begin{macrocode} -%<*package> -\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}}} -%</package> +\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% + }% + }% +}% % \end{macrocode} % \end{macro} % % \begin{macro}{\extref} -% The next macros use |\sref@hlink| with the respective prefix for external referencing +% The next macros use |\sref@href| with the respective prefix for external referencing % if external references are used as indicated by the |extrefs| option; otherwise it % disregards the first required macro and uses internal referencing.\ednote{This needs % to be implemented on the LaTeXML side.} % \begin{macrocode} -%<*package> -\ifextrefs -\newcommand{\extref}[3][]{\def\theextref{\sref@href[#1]{#2@#3}{#2}}% -\csname doextref@#2\endcsname} -\else -\newcommand{\extref}[3][]{\sref[#1]{#3}} -\fi -%</package> -%<*ltxml> -DefConstructor('\extref[]{}{}', - "<omdoc:oref href='#2@#3'/>"); -DefConstructor('\theextref',''); -%</ltxml> +\ifextrefs% + \newcommand\extref[3][]{% + \def\theextref{\sref@href[#1]{#2@#3}{#2}}% + \csname doextref@#2\endcsname% + }% +\else% + \newcommand\extref[3][]{\sref[#1]{#3}}% +\fi% % \end{macrocode} % \end{macro} % % \begin{macro}{\extpageref} -% The next macros use |\sref@hlink| with the respective prefix for external referencing +% The next macros use |\sref@pagref| with the respective prefix for external referencing % if external references are used as indicated by the |extrefs| option; otherwise it % disregards the first required macro and uses internal referencing.\ednote{This needs -% to be implemented on the LaTeXML side.} +% to be implemented on the LaTeXML side.} % \begin{macrocode} -%<*package> -\ifextrefs -\newcommand{\extpageref}[3][]{\def\theextref{\sref@pageref[#1]{#2@#3}{#2}}% -\csname doextpageref@#2\endcsname} -\else -\newcommand{\extpageref}[3][]{\spageref[#1]{#3}} -\fi -%</package> -%<*ltxml> -DefConstructor('\extpageref[]{}{}', - "<omdoc:oref href='#2@#3'/>"); -DefConstructor('\theextref',''); -%</ltxml> +\ifextrefs% + \newcommand\extpageref[3][]{% + \def\theextref{\sref@pageref{#2@#3}}% + \csname doextpageref@#2\endcsname% + }% +\else% + \newcommand\extpageref[3][]{\spageref{#3}}% +\fi% % \end{macrocode} % \end{macro} % @@ -677,24 +724,16 @@ DefConstructor('\theextref',''); % instance |\extrefstyle{foo}{\theextref in bar}| defines the macro |\doextref@foo| % which evaluates to \meta{the reference} |in bar|. This is used in the |\extref| macro. % \begin{macrocode} -%<*package> -\newcommand\extrefstyle[2]{\expandafter\gdef\csname doextref@#1\endcsname{#2}} -%</package> -%<*ltxml> -DefConstructor('\extrefstyle{}{}',""); -%</ltxml> +%\newcommand\extrefstyle[2]{\expandafter\gdef\csname doextref@#1\endcsname{#2}}% +\newcommand\extrefstyle[2]{\csgdef{doextref@#1}{#2}}% % \end{macrocode} % \end{macro} % % \begin{macro}{\extpagerefstyle} % This is analogous to |\extrefstyle| % \begin{macrocode} -%<*package> -\newcommand\extpagerefstyle[2]{\expandafter\gdef\csname doextpageref@#1\endcsname{#2}} -%</package> -%<*ltxml> -DefConstructor('\extrefstyle{}{}',""); -%</ltxml> +%\newcommand\extpagerefstyle[2]{\expandafter\gdef\csname doextpageref@#1\endcsname{#2}}% +\newcommand\extpagerefstyle[2]{\csgdef{doextpageref@#1}{#2}}% % \end{macrocode} % \end{macro} % @@ -702,18 +741,18 @@ DefConstructor('\extrefstyle{}{}',""); % If the external references file exists, it is read (under the protection of % |\makeatother|) otherwise an error message is displayed. % \begin{macrocode} -%<*package> -\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} -%</package> -%<*ltxml> -DefConstructor('\inputrefs{}{}',''); -%</ltxml> +\newcommand\inputrefs[2]{% + %\@namedef{sref@#1@URI}{#2}% + \csdef{sref@#1@URI}{#2}% + \extrefstyle{#1}{\theextref}\extpagerefstyle{#1}{\theextref}% + \makeatletter% + \IfFileExists{#2.refs}{% + \message{Reading external references: #2.refs}\input{#2.refs}% + }{% + \PackageError{sref}{Reference file #2.refs does not exist}% + {Maybe you have to run LaTeX on #2.tex first}}% + \makeatother% +}% % \end{macrocode} % \end{macro} % @@ -721,42 +760,36 @@ DefConstructor('\inputrefs{}{}',''); % % \begin{environment}{sequation} % \begin{macrocode} -%<*package> -\srefaddidkey{sequation} -\def\sref@sequation@heading{equation} -\newenvironment{sequation}[1][]{\metasetkeys{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} -%</package> -%<*ltxml> -DefEnvironment('{sequation} OptionalKeyVals', - "<ltx:equation " - . "?&KeyVal(#1,'id')(xml:id='&KeyVal(#1,'id')' " - . "refnum='#refnum')(xml:id='#id')>" - . "<ltx:Math mode='display'>" - . "<ltx:XMath>#body</ltx:XMath>" - . "</ltx:Math>" - . "</ltx:equation>", - mode=>'display_math', - properties=> sub { RefStepCounter('equation') }, - locked=>1); -%</ltxml> +\srefaddidkey{sequation}% +\def\sref@sequation@heading{equation}% +\newenvironment{sequation}[1][]{% + \metasetkeys{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% +}% % \end{macrocode} % \end{environment} % % \begin{environment}{seqnarray} % \begin{macrocode} -%<*package> -\newenvironment{seqnarray}[1][]% -{\metasetkeys{sequation}{#1}\begin{eqnarray*}\sref@target% -\sref@label@id{\sref@sequation@heading~(\theequation)}} -{\end{eqnarray*}} -%</package> -%<*ltxml> -DefMacro('\seqnarray OptionalKeyVals','\begin{eqnarray*}'); -DefMacro('\endseqnarray','\end{eqnarray*}'); -%</ltxml> +\newenvironment{seqnarray}[1][]{% + \metasetkeys{sequation}{#1}% + \begin{eqnarray*}% + \sref@target% + \sref@label@id{\sref@sequation@heading~(\theequation)}% +}{% + \end{eqnarray*}% +}% % \end{macrocode} % \end{environment} % @@ -764,50 +797,16 @@ DefMacro('\endseqnarray','\end{eqnarray*}'); % % \begin{macro}{withcite} % \begin{macrocode} -%<*package> -\newcommand\withcite[2]{#2~\cite{#1}} -%</package> -%<*ltxml> -DefMacro('\withcite{}{}','\begin{withcitation}{#1}#2\citeit\end{withcitation}'); -%</ltxml> +\newcommand\withcite[2]{#2~\cite{#1}}% % \end{macrocode} % \end{macro} % % \begin{environment}{withcitation} % \begin{macrocode} -%<*package> -\newenvironment{withcitation}[1]{\def\citeit{\cite{#1}}}{} +\newenvironment{withcitation}[1]{\def\citeit{\cite{#1}}}{}% %</package> -%<*ltxml> -DefConstructor('\citeit',"<omdoc:citation/> ", -afterConstruct => sub { - my ($document,$whatsit) = @_; - # LibXML acrobatics, since we can't talk about the xml:id prior to construction's end - # (and please do correct me if this is inaccurate) - my $node = $document->getNode; - my ($citenode) = $document->findnodes('preceding-sibling::omdoc:citation',$node); - my ($phrase_parent) = $document->findnodes('ancestor::ltx:text[@xml:id]',$node); - return unless (defined $phrase_parent) && (defined $citenode); - my $id = $phrase_parent->getAttribute('xml:id'); - my $refs = $phrase_parent->getAttribute('citeit-refs'); - $phrase_parent->removeAttribute('citeit-refs'); - $citenode->setAttribute('for',$id); - $citenode->setAttribute('refs',$refs); -});#$ -DefEnvironment('{withcitation}{}', - "<ltx:text citeit-refs='#1'>#body</ltx:text>"); -%</ltxml> % \end{macrocode} % \end{environment} -% -% \subsection{Finale}\label{sec:common} -% -% Finally, we need to terminate the file with a success mark for perl. -% \begin{macrocode} -%<*ltxml> -1; -%</ltxml> -% \end{macrocode} % \Finale \endinput % \iffalse @@ -817,34 +816,35 @@ DefEnvironment('{withcitation}{}', %%% End: % \fi -% LocalWords: GPL structuresharing STR omdoc dtx stex CPERL LoadClass url dc -% LocalWords: RequirePackage RegisterNamespace namespace xsl DocType ltxml dtd -% LocalWords: ltx DefEnvironment beforeDigest AssignValue inPreamble getGullet -% LocalWords: afterDigest keyval omgroup DefKeyVal Semiverbatim KeyVal iffalse -% LocalWords: OptionalKeyVals DefParameterType IfBeginFollows skipSpaces CMP -% LocalWords: ifNext DefMacro needwrapper unlist DefConstructor omtext bgroup -% LocalWords: useCMPItemizations RefStepItemCounter egroup beginItemize li di -% LocalWords: beforeDigestEnd useTheoryItemizations dt autoclose ul ol dl env -% LocalWords: afterOpen LastSeenCMP autoClose proto ToString textsuperscript -% LocalWords: addAttribute nlex nlcex omdocColorMacro args tok MergeFont qw -% LocalWords: TokenizeInternal toString isMath foreach maybeCloseElement id'd -% LocalWords: autoOpen minipage footnotesize scriptsize numberIt whatsit href -% LocalWords: getAttribute setAttribute OMDoc RelaxNGSchema noindex xml lec -% LocalWords: Subsubsection useDefaultItemizations refundefinedtrue blockquote -% LocalWords: DefCMPConstructor inlinequote idx idt ide idp emph sref extrefs -% LocalWords: flushleft flushright DeclareOption hyperref LaTeX tex pdf hlink -% LocalWords: sequation omd def texorpdfstring raisebox latexml texttt newpage -% LocalWords: fileversion maketitle tableofcontents autoref hpyerref mysection -% LocalWords: exfig vspacesrefaddidkey srefaddidkey scr vspace withcite LasSwi -% LocalWords: makeextrefs inputrefs extref foo Patashnik withcite biblatex10 -% LocalWords: extrefstyle theextref theextref displaymath hrule impl ednote -% LocalWords: printbibliography newif ifextrefs extrefsfalse extrefstrue srefs -% LocalWords: Crossreferencing newcommand ifundefined ifx srefl xref ifh gdef -% LocalWords: ifhref hreffalse ifpackageloaded hreftrue expandafter jobname -% LocalWords: jobname csname endcsname newwrite auxout makeatletter openout -% LocalWords: makeatother auxfile nameuse doextref namedef newenvironment -% LocalWords: theequation refnum refnum seqnarray eqnarray endseqnarray doctex -% LocalWords: textsuperscript spageref spageref thepage pageref ctancite rdf99 +% LocalWords: GPL structuresharing STR omdoc dtx stex CPERL LoadClass url dc sreflabel +% LocalWords: RequirePackage RegisterNamespace namespace xsl DocType ltxml dtd filedate +% LocalWords: ltx DefEnvironment beforeDigest AssignValue inPreamble getGullet slabel +% LocalWords: afterDigest keyval omgroup DefKeyVal Semiverbatim KeyVal iffalse rangle +% LocalWords: OptionalKeyVals DefParameterType IfBeginFollows skipSpaces CMP sucrossref +% LocalWords: ifNext DefMacro needwrapper unlist DefConstructor omtext bgroup suinterdoc +% LocalWords: useCMPItemizations RefStepItemCounter egroup beginItemize li di rangle +% LocalWords: beforeDigestEnd useTheoryItemizations dt autoclose ul ol dl env xspace +% LocalWords: afterOpen LastSeenCMP autoClose proto ToString textsuperscript withhash +% LocalWords: addAttribute nlex nlcex omdocColorMacro args tok MergeFont qw oref XMath +% LocalWords: TokenizeInternal toString isMath foreach maybeCloseElement id'd extpageref +% LocalWords: autoOpen minipage footnotesize scriptsize numberIt whatsit href citenode +% LocalWords: getAttribute setAttribute OMDoc RelaxNGSchema noindex xml lec hypertarget +% LocalWords: Subsubsection useDefaultItemizations refundefinedtrue blockquote findnodes +% LocalWords: DefCMPConstructor inlinequote idx idt ide idp emph sref extrefs endinput +% LocalWords: flushleft flushright DeclareOption hyperref LaTeX tex pdf hlink behavior +% LocalWords: sequation omd def texorpdfstring raisebox latexml texttt newpage etoolbox +% LocalWords: fileversion maketitle tableofcontents autoref hpyerref mysection ifcsundef +% LocalWords: exfig vspacesrefaddidkey srefaddidkey scr vspace withcite LasSwi csgdef +% LocalWords: makeextrefs inputrefs extref foo Patashnik withcite biblatex10 sref@pagref +% LocalWords: extrefstyle theextref theextref displaymath hrule impl ednote sref@ifundef +% LocalWords: printbibliography newif ifextrefs extrefsfalse extrefstrue srefs csedef +% LocalWords: Crossreferencing newrobustcmd ifundefined ifx srefl xref ifh gdef csdef +% LocalWords: ifhref hreffalse ifpackageloaded hreftrue expandafter jobname doextpageref +% LocalWords: jobname csname endcsname newwrite auxout makeatletter openout initialize +% LocalWords: makeatother auxfile nameuse doextref namedef newenvironment NeedsTeXFormat +% LocalWords: theequation refnum refnum seqnarray eqnarray endseqnarray doctex ldots +% LocalWords: textsuperscript spageref spageref thepage pageref ctancite rdf99 prepost % LocalWords: cross-referencable showmeta showmeta metakeys metasetkeys textsf % LocalWords: addmetakey referencable langle textsf langle withcitation citeit -% LocalWords: compactenum +% LocalWords: compactenum textbackslash supackage-authors extpagerefstyle customization +% LocalWords: categorization postpended |