summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-10-30 21:48:35 +0000
committerKarl Berry <karl@freefriends.org>2016-10-30 21:48:35 +0000
commit4ac92763388117ee6c055f0b76f64a143c447afe (patch)
tree0605704a9620c3629658349ff8864245296e37ac /Master/texmf-dist/tex
parent6459918940d7443298637e484ccc34677ddb9b7b (diff)
wtref (30oct16)
git-svn-id: svn://tug.org/texlive/trunk@42388 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/latex/wtref/wtref.sty166
1 files changed, 166 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/wtref/wtref.sty b/Master/texmf-dist/tex/latex/wtref/wtref.sty
new file mode 100644
index 00000000000..7b0c2281929
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/wtref/wtref.sty
@@ -0,0 +1,166 @@
+%
+% wtref.sty
+%
+
+%%%% package declaration
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{wtref}[2016/08/09 v0.3.1]
+\def\wtrf@pkgname{WTRef}
+\RequirePackage{xkeyval}
+
+%%%% error messages
+\def\wtrf@info{\PackageInfo\wtrf@pkgname}
+\def\wtrf@error{\PackageError\wtrf@pkgname}
+
+%%%% new ifs and new counts
+\newif\if@wtrf@use@scope@
+\newif\if@wtrf@use@namespace@
+\newif\if@wtrf@set@namespace@
+\newcount\wtrf@tempcnta
+\newcount\wtrf@tempcntb
+
+%%%% utility
+\def\wtrf@name@def#1{\expandafter\def\csname #1\endcsname}
+\def\wtrf@name@edef#1{\expandafter\edef\csname #1\endcsname}
+\def\wtrf@name@use#1{\csname #1\endcsname}
+\def\wtrf@if@option@exist{\@ifnextchar[}
+\def\wtrf@if@reftype@not@exist#1{\@ifundefined{wtrf@#1@namespace}}
+
+%%%% check commands
+\def\wtrf@check@counter#1{%
+ \@ifundefined{c@#1}
+ {\wtrf@error{Undefined LaTeX counter '#1'}}
+ {}}
+\def\wtrf@check@command#1{%
+ \@ifundefined{#1}
+ {}
+ {\wtrf@info{Redefining \expandafter\string\csname#1\endcsname}}}
+
+%%%% trimming spaces
+\define@cmdkeys[wtrf]{ts}[wtrf@temp@]{ref@name, label}
+\def\wtrf@set@ref@name#1{\setkeys[wtrf]{ts}{ref@name=#1}}
+\def\wtrf@set@label#1{\setkeys[wtrf]{ts}{label=#1}}
+
+%%%% define keys for new ref
+\define@key[wtrf]{ns}{namespace}{%
+ \@wtrf@set@namespace@true
+ \def\wtrf@namespace@temp{#1}}
+\define@key[wtrf]{ns}{nonamespace}[\@empty]{%
+ \@wtrf@use@namespace@false}
+\define@key[wtrf]{ns}{scope}{%
+ \wtrf@check@counter{#1}%
+ \@wtrf@use@scope@true
+ \def\wtrf@scope@temp{#1}}
+
+%%%% new ref
+\newcommand{\newref}{%
+ \let\wtrf@namespace@temp\@empty
+ \@wtrf@use@namespace@true
+ \@wtrf@set@namespace@false
+ \@wtrf@use@scope@false
+ \wtrf@if@option@exist
+ {\wtrf@set@namespace}
+ {\wtrf@@newref}}
+\@onlypreamble\newref
+\def\wtrf@set@namespace[#1]{%
+ \setkeys[wtrf]{ns}{#1}%
+ \wtrf@@newref}
+\def\wtrf@@newref#1{%
+ \@for\wtrf@member:=#1\do{%
+ \expandafter\wtrf@set@ref@name\expandafter{\wtrf@member}%
+ \expandafter\wtrf@newref@pre\expandafter{\wtrf@temp@ref@name}}}
+\def\wtrf@newref@pre#1{%
+ \wtrf@if@reftype@not@exist{#1}%
+ {\wtrf@newref{#1}}
+ {\wtrf@error{ref type '#1' already exists}}}
+\def\wtrf@newref#1{%
+ % define namespace
+ \if@wtrf@use@namespace@
+ \ifx\wtrf@namespace@temp\@empty
+ \@wtrf@set@namespace@false
+ \def\wtrf@namespace@temp{#1}%
+ \fi
+ \wtrf@name@edef{wtrf@#1@namespace}{\wtrf@namespace@temp:}%
+ \else
+ \wtrf@name@def{wtrf@#1@namespace}{}%
+ \fi
+ % define scope
+ \if@wtrf@use@scope@
+ \wtrf@name@edef{wtrf@#1@scope@cmd}{the\wtrf@scope@temp}%
+ \wtrf@name@def{wtrf@#1@scope}{\csname\wtrf@name@use{wtrf@#1@scope@cmd}\endcsname:}%
+ \else
+ \wtrf@name@def{wtrf@#1@scope}{}%
+ \fi
+ % define keys for setting styles
+ \define@key[wtrf]{#1@style}{refcmd}{\wtrf@name@def{wtrf@#1@refcmd}####1{##1}}%
+ \define@key[wtrf]{#1@style}{last sep}[\wtrf@name@use{wtrf@#1@sep}]{%
+ \wtrf@name@def{wtrf@#1@last@sep}{##1}}%
+ \define@cmdkeys[wtrf]{#1@style}[wtrf@#1@]{sep, prefix, suffix}%
+ % default key settings
+ \setkeys[wtrf]{#1@style}{%
+ refcmd=\ref{##1},
+ sep={,\space}, last sep,
+ prefix={}, suffix={}}%
+ % define label command
+ \wtrf@check@command{#1label}%
+ \wtrf@name@def{#1label}{\protect\wtrf@name@use{wtrf@#1label}}
+ \wtrf@name@def{wtrf@#1label}##1{%
+ \label{\wtrf@name@use{wtrf@#1@namespace}\wtrf@name@use{wtrf@#1@scope}##1}}%
+ % define ref command
+ \wtrf@check@command{#1ref}%
+ \wtrf@name@def{#1ref}{\protect\wtrf@name@use{wtrf@#1ref}}
+ \wtrf@name@def{wtrf@#1ref}{%
+ \wtrf@if@option@exist
+ {\wtrf@name@use{wtrf@#1ref@with@option}}
+ {\def\wtrf@scope{\wtrf@name@use{wtrf@#1@scope}}\wtrf@name@use{wtrf@#1@print}}}%
+ % when option exist
+ \if@wtrf@use@scope@
+ \wtrf@name@def{wtrf@#1ref@with@option}[##1]##2{%
+ \def\wtrf@scope{##1:}%
+ \wtrf@name@use{wtrf@#1@print}{##2}}%
+ \else
+ \wtrf@name@def{wtrf@#1ref@with@option}[##1]##2{%
+ \let\wtrf@scope\@empty
+ \wtrf@name@use{wtrf@#1@print}{##2}}%
+ \fi
+ % print refs
+ \wtrf@name@def{wtrf@#1@print}##1{%
+ \wtrf@tempcnta\z@
+ \@for\wtrf@member:=##1\do{\advance\wtrf@tempcnta\@ne}%
+ \ifnum\wtrf@tempcnta<\tw@
+ \wtrf@name@use{wtrf@#1@prefix}%
+ \wtrf@name@use{wtrf@#1@refcmd}{%
+ \wtrf@name@use{wtrf@#1@namespace}\wtrf@scope##1}%
+ \wtrf@name@use{wtrf@#1@suffix}%
+ \else
+ \wtrf@tempcntb\@ne
+ \advance\wtrf@tempcnta\m@ne
+ \wtrf@name@use{wtrf@#1@prefix}%
+ \@for\wtrf@member:=##1\do{%
+ \expandafter\wtrf@set@label\expandafter{\wtrf@member}%
+ \wtrf@name@use{wtrf@#1@refcmd}{%
+ \wtrf@name@use{wtrf@#1@namespace}\wtrf@scope\wtrf@temp@label}%
+ \ifnum\wtrf@tempcnta>\wtrf@tempcntb
+ \wtrf@name@use{wtrf@#1@sep}%
+ \else\ifnum\wtrf@tempcnta=\wtrf@tempcntb
+ \wtrf@name@use{wtrf@#1@last@sep}%
+ \fi\fi
+ \advance\wtrf@tempcntb\@ne}%
+ \wtrf@name@use{wtrf@#1@suffix}%
+ \fi}%
+ % reset \wtrf@namespace@temp
+ \if@wtrf@set@namespace@\else
+ \let\wtrf@namespace@temp\@empty
+ \fi}
+
+%%%% set ref style
+\newcommand{\setrefstyle}[2]{%
+ \@for\wtrf@member:=#1\do{%
+ \expandafter\wtrf@set@ref@name\expandafter{\wtrf@member}%
+ \expandafter\wtrf@setrefstyle\expandafter{\wtrf@temp@ref@name}{#2}}}
+\def\wtrf@setrefstyle#1#2{%
+ \wtrf@if@reftype@not@exist{#1}%
+ {\wtrf@error{ref type '#1' does not exist}}
+ {\setkeys[wtrf]{#1@style}{#2}}}
+
+%% EOF