diff options
author | Karl Berry <karl@freefriends.org> | 2014-08-20 20:02:31 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-08-20 20:02:31 +0000 |
commit | ad409dcf2ee3052e025ecf5cca832ae5147ad253 (patch) | |
tree | e658185f936a8ef9b69bf204baaf9e2d88145d03 /Master/texmf-dist | |
parent | 18bde681e8eae08ccb3a09cd5eef0d1ca1b3bf70 (diff) |
dataref (20aug14)
git-svn-id: svn://tug.org/texlive/trunk@34994 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/dataref/dataref.pdf | bin | 227149 -> 235912 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/dataref/dataref.dtx | 564 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/dataref/dataref.sty | 313 |
3 files changed, 723 insertions, 154 deletions
diff --git a/Master/texmf-dist/doc/latex/dataref/dataref.pdf b/Master/texmf-dist/doc/latex/dataref/dataref.pdf Binary files differindex a2f8d90b173..4aa3b957609 100644 --- a/Master/texmf-dist/doc/latex/dataref/dataref.pdf +++ b/Master/texmf-dist/doc/latex/dataref/dataref.pdf diff --git a/Master/texmf-dist/source/latex/dataref/dataref.dtx b/Master/texmf-dist/source/latex/dataref/dataref.dtx index 6ac408740e8..0f44412b029 100644 --- a/Master/texmf-dist/source/latex/dataref/dataref.dtx +++ b/Master/texmf-dist/source/latex/dataref/dataref.dtx @@ -1,7 +1,7 @@ % \iffalse meta-comment % % The MIT License (MIT) -% + % Copyright (c) 2013 Christian Dietrich % % Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -27,12 +27,12 @@ \ProvidesFile{dataref.dtx} %</driver> %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] -%<package>\ProvidesPackage{dref} -%<package> [2013/12/06 v0.1 dref] +%<package>\ProvidesPackage{dataref} +%<package> [2014/08/20 v0.2 dataref] % %<*driver> \documentclass{ltxdoc} -\usepackage[usagereport]{dataref}[2013/12/06] +\usepackage[usagereport]{dataref}[2014/08/20] \EnableCrossrefs \CodelineIndex \RecordChanges @@ -101,35 +101,64 @@ % % \section{Introduction} % -% Writing scientific texts is a craft. It is the craft of communicating your results to your colleagues and to the curious world public. Often your conclusions are based upon facts and numbers that you gathered during your research for the specific topic. You might have done many experiments and produced lot of data. The craft of writing is to guide your reader through a narrative that is based upon that data. But there may be many versions of that data. Perhaps you found a problem in your experiment, while already writing, that forces you back into the laboratory. After a while, the moon has done its circle many times, you return from that dark place and your methodology has improved as significantly as your data has. But now you have to rewrite that parts of the data that reference the old data points. -% -% The \textsf{dataref} is here to help you with managing your data points. It provides you with macro style keys that represent symbolic names for your data points. You can reference those symbolic names with \cmd{\dref}, use them in calculations to have always up-to-date percentage values, define projections between sets of data points and document them. \textsf{dataref} also introduces the notion of assertions (\cmd{\drefassert}) for your results to ensure that your prosa text references fit the underlying data. +% Writing scientific texts is a craft. It is the craft of communicating your results to your +% colleagues and to the curious world public. Often your conclusions are based upon facts and +% numbers that you gathered during your research for the specific topic. You might have done many +% experiments and produced lot of data. The craft of writing is to guide your reader through a +% narrative that is based upon that data. But there may be many versions of that data. Perhaps you +% found a problem in your experiment, while already writing, that forces you back into the +% laboratory. After a while, the moon has done its circle many times, you return from that dark +% place and your methodology has improved as significantly as your data has. But now you have to +% rewrite that parts of the data that reference the old data points. +% +% The \textsf{dataref} is here to help you with managing your data points. It provides you with +% macro style keys that represent symbolic names for your data points. You can reference those +% symbolic names with \cmd{\dref}, use them in calculations to have always up-to-date percentage +% values, define projections between sets of data points and document them. \textsf{dataref} also +% introduces the notion of assertions (\cmd{\drefassert}) for your results to ensure that your prosa +% text references fit the underlying data. % % \section{Usage} % -% The \textsf{dataref} package heavily uses \textsf{pgfkeys} and \textsf{pgfmath} to perform storage and operations upon data points. See \texttt{texdoc pgfmanual} for further informations about those topics. +% The \textsf{dataref} package heavily uses \textsf{pgfkeys} and \textsf{pgfmath} to perform storage +% and operations upon data points. See \texttt{texdoc pgfmanual} for further information about those +% topics. % % \DescribeMacro{\drefset\{\meta{name}\}\{\meta{value}\}} % -% The \cmd{\drefset} command is used to define the symbolic data points. The first argument is the symbolic name, the second argument is the value. The value can be a number, but it can also be arbitrary text. The key may contain virtually all characters, including spaces and slashes. It is good practice to use a hierarchy to structure you data point names. +% The \cmd{\drefset} command is used to define the symbolic data points. The first argument is the +% symbolic name, the second argument is the value. The value can be a number, but it can also be +% arbitrary text. The key may contain virtually all characters, including spaces and slashes. It is +% good practice to use a hierarchy to structure you data point names. % % \lstinputlisting[language=tex, firstline=5, lastline=15,basicstyle=\footnotesize,frame=single]{datapoints.tex} % -% The code snippet, which is best stored in an external file, and which might be auto-generated, is best read with \cmd{\input}. It defines 10 symbolic names, that are partitioned into two "directories" (\texttt{control group} and \texttt{medicament A}). +% The code snippet, which is best stored in an external file, and which might be auto-generated, is +% best read with \cmd{\input}. It defines 10 symbolic names, that are partitioned into two +% "directories" (\texttt{control group} and \texttt{medicament A}). % -% \DescribeMacro{\dref\{\meta{name}\}} +% \DescribeMacro{\dref*\{\meta{name}\}} +% \DescribeMacro{\dref[\meta{format}]\{\meta{name}\}} + % -% This macro is used to reference a single symbolic data point. The value stored in that datapoint is inserted into the text. \cmd{\dref} additonally marks the data point as used. It will then appear in the dref usage report. For undefined keys the default behaviour is to abort the compilation. But the package option \texttt{ignoremissing} just outputs a warning. All referenced/missing/found datapoints are noted in the aux file. +% This macro is used to reference a single symbolic data point. The value stored in that datapoint +% is inserted into the text. \cmd{\dref} additionally marks the data point as used. It will then +% appear in the dref usage report. For undefined keys the default behaviour is to abort the +% compilation. But the package option \texttt{ignoremissing} just outputs a warning. All +% referenced/missing/found datapoints are noted in the aux file. % % \vspace{1em}\noindent\begin{tabular}{ll}\toprule % Macro & Expansion \\ % \midrule -% \cmd{\dref\{/control group/mice race\}} & \dref{/control group/mice race} \\ -% \cmd{\dref\{/control group/mice count\}} & \dref{/control group/mice count} \\ +% \cmd{\dref*\{/control group/mice race\}} & \dref*{/control group/mice race} \\ +% \cmd{\dref*\{/control group/mice count\}} & \dref*{/control group/mice count} \\ % \cmd{\dref[sci,precision=2,zerofill=true]\{/med A/recovered\}} & \dref[sci,precision=2,zerofill=true]{/med A/recovered} \\ \bottomrule % \end{tabular}\vspace{1em} % -% \cmd{\dref} additionally takes an optional argument. This argument is interpreted as \texttt{/pgf/number format/} argument. See the pgf/tikz manual for more information. Only if the optional argument is present the value is printed as a number, so \verb|[]| is a useful option, since it enforces printing it as a number with the proper number format applied. Be aware that \cmd{\dref} is \textbf{not} expandable. +% \cmd{\dref} additionally takes an optional argument. This argument is interpreted as +% \texttt{/pgf/number format/} argument. See the pgf/tikz manual for more information. Only in the +% unstarred version this macro parses the value as a number. Be aware that +% \cmd{\dref} is \textbf{not} expandable. % % \DescribeMacro{\drefvalueof\{\meta{name}\}} % @@ -163,12 +192,11 @@ % \verb|\drefhelp{/med A/mice race}| % \end{quote} % -% \DescribeMacro{\drefcalc[\meta{lets}]\{\meta{expr}\}[\meta{format}]} +% \DescribeMacro{\drefcalc[\meta{format}]\{\meta{expr}\}} % -% The \cmd{\drefcalc} command is the core function of calculating with -% data points. It is based on the pgfmath engine. It uses the required -% argument as a mathematical expression, but has additional features, -% that can be used. +% The \cmd{\drefcalc} command is the core function of calculating with data points. It is based on +% the pgfmath engine. It uses the required argument as a mathematical expression, but has additional +% features, that can be used. % % \begin{quote} % \verb|\drefcalc{(4+7)/12 * 100}| $\Rightarrow$ \drefcalc{(4+7)/12 * 100} @@ -188,38 +216,56 @@ % \verb|\drefcalc{\cg{recovered}/\cg{mice count}}| $\Rightarrow$ \drefcalc{\cg{recovered}/\cg{mice count}} % \end{quote} % -% \noindent The first optional argument lets you define constants within pgfmath -% (zero arity functions, that can be called without parenthesis). Those -% bindings are only valid for the current \cmd{\datarefcalc} call. -% +% \noindent The optional argument lets you give a number format, which is used for printing the +% result number (\verb|/pgf/number format|). +% % \begin{quote} -% \verb|\drefcalc[A=\cg{recovered},B=12*20]{B/A}| $\Rightarrow$ \drefcalc[A=data("/control group/recovered"),B=12*20]{B/A}\\ -% \verb|\drefcalc[X=100]{30/X}| $\Rightarrow$ \drefcalc[X=100]{30/X} +% \verb|\drefcalc[precision=5,fixed]{1/3}| $\Rightarrow$ \drefcalc[fixed,precision=5]{1/3} % \end{quote} -% -% \noindent The second optional argument, that appears after the required argument defines the pgfmath's \texttt{number format}. +% +% \cmd{\drefcalc} works as well in a \cmd{/pgf/fpu} environment or a normal one. The FPU feature of +% pgfmath is used to handle large numbers, which may occur often when handling experiment data +% points. +% % \begin{quote} -% \verb|\drefcalc{1/3}[precision=5,fixed]| $\Rightarrow$ \drefcalc{1/3}[fixed,precision=5] +% % \end{quote} +% \dreflet{A=123456789,B=987654321, a=12, b=98} +% +% \begin{tabular}{lrr} +% \multicolumn{3}{l}{\cmd{\dreflet\{A=123456789, B=987654321, a=12, b=98\}}} \\ +%\toprule +% Macro & Inserted Text & \cmd{\drefresult} \\\midrule +% \verb|\drefcalc[/pgf/fpu]{A/B}| & \drefcalc[/pgf/fpu]{A/B} & \drefresult\\ +% \verb|\drefcalc{a/b}| & \drefcalc[]{a/b} & \drefresult \\ +% \verb|\drefcalc*[/pgf/fpu]{A/B}| & \drefcalc*[/pgf/fpu]{A/B} & \drefresult\\ +% \verb|\drefcalc*{a/b}| & \drefcalc*[]{a/b} & \drefresult \\ +% \bottomrule +% \end{tabular} +% % % \DescribeMacro{\drefcalc*} % \DescribeMacro{\drefresult} % \DescribeMacro{\drefformat\{\meta{number}\}} % -% \noindent When you get confused about the which optional argument does -% what, just think of a pipe. First you define bindings, then you -% calculate, then you emit stuff. When drefcalc is called with an star -% argument, it does not print the result, but only sets -% \cmd{\drefresult}. \cmd{\drefformat} is used to format a number. -% % \begin{quote} % \verb|\drefcalc*{1/3} ABC: \drefresult| $\Rightarrow$ \drefcalc*{1/3} ABC: \drefresult\\ % \verb|\drefformat[fixed,precision=1]{\drefresult}|$\Rightarrow$ \drefformat[fixed,precision=1]{\drefresult}\\ % \verb|\drefformat[sci]{100000}| $\Rightarrow$ \drefformat[sci]{100000} % \end{quote} -% +% +% \DescribeMacro{/dref/let=\{\meta{lets}\}} % \DescribeMacro{\dreflet\{\meta{lets}\}} % +% Since symbolic key names can get long, dataref has the possibility to define variables for use +% within mathematical expression from other expressions. These "let"-bindings can either be defined +% locally for a \cmd{\drefcalc} commando with a pgf key or globally with \cmd{\dreflet}. +% +% \begin{quote} +% \verb|\drefcalc[/dref/let{A=12*20,B=\cg{recovered}}]{A/B}| $\Rightarrow$ \drefcalc[/dref/let={B=data("/control group/recovered"),A=12*20}]{A/B}\\ +% \verb|\drefcalc[/dref/let={X=100}]{30/X}| $\Rightarrow$ \drefcalc[/dref/let={X=100}]{30/X} +% \end{quote} +% % The bindings for \cmd{\drefcalc} are only local to that macro % call. Defining a binding for the current group can be done with % \cmd{\dreflet}. @@ -236,7 +282,114 @@ % \drefcalc{\cg{dead after 24h}/percent} percent within 24 % and \drefcalc{\cg{dead after 48h}/percent} percent within 48 hours. % \end{quote} +% +% \DescribeMacro{\drefrel*[\meta{opts}]\{\meta{key}\}} +% \DescribeMacro{\drefrel[\meta{opts}]\{\meta{key}\}} +% +% The \cmd{\drefrel} macro is used to calculate relations between a base value and a concrete key. A +% prominent example of such a relation is the percent relation. \cmd{\drefrel} allows you to write +% down intentionally what relation you want to express without thinking about a concrete +% formula. The starred version of this macro does not print anything, but sets only +% \cmd{\drefresult}. +% +% \begin{quote} +% \noindent\verb|\drefrel[base=/med A/mice count,factor]{/med A/recovered}| \\ +% \mbox{}\hspace{1cm} $\Rightarrow$ \drefrel[base=/med A/mice +% count,factor,percent]{/med A/recovered} \\ +% \end{quote} +% +% The type of relation can be manipulated with various keys. Almost +% always the given argument key will be set in relation to a base +% value. The type of relation can be given as well as post-processing +% steps. +% +% Like \cmd{\drefcalc}, \cmd{\drefrel} sets the \cmd{\drefresult} +% macro accordingly. % +% \DescribeMacro{/dref/base} +% \DescribeMacro{/dref/base plain} +% \DescribeMacro{/dref/value plain} +% +% This specifies the key that will be used as a base. Without the +% \cmd{base plain} option, the value will be interpreted as a symbolic +% datapoint. With the option, base contains the plain value. When +% \cmd{value plain} is given, the mandatory argument is interpreted as +% a number and not as a symbolic name. +% +% \verb|\drefrel[factor,base=50,base plain]{/med A/mice count}| $\Rightarrow$ +% \drefrel[factor,base=50,base plain]{/med A/mice count} +% +% \verb|\drefrel[factor,base=50,base plain,value plain]{45}| $\Rightarrow$ +% \drefrel[factor,base=50,base plain,value plain]{45} +% +% \DescribeMacro{/dref/factor} +% +% Is a base relation type, which cannot be mixed with other relation +% types. It simply divides the given value by the base value. +% +% \[\cmd{\drefresult} = \frac{\texttt{value}}{\texttt{base}}\] +% +% \DescribeMacro{/dref/increase} +% \DescribeMacro{/dref/overhead} +% +% Is a base relation type. It calculates the overhead factor a value +% show toward the base value. \texttt{increase} and \texttt{overhead} +% are synonyms. +% +% \[\cmd{\drefresult} = \frac{\texttt{value} - +% \texttt{base}}{\texttt{base}}\] +% +% \verb|\drefrel[overhead,base=50,base plain,value plain]{45}| $\Rightarrow$ +% \drefrel[overhead,base=50,base plain,value plain]{45} +% +% +% \DescribeMacro{/dref/delta} +% +% Is a base relation type. It calculates the difference between value +% and base. +% +% \[\cmd{\drefresult} = \texttt{value} - \texttt{base}\] +% +% \verb|\drefrel[delta,base=50,base plain,value plain]{45}| $\Rightarrow$ +% \drefrel[delta,base=50,base plain,value plain]{45} +% +% % \DescribeMacro{/dref/percent} +% +% Is a post-processing type. It calculates the percent value from a fraction. +% +% \[\cmd{\drefresult} = \cmd{\drefresult} \cdot 100.0 \] +% +% \noindent\verb|\drefrel[factor,percent,base=/med A/mice count]{/med A/recovered}| \\ +% \mbox{}\hspace{1cm}$\Rightarrow$ \drefrel[factor,percent,base=/med A/mice count]{/med A/recovered} +% +% % \DescribeMacro{/dref/abs} +% +% Is a post-processing type. It takes the absolute value. +% +% \[\cmd{\drefresult} = \mid \cmd{\drefresult} \mid \] +% \verb|\drefrel[overhead,abs,base=50,base plain,value plain]{45}| $\Rightarrow$ +% \drefrel[overhead,abs,base=50,base plain,value plain]{45} +% +% % \DescribeMacro{/dref/negate} +% +% Is a post-processing type. It negates the value. +% +% \[\cmd{\drefresult} = \cmd{\drefresult} \cdot -1.0 \] +% +% \noindent\verb|\drefrel[factor,negate,base=/med A/mice count]{/med A/recovered}| \\ +% \mbox{}\hspace{1cm}$\Rightarrow$ \drefrel[factor,negate,base=/med A/mice count]{/med A/recovered} +% +% \DescribeMacro{/dref/divide} +% +% Is a post-processing type. Divides the result by a contant +% factor. The argument must be a plain number. +% +% \[\cmd{\drefresult} = \cmd{\drefresult} \cdot \{divide\} \] +% +% \noindent\verb|\drefrel[value plain,divide=1e6]{1453342654}| +% $\Rightarrow$ +% \drefrel[value plain,divide=1e6]{1453342654} +% % \DescribeMacro{\drefprojection\{\meta{from}\}\{\meta{to}\}\{\meta{projection}\}} % % Sometimes one or multiple sets of data have to be projected/mixed into a @@ -258,8 +411,8 @@ % \calc{data("/dead after 24h")+data("/dead after 48h")}{died} % }\end{verbatim} % -% \verb|\dref{/projection/died}| $\Rightarrow$ \dref{/projection/died}\\ -% \verb|\dref{/projection/mice race}| $\Rightarrow$ \dref{/projection/mice race}\\ +% \verb|\dref*{/projection/died}| $\Rightarrow$ \dref*{/projection/died}\\ +% \verb|\dref*{/projection/mice race}| $\Rightarrow$ \dref*{/projection/mice race}\\ % \verb|\dref{/projection/count}| $\Rightarrow$ \dref{/projection/count} % \end{quote} % @@ -274,7 +427,7 @@ % of values and fills out a macro which is interpreted as a symbolic % data point. The entries are seperated with \& and printed. In the % starred variant the resulting text is not interpreted as symbolic -% name, but as a macro. +% name, but as a macro. The symbolic name is expanded with \cmd{\drefvalueof}. % % The second argument is the macro, and can have two macro % replacements. The first replacement \verb|#1| is the value of the list @@ -312,6 +465,9 @@ % \begin{verbatim}\drefassert{data("/control group/mice count") > 30} % Of the more than thirty infected mice... % \end{verbatim} +% \drefassert{data("/control group/mice count") > 30} +% \begingroup \pgfset{/pgf/fpu} \drefassert{data("/control group/mice +% count") > 30} \endgroup % % The \textbf{noassert} package options disables the latex abortion. In % that case only a warning message is printed on the terminal. @@ -333,25 +489,27 @@ % % \begin{quote} % \verb|\drefannotate{none}|\drefannotate{none}\\ -% \dref{/control group/mice race}, \dref{/control group/mice count}, \drefcalc{100/3} +% \dref*{/control group/mice race}, \dref{/control group/mice count}, \drefcalc{100/3} % \end{quote} % % \begin{quote} % \verb|\drefannotate{footnote}|\drefannotate{footnote}\\ -% \dref{/control group/mice race}, \dref{/control group/mice count}, \drefcalc{100/3} +% \dref*{/control group/mice race}, \dref{/control group/mice count}, \drefcalc{100/3} % \end{quote} % % \begin{quote} % \verb|\drefannotate{pdfcomment}|\drefannotate{pdfcomment}\\ -% \dref{/control group/mice race}, \dref{/control group/mice count}, \drefcalc{100/3} +% \dref*{/control group/mice race}, \dref{/control group/mice count}, \drefcalc{100/3} % \end{quote} % % \DescribeMacro{\drefusagereport} % \DescribeMacro{[usagereport]} +% \DescribeMacro{[refall]} % % With the \textbf{usagereport} package option enabled, % \cmd{\drefusagereport} generates a usagereport of all referenced -% keys. The usage report groups the keys by the help texts. +% keys. The usage report groups the keys by the help texts. If the +% refall package option is given, all keys are marked as referenced. % % \section*{Datagraphy} % \drefusagereport @@ -381,9 +539,13 @@ % \begin{macrocode} \RequirePackage{pgf} \RequirePackage{kvoptions} -\RequirePackage{xparse} -\RequirePackage{etoolbox} -\RequirePackage{etextools} +\usepgflibrary{fpu} +\usepackage{etoolbox} +\let\origforlistloop\forlistloop +\usepackage{etextools} +\let\forlistloop\origforlistloop +\RequirePackage{xcolor} + % \end{macrocode} % \begin{macrocode} \SetupKeyvalOptions{ @@ -394,6 +556,7 @@ \DeclareStringOption[1]{defaultvalue} \DeclareStringOption[none]{annotate} \DeclareBoolOption{usagereport} +\DeclareBoolOption{refall} \DeclareBoolOption{ignoremissing} \DeclareBoolOption{noassert} \ProcessKeyvalOptions* @@ -401,9 +564,14 @@ % % \begin{macro}{\dref@set} % \begin{macrocode} -\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% } % \end{macrocode} % \end{macro} @@ -418,11 +586,15 @@ % % \begin{macro}{\dref@expandable} % \begin{macrocode} -\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% }% } % \end{macrocode} @@ -431,7 +603,7 @@ % % \begin{macro}{\dref@unexpandable} % \begin{macrocode} -\long\def\dref@unexpandable#1{% +\def\dref@unexpandable#1{% \def\drefcurrentkey{\dref@datapath#1}% \pgfkeysifdefined{\drefcurrentkey}{% \immediate\write\@auxout{\noexpand\dref@found{\drefcurrentkey}{\thepage}}% @@ -449,20 +621,31 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\drefifdefined} +% \begin{macrocode} +\newcommand{\drefifdefined}[3]{ + \def\drefcurrentkey{\dref@datapath#1}% + \pgfkeysifdefined{\drefcurrentkey}{#2}{#3}% +} +% \end{macrocode} +% \end{macro} +% % % % \begin{macro}{\dref} % \begin{macrocode} -\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}% - }% - }% +\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}% } @@ -535,17 +718,17 @@ % % \begin{macro}{\dref@referenced} % \begin{macrocode} -\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% @@ -558,9 +741,11 @@ \def\dref@let#1{% \def\@tmp##1=##2;{\pgfmathdeclarefunction*{##1}{0}{\pgfmathparse{##2}}}% \renewcommand*{\do}[1]{\@tmp##1;}% - \docsvlist{#1}% + \ifstrempty{#1}{}{% + \docsvlist{#1}% + }% } -% \end{macrocode} + % \end{macro} % % @@ -573,24 +758,93 @@ % \end{macro} % \begin{macro}{\drefcalc} % \begin{macrocode} -\DeclareDocumentCommand{\dref@calc}{o m}{% - \IfNoValueTF {#1}{}{% - \dref@let{#1}% - }% - \pgfmathparse{#2}% + + +\def\dref@calc@parser@d#1#2\@nnil{% + \ifx\else% + \if#1d% + \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\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\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\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\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\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&\else\dref@calc@parser@d #2\@nnil\fi% } -\def\drefresult{0.0} -\DeclareDocumentCommand{\drefcalc}{s O{} m O{}}{% + +\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% +} % \end{macrocode} % \end{macro} % @@ -599,9 +853,7 @@ \newcommand{\dref@format}[2][]{% \pgfmathprintnumber[#1]{#2}% } -\DeclareDocumentCommand{\drefformat}{O{} m}{% - \dref@format[#1]{#2}% -} +\newcommand{\drefformat}[2][]{\dref@format[#1]{#2}} % \end{macrocode} % \end{macro} @@ -616,15 +868,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}% }% @@ -660,13 +912,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 % \end{macrocode} % \end{macro} % @@ -754,7 +1002,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}} \\% } % \end{macrocode} % \end{macro} @@ -773,8 +1021,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% @@ -791,9 +1042,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}% } @@ -829,8 +1082,8 @@ % \begin{macrocode} \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% @@ -845,6 +1098,121 @@ % \end{macro} % % +% \begin{macro}{\drefrel} +% \begin{macrocode} +\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% +} + +% +% \end{macrocode} +% \end{macro} +% % \iffalse %</package> % \fi 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\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\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\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\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\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\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&\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'. |