summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/dataref
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-08-20 20:02:31 +0000
committerKarl Berry <karl@freefriends.org>2014-08-20 20:02:31 +0000
commitad409dcf2ee3052e025ecf5cca832ae5147ad253 (patch)
treee658185f936a8ef9b69bf204baaf9e2d88145d03 /Master/texmf-dist/tex/latex/dataref
parent18bde681e8eae08ccb3a09cd5eef0d1ca1b3bf70 (diff)
dataref (20aug14)
git-svn-id: svn://tug.org/texlive/trunk@34994 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/dataref')
-rw-r--r--Master/texmf-dist/tex/latex/dataref/dataref.sty313
1 files changed, 257 insertions, 56 deletions
diff --git a/Master/texmf-dist/tex/latex/dataref/dataref.sty b/Master/texmf-dist/tex/latex/dataref/dataref.sty
index d35434d5189..1b9e1d2c32d 100644
--- a/Master/texmf-dist/tex/latex/dataref/dataref.sty
+++ b/Master/texmf-dist/tex/latex/dataref/dataref.sty
@@ -22,9 +22,11 @@
%%
%% This work consists of the files dataref.dtx and dataref.ins
%% and the derived file dataref.sty.
+
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
-\ProvidesPackage{dref}
- [2013/12/06 v0.1 dref]
+\ProvidesPackage{dataref}
+ [2014/08/20 v0.2 dataref]
+
\ifx\drefloaded\undefined
\let\drefloaded=\relax
\else
@@ -37,9 +39,13 @@
\fi
\RequirePackage{pgf}
\RequirePackage{kvoptions}
-\RequirePackage{xparse}
-\RequirePackage{etoolbox}
-\RequirePackage{etextools}
+\usepgflibrary{fpu}
+\usepackage{etoolbox}
+\let\origforlistloop\forlistloop
+\usepackage{etextools}
+\let\forlistloop\origforlistloop
+\RequirePackage{xcolor}
+
\SetupKeyvalOptions{
family=dref,
prefix=dref@
@@ -48,23 +54,33 @@
\DeclareStringOption[1]{defaultvalue}
\DeclareStringOption[none]{annotate}
\DeclareBoolOption{usagereport}
+\DeclareBoolOption{refall}
\DeclareBoolOption{ignoremissing}
\DeclareBoolOption{noassert}
\ProcessKeyvalOptions*
-\newcommand{\dref@set}[2]{%
+\def\dref@set#1#2{%
\pgfkeys@temptoks{#2}%
- \expandafter\xdef\csname pgfk@\dref@datapath#1\endcsname{\the\pgfkeys@temptoks}%
+ \expandafter\xdef\csname
+ pgfk@\dref@datapath#1\endcsname{\the\pgfkeys@temptoks}%
+ \ifdref@refall%
+ \expandafter\dref@found\expandafter{\dref@datapath#1}{0}
+ \expandafter\dref@referenced\expandafter{\dref@datapath#1}{0}%
+ \fi%
}
\def\drefset#1#2{\dref@set{#1}{#2}}
-\long\def\dref@expandable#1{%
+\def\dref@expandable#1{%
\pgfkeysifdefined{\dref@datapath#1}{%
\pgfkeysvalueof{\dref@datapath#1}%
}{%
- \dref@defaultvalue%
+ \ifdref@ignoremissing%
+ \dref@defaultvalue%
+ \else%
+ \typeout{Dref error: undefined key `#1'}\QUIT%
+ \fi%
}%
}
-\long\def\dref@unexpandable#1{%
+\def\dref@unexpandable#1{%
\def\drefcurrentkey{\dref@datapath#1}%
\pgfkeysifdefined{\drefcurrentkey}{%
\immediate\write\@auxout{\noexpand\dref@found{\drefcurrentkey}{\thepage}}%
@@ -79,16 +95,22 @@
}%
\immediate\write\@auxout{\noexpand\dref@referenced{\drefcurrentkey}{\thepage}}%
}
-\DeclareDocumentCommand{\dref}{o m}{%
- \dref@unexpandable{#2}%
- \IfNoValueTF {#1}{%
- \gdef\dref@dref@output{\dref@expandable{#2}}%
- }{%
- \gdef\dref@dref@output{%
- \pgfmathparse{\dref@expandable{#2}}%
- \dref@format[#1]{\pgfmathresult}%
- }%
- }%
+\newcommand{\drefifdefined}[3]{
+ \def\drefcurrentkey{\dref@datapath#1}%
+ \pgfkeysifdefined{\drefcurrentkey}{#2}{#3}%
+}
+\def\dref{\@ifstar\@@dref\@dref}
+\newcommand{\@dref}[2][]{% Unstarred
+ \edef\dref@argument{#2}
+ \expandafter\dref@unexpandable\expandafter{\dref@argument}%
+ \pgfmathparse{\dref@expandable{#2}}%
+ \dref@format[#1]{\pgfmathresult}%
+ \dref@mkannotate{#2}%
+}
+\newcommand{\@@dref}[2][]{ % Starred
+ \edef\dref@argument{#2}
+ \expandafter\dref@unexpandable\expandafter{\dref@argument}%
+ \expandafter\gdef\expandafter\dref@dref@output\expandafter{\expandafter\dref@expandable\expandafter{\dref@argument}}%
\dref@dref@output%
\dref@mkannotate{#2}%
}
@@ -121,17 +143,17 @@
\dolistcsloop{dref@helps}%
}%
}
-\long\def\dref@notfound#1#2{
+\def\dref@notfound#1#2{
\ifdref@usagereport%
\dref@usagereport@notfound{#1}{#2}%
\else\relax\fi%
}
-\long\def\dref@found#1#2{
+\def\dref@found#1#2{
\ifdref@usagereport%
\dref@usagereport@found{#1}{#2}%
\else\relax\fi%
}
-\long\def\dref@referenced#1#2{
+\def\dref@referenced#1#2{
\ifdref@usagereport%
\dref@usagereport@referenced{#1}{#2}%
\else\relax\fi%
@@ -139,35 +161,104 @@
\def\dref@let#1{%
\def\@tmp##1=##2;{\pgfmathdeclarefunction*{##1}{0}{\pgfmathparse{##2}}}%
\renewcommand*{\do}[1]{\@tmp##1;}%
- \docsvlist{#1}%
+ \ifstrempty{#1}{}{%
+ \docsvlist{#1}%
+ }%
}
+
\def\dreflet#1{%
\dref@let{#1}%
}
-\DeclareDocumentCommand{\dref@calc}{o m}{%
- \IfNoValueTF {#1}{}{%
- \dref@let{#1}%
- }%
- \pgfmathparse{#2}%
+
+\def\dref@calc@parser@d#1#2\@nnil{%
+ \ifx&#2&#1\else%
+ \if#1d%
+ \dref@calc@parser@a #2\@nnil%
+ \else%
+ #1\dref@calc@parser@d #2\@nnil%
+ \fi\fi
}
-\def\drefresult{0.0}
-\DeclareDocumentCommand{\drefcalc}{s O{} m O{}}{%
+
+\def\dref@calc@parser@a#1#2\@nnil{%
+ \ifx&#2&#1\else%
+ \if#1a%
+ \dref@calc@parser@t #2\@nnil%
+ \else%
+ #1\dref@calc@parser@d #2\@nnil%
+ \fi\fi
+}
+
+\def\dref@calc@parser@t#1#2\@nnil{%
+ \ifx&#2&#1\else%
+ \if#1t%
+ \dref@calc@parser@A #2\@nnil%
+ \else%
+ #1\dref@calc@parser@d #2\@nnil%
+ \fi\fi
+}
+
+\def\dref@calc@parser@A#1#2\@nnil{%
+ \ifx&#2&#1\else%
+ \if#1a%
+ \dref@calc@parser@P #2\@nnil%
+ \else%
+ #1\dref@calc@parser@d #2\@nnil%
+ \fi\fi
+}
+
+\def\dref@calc@parser@P#1#2\@nnil{%
+ \ifx&#2&#1\else%
+ \if#1(%
+ \dref@calc@parser@Q #2\@nnil%
+ \else%
+ #1\dref@calc@parser@d #2\@nnil%
+ \fi\fi
+}
+
+\def\dref@calc@parser@Q#1#2\@nnil{%
+ \ifx&#2&#1\else%
+ \if#1"%
+ \dref@calc@parser@E #2\@nnil%
+ \else%
+ #1\dref@calc@parser@d #2\@nnil%
+ \fi\fi
+}
+
+\def\dref@calc@parser@E#1")#2\@nnil{%
+ (\drefvalueof{\dref@data@math@prefix#1})\ifx&#2&\else\dref@calc@parser@d #2\@nnil\fi%
+}
+
+\newcommand{\dref@calc}[1]{%
+ \xdef\dref@calc@argA{#1}%
+ \xdef\dref@calc@@argA{\expandafter\dref@calc@parser@d \dref@calc@argA\@nnil}%%
+ % \typeout{>>>> \dref@calc@argA -> \dref@calc@@argA}%
+ \pgfmathparse{\dref@calc@@argA}
+}
+\pgfset{/dref/let/.code={\dref@let{#1}}}
+\def\drefresult{0}
+\def\drefcalc{\@ifstar\@@drefcalc\@drefcalc}
+\newcommand{\@drefcalc}[2][]{% Unstarred
\begingroup%
- \dref@calc[#2]{#3}%
- \xdef\drefresult{\pgfmathresult}%
- \IfBooleanTF {#1} {}% Wit star do not print anything
- {%
- \dref@format[#4]{\pgfmathresult}%
- \dref@mkannotate{#3}%
- }%
+ \pgfset{/pgf/number format/.cd, #1}%
+ \dref@calc{#2}%
+ \pgfmathprintnumberto[fixed,assume math mode=true,precision=10,1000 sep={}]{\pgfmathresult}{\drefresult}
+ \xdef\drefresult{\drefresult}%
+ \dref@format{\pgfmathresult}%
+ \dref@mkannotate{#2}%
\endgroup%
}
+\newcommand{\@@drefcalc}[2][]{ % Starred
+ \begingroup%
+ \pgfset{/pgf/number format/.cd, #1}%
+ \dref@calc{#2}%
+ \pgfmathprintnumberto[fixed,assume math mode=true,precision=10,1000 sep={}]{\pgfmathresult}{\drefresult}
+ \xdef\drefresult{\drefresult}%
+ \endgroup%
+}
\newcommand{\dref@format}[2][]{%
\pgfmathprintnumber[#1]{#2}%
}
-\DeclareDocumentCommand{\drefformat}{O{} m}{%
- \dref@format[#1]{#2}%
-}
+\newcommand{\drefformat}[2][]{\dref@format[#1]{#2}}
\gdef\dref@data@math@prefix{}
\pgfmathdeclarefunction{data}{1}{%
@@ -177,15 +268,15 @@
\pgfmath@smuggleone\pgfmathresult%
\endgroup%
}
-\DeclareDocumentCommand{\drefprojection}{m m m}{%
+\long\def\drefprojection#1#2#3{%
\begingroup%
\def\dref@data@math@prefix{#1}%
\def\rename##1##2{\dref@unexpandable{#1/##1}\drefset{#2/##2}{\dref@expandable{#1/##1}}}%
\def\id##1{\rename{##1}{##1}}%
\def\calc##1##2{%
\begingroup%
- \dref@calc{##1}%
- \xdef\dref@project@result{\pgfmathresult}
+ \drefcalc{##1}%
+ \xdef\dref@project@result{\drefresult}
\endgroup%
\drefset{#2/##2}{\dref@project@result}%
}%
@@ -216,13 +307,9 @@
\repeat}%
}%
\the\dref@toks}
-\DeclareDocumentCommand{\drefrow}{s m m}{%
- \IfBooleanTF {#1} {%
- \dref@makerow{#2}{#3}%
- }{% Wit star do not print anything
- \dref@makerow{#2}{\dref[]{#3}}%
- }%
-}
+\long\def\drefrow{\@ifstar\@@drefrow\@drefrow}
+\def\@drefrow#1#2{\dref@makerow{#1}{\drefvalueof{#2}}} % Unstarred
+\def\@@drefrow#1#2{\dref@makerow{#1}{#2}} % Starred
\expandafter\ifstrequal\expandafter{\dref@annotate}{pdfcomment}{
\RequirePackage{pdfcomment}
@@ -280,7 +367,7 @@
{\hypertarget{#1}{\dref@usagereport@strippath{#1}}}%
{\dref@usagereport@strippath{#1}}}%
& \dref@usagereport@formatreferencelist{#1}%
- & \pgfkeysifdefined{#1}{\pgfkeysvalueof{#1}}{\textbf{\red{undefined}}} \\%
+ & \pgfkeysifdefined{#1}{\pgfkeysvalueof{#1}}{\textbf{\color{red}undefined}} \\%
}
\newcommand{\dref@usagereport@forhelp}[1]{%
\begingroup%
@@ -293,8 +380,11 @@
}%
}{}%
}%
- \begin{longtable}{lll}\toprule%
+ \begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule%
& Page(s) & Value \\ \midrule
+ \endhead
+ \bottomrule%
+ \endfoot
\dolistcsloop{dref@usagereport@keys}%
\end{longtable}%
\endgroup%
@@ -305,9 +395,11 @@
\dref@usagereport@keyheader{##1}%
}%
}%
- \begin{longtable}{lll}\toprule%
+ \begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule%
Keys without Help & Page(s) & Value \\\midrule
\endhead
+ \bottomrule
+ \endfoot
\dolistcsloop{dref@usagereport@keys}%
\end{longtable}%
}
@@ -331,8 +423,8 @@
}
\newcommand{\drefassert}[1]{%
\begingroup%
- \pgfmathsetmacro{\result}{(#1) ? 1 : 0}
- \expandafter\ifstrequal\expandafter{\result}{1.0}{%
+ \drefcalc*{#1}%
+ \expandafter\ifstrequal\expandafter{\drefresult}{1}{%
\typeout{Assertion holds: #1}%
}{%
\ifdref@noassert%
@@ -343,6 +435,115 @@
}%
\endgroup%
}
+\newif\if@dref@valuemustderef%
+\newif\if@dref@basemustderef%
+\newif\if@dref@increase%
+\newif\if@dref@factor%
+\newif\if@dref@delta%
+\newif\if@dref@percent%
+\newif\if@dref@abs%
+\newif\if@dref@neg%
+\pgfkeys{%
+ \dref@datapath/.DUMMY/.initial=1
+}
+\pgfkeys{%
+ /dref/.cd,%
+ value/.initial = /.DUMMY,%
+ base/.initial = /.DUMMY,%
+ divide/.initial = 1,%
+ value plain/.is if=@dref@valuemustderef,%
+ value plain/.default=false,%
+ value plain=true,%
+ base plain/.is if=@dref@basemustderef,%
+ base plain/.default=false,%
+ base plain=true,%
+ factor/.is if=@dref@factor,%
+ factor/.default=true,%
+ factor=false,%
+ delta/.is if=@dref@delta,%
+ delta/.default=true,%
+ delta=false,%
+ increase/.is if=@dref@increase,%
+ increase/.default=true,%
+ increase=false,%
+ overhead/.is if=@dref@increase,%
+ overhead/.default=true,%
+ overhead=false,%
+ percent/.is if=@dref@percent,%
+ percent/.default=true,%
+ percent=false,%
+ abs/.is if=@dref@abs,%
+ abs/.default=true,%
+ abs=false,%
+ negate/.is if=@dref@neg,%
+ negate/.default=true,%
+ negate=false,%
+}
+
+\def\drefrel{\@ifstar\@@drefrel\@drefrel}
+
+\newcommand{\@drefrel}[2][]{%
+ \@@drefrel[#1]{#2}%
+ \@@drefrel@result%
+}
+
+\newcommand{\@@drefrel}[2][]{%
+ \begingroup%
+ \pgfkeys{/pgf/fpu}%
+ \pgfkeys{/dref/.cd,#1}%
+ \pgfkeys{/dref/value=#2}%
+ \if@dref@valuemustderef%
+ \drefref{\pgfkeysvalueof{/dref/value}}%
+ \edef\drefvalue{\drefvalueof{\pgfkeysvalueof{/dref/value}}}%
+ \else%
+ \def\drefvalue{\pgfkeysvalueof{/dref/value}}%
+ \fi%
+ \if@dref@basemustderef%
+ \drefref{\pgfkeysvalueof{/dref/base}}%
+ \def\drefbase{\drefvalueof{\pgfkeysvalueof{/dref/base}}}%
+ \else%
+ \def\drefbase{\pgfkeysvalueof{/dref/base}}%
+ \fi%
+ \xdef\drefresult{\drefvalue}%
+ \if@dref@increase%
+ \pgfmathparse{((\drefvalue) - (\drefbase)) / (\drefbase)}%
+ \def\drefresult{\pgfmathresult}%
+ \else%
+ \if@dref@factor%
+ \pgfmathparse{(\drefvalue) / (\drefbase)}%
+ \def\drefresult{\pgfmathresult}%
+ \else%
+ \if@dref@delta%
+ \pgfmathparse{(\drefvalue) - (\drefbase)}%
+ \def\drefresult{\pgfmathresult}%
+ \else%
+ \def\drefresult{\drefvalue}%
+ \fi%
+ \fi%
+ \fi%
+ % Percent
+ \if@dref@percent%
+ \pgfmathparse{(\drefresult)*100.0}%
+ \def\drefresult{\pgfmathresult}%
+ \fi%
+ % Absolute Value
+ \if@dref@abs%
+ \pgfmathparse{abs(\drefresult)}%
+ \def\drefresult{\pgfmathresult}%
+ \fi%
+ % Negative Value
+ \if@dref@neg%
+ \pgfmathparse{-1.0*(\drefresult)}%
+ \def\drefresult{\pgfmathresult}%
+ \fi%
+ \pgfmathparse{\drefresult/\pgfkeysvalueof{/dref/divide}}%
+ \pgfmathprintnumberto[fixed,assume math mode=true,precision=10,1000 sep={}]{\pgfmathresult}{\drefresult}%
+ \pgfmathprintnumberto{\pgfmathresult}{\@@drefrel@result}%
+ \xdef\drefresult{\drefresult}%
+ \xdef\@@drefrel@result{\@@drefrel@result}%
+ \endgroup%
+}
+
\endinput
%%
%% End of file `dataref.sty'.