texlive[42883] Master: dataref (6jan17)

commits+karl at tug.org commits+karl at tug.org
Fri Jan 6 23:25:07 CET 2017


Revision: 42883
          http://tug.org/svn/texlive?view=revision&revision=42883
Author:   karl
Date:     2017-01-06 23:25:07 +0100 (Fri, 06 Jan 2017)
Log Message:
-----------
dataref (6jan17)

Modified Paths:
--------------
    trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty
    trunk/Master/tlpkg/libexec/ctan2tds

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/dataref/README.md
    trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf
    trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex

Removed Paths:
-------------
    trunk/Master/texmf-dist/doc/latex/dataref/README
    trunk/Master/texmf-dist/doc/latex/dataref/dataref.pdf
    trunk/Master/texmf-dist/source/latex/dataref/

Deleted: trunk/Master/texmf-dist/doc/latex/dataref/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/dataref/README	2017-01-06 22:24:20 UTC (rev 42882)
+++ trunk/Master/texmf-dist/doc/latex/dataref/README	2017-01-06 22:25:07 UTC (rev 42883)
@@ -1,51 +0,0 @@
-dataref
-=======
-
-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 dataref is here to help you with managing your data points. It provides
-you with macro style keys, that represent symbolic names for your datapints.
-You can reference those symbolic names with \dref, use them in calculations
-to have always up-to-date percentage values, define projections between sets of
-data points and document them. dataref also introduces the notion of assertions
-(\drefassert) for your results to ensure that your prosa text references fit the
-underlying data.
-
-Building the documentation
-==========================
-With latexmk installed:
-
-    make
-    
-or
-
-    make dataref.sty; pdflatex dataref.dtx; pdflatex dataref.dtx; pdflatex dataref.dtx
-    
-    
-Examples
-========
-
-Setting symbolic data points
-
-    \drefset{/count}{42}
-    \drefset{/abc}{23}
-   
-Referencing them with \dref, \drefcalc, \drefassert
-
-    \dref{/count}  => 42
-    \drefcalc{data("/abc") / data("/count")} => 0.55
-    \drefassert{data("/abc") < data("/count")}
-
-Getting the latest version
-==========================
-
-dataref is hosted at github: https://github.com/stettberger/dataref
\ No newline at end of file

Added: trunk/Master/texmf-dist/doc/latex/dataref/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/dataref/README.md	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/dataref/README.md	2017-01-06 22:25:07 UTC (rev 42883)
@@ -0,0 +1,51 @@
+dataref
+=======
+
+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 dataref is here to help you with managing your data points. It provides
+you with macro style keys, that represent symbolic names for your datapints.
+You can reference those symbolic names with \dref, use them in calculations
+to have always up-to-date percentage values, define projections between sets of
+data points and document them. dataref also introduces the notion of assertions
+(\drefassert) for your results to ensure that your prosa text references fit the
+underlying data.
+
+Building the documentation
+==========================
+With latexmk installed:
+
+    make
+
+or
+
+    pdflatex dataref.tex; pdflatex dataref.tex; pdflatex dataref.tex
+
+
+Examples
+========
+
+Setting symbolic data points
+
+    \drefset{/count}{42}
+    \drefset{/abc}{23}
+
+Referencing them with \dref, \drefcalc, \drefassert
+
+    \dref{/count}  => 42
+    \drefcalc{data("/abc") / data("/count")} => 0.55
+    \drefassert{data("/abc") < data("/count")}
+
+Getting the latest version
+==========================
+
+dataref is hosted at github: https://github.com/stettberger/dataref

Added: trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf	2017-01-06 22:24:20 UTC (rev 42882)
+++ trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf	2017-01-06 22:25:07 UTC (rev 42883)

Property changes on: trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex	2017-01-06 22:25:07 UTC (rev 42883)
@@ -0,0 +1,735 @@
+% Copyright (c) 2013-2017 Christian Dietrich
+%
+% This work may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.3
+% of this license or (at your option) any later version.
+% The latest version of this license is in
+%   http://www.latex-project.org/lppl.txt
+% and version 1.3 or later is part of all distributions of LaTeX
+% version 2005/12/01 or later.
+%
+% This work has the LPPL maintenance status `maintained'.
+%
+% The Current Maintainer of this work is Christian Dietrich
+%
+% This work consists of the files dataref.tex and dataref.sty
+
+\documentclass{ltxdoc}
+\usepackage[usagereport]{dataref}[2017/01/06]
+
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+
+\usepackage{verbatim}
+\usepackage{listings}
+\usepackage{pdfcomment}
+\usepackage{siunitx}
+\usepackage{xspace}
+\usepackage{pgffor}
+\usepackage{filecontents}
+\usepackage{tikz}
+\usetikzlibrary{positioning, arrows}
+
+\begin{filecontents}{datapoints.tex}
+\drefset{/control group/mice race}{Black Six}
+\drefset{/control group/mice count}{32}
+\drefset{/control group/dead after 24h}{4}
+\drefset{/control group/dead after 48h}{7}
+\drefset{/control group/recovered}{21}
+
+\drefset{/med A/mice race}{Black Six}
+\drefset{/med A/mice count}{32}
+\drefset{/med A/dead after 24h}{6}
+\drefset{/med A/dead after 48h}{12}
+\drefset{/med A/recovered}{20}
+
+\drefsethelp{.*/mice race}{The mice race used for experiments heavily
+     influences the outcome of the results}
+
+\drefsethelp{.*/(dead after|recovered)}{Of all infected mice, a
+  certain number died within a specified period of time. A certain
+  recovered from the infection. The dead categories are cumulative and
+include all dead mice before.}
+\end{filecontents}
+\input{datapoints}
+% \OnlyDescription
+\drefkeys{prefix=/foo,value=123,save=/foo}
+\drefset{/override test}{2}
+\begin{document}
+\drefsave{/override test}{4}
+\drefkeys{prefix=}
+
+\parskip=1ex
+\parindent=0pt
+
+\CheckSum{0}
+
+
+ \CharacterTable
+  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
+   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
+   Digits        \0\1\2\3\4\5\6\7\8\9
+   Exclamation   \!     Double quote  \"     Hash (number) \#
+   Dollar        \$     Percent       \%     Ampersand     \&
+   Acute accent  \'     Left paren    \(     Right paren   \)
+   Asterisk      \*     Plus          \+     Comma         \,
+   Minus         \-     Point         \.     Solidus       \/
+   Colon         \:     Semicolon     \;     Less than     \<
+   Equals        \=     Greater than  \>     Question mark \?
+   Commercial at \@     Left bracket  \[     Backslash     \\
+   Right bracket \]     Circumflex    \^     Underscore    \_
+   Grave accent  \`     Left brace    \{     Vertical bar  \|
+   Right brace   \}     Tilde         \~}
+
+
+ \changes{v0.6}{2016/11/15}{Units, Unit Scaling, general overhaul}
+ \changes{v0.4}{2015/04/21}{Remove Spurious Whitespaces}
+ \changes{v0.1}{2013/12/06}{Initial version}
+
+ \DoNotIndex{\newcommand,\newenvironment}
+
+ \makeatletter
+ \def\colorfirsttoken#1#2{\bgroup\expandafter\color{#1}\cmd{#2}\egroup}
+ \def\Macro at Name#1#2\@nnil{\string#1}
+
+\renewcommand{\meta}[1]{\bgroup\color{green!40!black}$\langle$\textit{#1}$\rangle$\egroup}
+\newcommand{\Macro}[2][]{%
+  \noindent\hspace{-\marginparwidth}%
+  \hypertarget{\Macro at Name#2\@nnil}{%
+   \mbox{\colorfirsttoken{blue!50!black}#2}} \hfill\mbox{#1}\par}
+ \newcommand{\Option}[2][]{%
+   \noindent\hspace{-\marginparwidth}%
+   \mbox{\color{red!50!black}#2} \hfill\mbox{#1}\par}
+
+ \newcommand{\option}[1]{%
+   \bgroup\color{red!50!black}#1\egroup\xspace
+ }
+
+ \renewcommand{\macro}[1]{%
+   \hyperlink{\Macro at Name#1\@nnil}{\bgroup\color{blue!50!black}\cmd#1\egroup}\xspace
+ }
+ \makeatother
+
+ \colorlet{examplefill}{yellow!80!black}
+ \definecolor{codebackground}{rgb}{0.9,0.9,1}
+ \newdimen\examplewidth
+ \newsavebox{\codebox}
+ \newenvironment{example}[1][\marginparwidth-12pt]
+ {\begin{lrbox}{\codebox}\begin{minipage}{#1-2\fboxsep}}
+ {\end{minipage}\end{lrbox}%
+   \examplewidth=\wd\codebox%
+   \addtolength{\examplewidth}{-\marginparwidth+15pt}%
+   \global\examplewidth=\examplewidth%
+  \noindent\hspace{-\marginparwidth}\colorbox{examplefill}{\usebox{\codebox}}\hspace{12pt}}
+
+ \newenvironment{codeexample}
+ {\begin{lrbox}{\codebox}\begin{minipage}{\textwidth-\examplewidth-2\fboxsep}}
+{\end{minipage}\end{lrbox}\noindent\colorbox{codebackground}{\usebox{\codebox}}\global\examplewidth=0pt%
+\par\vspace{1em}}%
+
+
+ \newcommand{\dataref}{\textsc{dataref}\xspace}
+ \providecommand*{\url}{\texttt}
+ \GetFileInfo{dataref.sty}
+ \title{The \textsf{dataref} package}
+ \author{Christian Dietrich 2013-2016\\ \url{stettberger at dokucode.de}\\
+        \url{https://github.com/stettberger/dataref}}
+ \date{\filedate~\fileversion}
+
+ \maketitle
+
+ \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 \macro{\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 (\macro{\drefassert}) for your results to ensure that your prosa
+ text references fit the underlying data.
+
+ \section{Usage (or \dref*{/control group/mice count} mice)}
+
+ \begin{example}
+   From the \dref{/med A/mice count} mice in the experiment, \drefcalc[prefix=/med A]{d(/mice
+     count)-d(/recovered)} died.
+ \end{example}
+ \begin{codeexample}
+   \verb|\drefset{/med A/mice count}{32}|\\
+   \verb|\drefset{/med A/recovered}{20}|\\
+   \verb|From the \dref{/med A/mice count} mice in the experiment, |\\
+   \verb|\drefcalc[prefix=/med A]{d(/mice count)-d(/recovered)} died.|
+ \end{codeexample}
+
+ \subsection{Design Principles}
+
+ Before we jump into the description of \dataref, let us look a little bit into the design principles of \dataref. By
+ understanding the principles, you will be more productive and embedding data into your document will become easier.
+
+ First of all, \dataref is built on top of \textsf{pgfkeys} and \textsf{pgfmath} from the PGF/TiKZ macro packages. While
+ the former provides a usable user interface to provide options to \dataref, the later is used to perform computation on
+ your datapoints. If you are interested into these two excellent \TeX{} packages, please look at \texttt{texdoc
+   pgfmanual} for further information.
+
+ There are two aspects of \dataref: setting datapoints and referencing datapoints. While setting datapoints is kind of
+ boring, we have a wide variety of options when it comes to referencing. The expansion of datapoints is done in
+ multiples phases (see Figure~\ref{fig:pipeline}).
+
+
+ \begin{figure}[t]
+  \begin{tikzpicture}[node distance=0.5cm]
+    \tikzstyle{phase}=[draw,minimum width=1.5cm, fill=green!20!white];
+    \tikzstyle{desc}=[align=left, text width=3cm,anchor=#1,draw];
+
+
+   \node[phase](@init){@init};
+   \node[phase,right=of @init](@options){@options};
+   \node[phase,right=of @options](@get){@get};
+   \node[phase,right=of @get](@calc){@calc};
+   \node[phase,right=of @calc](@print){@print};
+   \node[phase,right=of @print](@set){@set};
+
+   \draw[>=latex']
+     (@init) edge[->] (@options)
+     (@options) edge[->] (@get)
+     (@get) edge[->] (@calc)
+     (@calc) edge[->] (@print)
+     (@print) edge[->] (@set);
+
+     \draw[ultra thin,shorten <=2pt] (@init) -- ++(75:1cm)
+        node[desc=south] {Set up a clean working environment.};
+
+      \draw[ultra thin,shorten <=2pt] (@options) -- ++(-140:1.5cm)
+        node[desc=north] {Parse the user-defined options and fill up all subsequent phases.};
+
+      \draw[ultra thin,shorten <=2pt] (@get) -- ++(95:1cm)
+        node[desc=south] {Load the main datapoint into \macro{\drefresult} and reference it.};
+
+      \draw[ultra thin,shorten <=2pt] (@calc) -- ++(-140:1.5cm)
+       node[desc=north] {Perform calculations on the main datapoint, including unit scaling.};
+
+      \draw[ultra thin,shorten <=2pt] (@print) -- ++(95:1.5cm)
+        node[desc=south] {Format and insert the result into the document body.};
+
+      \draw[ultra thin,shorten <=2pt] (@set) -- ++(-140:1.5cm)
+       node[desc=north] {Save the result as a datapoint or macro.};
+
+     \end{tikzpicture}
+     \caption{The \dataref Pipeline}\label{fig:pipeline}
+   \end{figure}
+
+   The \dataref macros are different regarding the phases they include or omit and in their default settings. In the
+   following, we will discuss all options and macros you can use to reference your datapoints. By default, the
+   \macro{\drefresult} is always set to the result of the pipeline.
+
+ \subsection{Setting Datapoints}
+
+
+
+ \Macro[(@set)]{\drefset\oarg{options}\{\meta{name}\}\{\meta{value}\}}
+
+
+\begin{codeexample}
+\begin{verbatim}
+\drefset{/med A/mice race}{Black Six}
+\drefset{/med A/mice count}{32}
+\drefset{/med A/dead after 24h}{6}
+\drefset{/med A/dead after 48h}{1}
+\end{verbatim}
+\end{codeexample}
+
+
+ The \macro{\drefset} command is used to define the symbolic datapoints. The name of a datapoint may contain virtually all
+ characters, including spaces and slashes. It is good practice to use a hierarchy to structure your data point names.
+ The value might be any string, while the focus of \dataref is on numerical datapoints. The \macro{\drefset} command works
+ outside the pipeline model (Figure \ref{fig:pipeline}) for performance reasons. It virtually consists only of the
+ @options and @set stage.
+
+ \Macro[(@set)]{\drefsave[\meta{options}]\{\meta{name}\}\{\meta{value}\}}
+
+ Besides setting the datapoint, \macro{\drefsave} writes it to the \textsc{aux} file and, therefore, makes it available in
+ the next \LaTeX{} run from the very beginning. The \option{ignoremissing} option is useful to reference the saved keys
+ at an earlier place in the document.
+
+\Option[(no default)]{/dref/set=\meta{key}}
+
+Inserts a \macro{\drefset} to the @set that captures the current result and saves it to the given datapoint.
+
+\Option[(no default)]{/dref/save=\meta{key}}
+
+Inserts a \macro{\drefsave} to the @set that captures the current result and saves it to the given datapoint. Since
+\macro{\drefsave} is used the result is available from the beginning of the document.
+
+\Option[(no default)]{/dref/to macro=\meta{macro}}
+
+The current result is saved to the given macro.
+
+\begin{example}[2cm]
+  \dref[set=/foo]{/med A/mice count} \dref{/foo}\\
+  \dref[ignoremissing]{/bar} \dref[save=/bar]{/med A/mice count}\\
+  \drefcalc*[to macro=\myresult]{3+2} \myresult
+\end{example}
+\begin{codeexample}
+\begin{verbatim}
+\dref[set=/foo]{/med A/mice count} \dref{/foo}\\
+\dref[ignoremissing]{/bar} \dref[save=/bar]{/med A/mice count}\\
+\drefcalc*[to macro=\myresult]{3+2} \myresult
+\end{verbatim}
+\end{codeexample}
+
+
+\Option[(no default, initially "")]{/dref/prefix=\meta{key prefix}}
+
+On every key retrieval or setting of a datapoint this prefix is added.
+It is a value-typed PGF key, so operations like
+\texttt{prefix/.append} are possible.
+
+\Macro{\drefinput[\meta{prefix}]\{\meta{filename}\}}
+
+Uses \cmd{\input} to read the file. During the processing of this file
+\option{prefix} is set to the given value. This is useful to include
+several files that resulted from different experiments but include
+equal datapoint keys.
+
+
+\subsection{Referencing Datapoints}
+
+
+ \Macro[(@options=\{print=default\}, @get, @calc, @print, @set)]{\dref*[\meta{options}]\{\meta{name}\}}
+ \Macro[(@options=\{print=raw\},     @get, @calc, @print, @set)]{\dref[\meta{options}]\{\meta{name}\}}
+
+ This macro is used to reference a single symbolic data point. The value stored in that datapoint is inserted into the
+ text. \macro{\dref} additionally marks the data point as used; it will appear in the datagraphy (see
+ Section~\ref{sec:datagraphy}). The starred variant does not attempt to parse the datapoint as a numerical value, but
+ outputs the saved string.
+
+\begin{example}
+\dref*{/control group/mice race}\\
+\dref*{/control group/mice count}\\
+\dref[sci,precision=2,zerofill=true]{/med A/recovered}
+\end{example}
+\begin{codeexample}
+\begin{verbatim}
+\dref*{/control group/mice race}\\
+\dref*{/control group/mice count}\\
+\dref[sci,precision=2,zerofill=true]{/med A/recovered}
+\end{verbatim}
+\end{codeexample}
+
+\Macro[(@get, @print)]{\drefvalueof\{\meta{name}\}}
+\Macro[(@get)]{\drefref\{\meta{name}\}}
+\vspace{1em}
+
+\begin{example}
+\drefvalueof{/med A/mice race}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\drefvalueof{/med A/mice race}
+\end{verbatim}
+\end{codeexample}
+
+  Since \macro{\dref} is not expandable, it cannot be used in all circumstances. Therefore, \macro{\drefvalueof} bypasses
+  all internal bookkeeping and provides access to the raw datapoint value. \macro{\drefref} can be used to mark the
+  datapoint as used to let it appear in the datagraphy.
+
+\Option[(default \textbf{true}, initially \textbf{false})]{/dref/ignoremissing=\meta{true-or-false}}
+\Option[(no default, initially \textbf{1.0})]{/dref/defaultvalue=\meta{value}}
+
+By default, \dataref produces an error if the referenced datapoint is undefined. If ignoremissing is given, the
+defaultvalue is used. This key is useful in combination with \macro{\drefsave}. Furthermore, it is possible to extract the
+missing keys from the \textsc{aux} file and to retrieve it from a secondary source (e.g. database, wikidata, etc).
+
+\begin{example}
+\dref*[ignoremissing,defaultvalue=undefined]{blah}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\dref*[ignoremissing,defaultvalue=undefined]{blah}
+\end{verbatim}
+\end{codeexample}
+
+\Macro{\drefsethelp\{\meta{pattern}\}\{\meta{text}\}}
+\Macro{\drefhelp\{\meta{name}\}}
+
+ \textsf{dataref} comes with a simple method for defining documentation for data points. This help can for example be used to communicate what is the concrete semantics of the data point. This is of special interest when writter and data gatherer are not the same person. \macro{\drefsethelp} takes two arguments: first a regular expression that matches the symbolic data point, second the help text.
+
+\begin{codeexample}
+\begin{verbatim}
+\drefsethelp{.*/mice race}{The mice race used for experiments
+ heavily influences the outcome of the results}
+\end{verbatim}
+\end{codeexample}
+
+The documentation for a datapoint is obtained by using the \macro{\drefhelp} macro. It checks all defined documentation
+strings (in linear order, first defined, first matched), and prints the first matching help text. With \textbf{LuaTeX}:
+only Lua (string.find) regular expressions are supported as patterns.
+
+ \begin{example}
+    \drefhelp{/med A/mice race}
+  \end{example}\begin{codeexample}
+\begin{verbatim}
+\drefhelp{/med A/mice race}
+\end{verbatim}
+  \end{codeexample}
+
+
+\Macro{\drefresult}
+
+Is set in the @set phase to the result of the currently executed pipeline.
+
+
+\subsection{Calculations and Math Tools}
+
+\Macro[(@calc, @print, @set)]{\drefcalc[\meta{options}]\{\meta{expression}\}}
+\Macro[(@calc, @set)]{\drefcalc*[\meta{options}]\{\meta{expression}\}}
+\Macro[(@print)]{\drefformat*[\meta{options}]\{\meta{number}\}}
+
+The \macro{\drefcalc} is the core function of calculating with data points. It is based on the pgfmath engine, but allows
+also the usage of symbolic datapoints within mathematical expressions. Datapoints can either are inserted into the
+calculations with the \cmd{d(\meta{path})} or the \cmd{data("\meta{path}")} notation. The starred variant of
+\macro{\drefcalc} does not print the result, but only sets the result macros.
+
+It is important to note, that \macro{\drefcalc} always uses the \textbf{/pgf/fpu} environment. The FPU feature of pgfmath
+is used to handle large numbers, which may occur often when handling experiment data points.
+
+\begin{example}
+  \drefcalc{(4+7)/12 * 100}\\
+  \drefcalc{d(/med A/mice count) * 100}\\
+  \drefcalc{data("/med A/mice count") * 100}\\
+  \drefcalc*{1+3}\\
+  \drefresult
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\drefcalc{(4+7)/12 * 100}\\
+\drefcalc{d(/med A/mice count) * 100}\\
+\drefcalc{data("/med A/mice count") * 100}\\
+\drefcalc*{1+3}\\
+\drefresult
+\end{verbatim}
+\end{codeexample}
+
+Since the default printing mechanism of \dataref utilizes PGF, all options from \texttt{/pgf/number format} can be
+directly used in the options. \macro{\drefformat} does only the printing. For documentation on the available options,
+please consult the PGF manual.
+
+\begin{example}
+  \drefcalc[precision=4]{1/3}\\
+  \drefcalc[sci]{123456789}\\
+  \drefcalc[prefix=/med A/,frac]{d(recovered)/d(mice count)}\\
+  \drefformat[fixed zerofill, precision=2]{\drefresult}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\drefcalc[precision=4]{1/3}\\
+\drefcalc[sci]{123456789}\\
+\drefcalc[prefix=/med A/,frac]{d(recovered)/d(mice count)}\\
+\drefformat[fixed zerofill, precision=2]{\drefresult}
+\end{verbatim}
+\end{codeexample}
+
+\subsection{Units and Unit Scaling}
+
+\dataref allows to give the unit of a datapoint and enforces the correct combination of units when using them in
+calculations. \dataref units can be arbitrary combinations of macros and strings, which allows the combination with the
+\textsc{SIUnitX} package.
+
+\Option[(no default)]{/dref/unit=\meta{unit}}
+
+The unit of a datapoint is loaded in the @get phase, and stored in the @set phase of the \dataref pipeline.
+
+\drefset[unit=\joule]{/power}{1234}
+\drefset[unit=ms]{/duration}{5555}
+\begin{codeexample}
+\begin{verbatim}
+\drefset[unit=ms]{/duration}{5555}
+\drefset[unit=\joule]{/power}{1234}
+\end{verbatim}
+\end{codeexample}
+
+\Option[(no default, choice)]{/dref/unit/format=\meta{formatting style}}
+\Option[(initially \textbf{plain})]{/dref/unit/format default=\meta{formatting style}}
+
+
+If a datapoint with unit is referenced, the unit is printed after the value. The formatting mechanism can be exchanged,
+in order to omit the unit, or to use \textsc{SIUnitX} for properly print it. By default, the \texttt{unit/format
+  default} is set in the @init phase. If you are using \textsc{SIUnitX} in your document, it is safe to set the default
+value accordingly. Currently, the values \texttt{false}, \texttt{plain}, and \texttt{siunitx} are valid formatting
+styles.
+
+\drefkeys{unit/format default=siunitx}
+\begin{example}
+  \dref[unit/format=false]{/duration}; \dref{/duration};
+    \typeout{\pgfkeysvalueof{/dref/unit/format default}}
+    \dref{/power}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\drefkeys{unit/format default=siunitx}
+\dref[unit/format=false]{/duration}; \dref{/duration};
+\dref{/power}
+\end{verbatim}
+\end{codeexample}
+
+\Option[(no default)]{/dref/unit/new scala=\meta{scala}}
+
+\dataref allows to define scaled units and conversion between the members of the scala. A scala definition is a list of
+units with scaling factors between them.
+
+
+\drefkeys{
+  unit/new scala={
+    1/y, 365/d, 24/h, 60/m, 60/s, 1000/ms, 1000/us, 1000/ns
+  },
+  unit/new scala={
+    1/\kilo\joule, 1000/\joule, 1000/\milli\joule,
+    1000/\micro\joule, 1000/\nano\joule
+  }
+}
+
+\begin{codeexample}
+\begin{verbatim}
+\drefkeys{
+  unit/new scala={
+    1/y, 365/d, 24/h, 60/m, 60/s, 1000/ms, 1000/us, 1000/ns
+  },
+  unit/new scala={
+    1/\kilo\joule, 1000/\joule, 1000/\milli\joule,
+    1000/\micro\joule, 1000/\nano\joule
+  }
+}
+\end{verbatim}
+\end{codeexample}
+
+\Option[(no default)]{/dref/unit/scale to=\meta{unit}}
+
+With a defined scala, you can scale to any unit on that scala automatically. In the example, we use unit to set the unit
+of plain value to nano joule, and scale everything to milli joule.
+
+\begin{example}
+\foreach \a in {1234, 4135413, 213516513245, 24} {%
+  \drefformat[unit=\nano\joule, unit/scale to=\milli\joule]{\a}\\
+}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\foreach \x in {1234, 4135413, 213516513245, 24} {%
+  \drefformat[
+    unit=\nano\joule,
+    unit/scale to=\milli\joule]{\x}\\
+}
+\end{verbatim}
+\end{codeexample}
+
+\Option[(default \textbf 50)]{/dref/unit/scale to auto=\meta{optimum number}}
+
+With \texttt{scale to auto}, the appropriate unit is chosen automatically. The algorithm tries every unit on the scala
+and chooses the unit, where the numerical value after scaling is nearest to the \meta{optimum number}. So with a optimum
+number of 50, 5000 seconds are scaled to \drefformat[unit=s, unit/scale to auto]{5000} instead of \drefformat[unit=s,
+unit/scale to=h]{5000}.
+
+
+\begin{example}
+\foreach \a in {1234, 4135413, 213516513245, 24} {%
+  \drefformat[unit=ms, unit/scale to auto]{\a}\\
+}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\foreach \x in {1234, 4135413, 213516513245, 24} {%
+  \drefformat[unit=ms, unit/scale to auto]{\x}\\
+}
+\end{verbatim}
+\end{codeexample}
+
+
+\subsection{Relating Datapoints}
+
+\Macro[(@calc, @set)]{\drefrel*[\meta{options}]\{\meta{key or value}\}}
+\Macro[(@calc, @print, @set)]{\drefrel[\meta{options}]\{\meta{key or value}\}}
+
+Often, datapoints are set in relation to each other. This can either be done with \macro{\drefcalc} or, more explictily,
+with \macro{\drefrel}. The different options that come along \macro{\drefrel}, add steps to the @calc phase and can,
+therefore, be combinated with any other dref macro that includes the @calc phase.
+
+All operations operate on the current result, which is initially the given key or value from the mandatory argument.
+
+\begin{example}
+  \drefrel[percent of=123]{40}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+  \drefrel[percent of=123]{40}
+\end{verbatim}
+\end{codeexample}
+
+The different relation operations try to have a speaking name, such that the \TeX{} code is easily understandable by the
+writer. This explicit notation aims to prevent common mistakes, like confusing denominator and numerator.
+
+The starred version of \macro\drefrel does not print any number, but only saves the result in \macro\drefresult. Instead of
+only taking datapoint keys, \macro\drefrel, as well as the relating operations, take either a key or a bare number as you can
+see from the example.
+
+\Option[(no default)]{/dref/scale by=\meta{key or value}}
+
+Scales the current value by the given factor, which must be unit less. The resulting unit is untouched.
+
+\Option[(no default)]{/dref/percent}
+
+Scales the current value by 100. The unit is not changed.
+
+\Option[(no default)]{/dref/negate}
+
+Scales the current value by -1. The resulting unit is untouched.
+
+\Option[(no default)]{/dref/divide by=\meta{key or value}}
+
+Divides the current value by the given factor, which must be unit less. The resulting unit is untouched.
+
+
+\Option[(no default)]{/dref/abs}
+
+Calculate the absolute value.
+
+\Option[(no default)]{/dref/factor of=\meta{key or value}}
+\Option[(no default)]{/dref/percent of=\meta{key or value}}
+
+The \textbf{factor of} operation gives the portion the current value in relation to the given base value. In easy words:
+a division. This macro ensures, that base and current vale have the same unit or are unit less. The result of this
+operation is unit less. The \textbf{percent of} operation, furthermore, scales the result with 100 to get a percentage.
+
+\Option[(no default)]{/dref/increase from=\meta{key or value}}
+\Option[(no default)]{/dref/decrease from=\meta{key or value}}
+\Option[(no default)]{/dref/increase factor from=\meta{key or value}}
+\Option[(no default)]{/dref/decrease factor from=\meta{key or value}}
+\Option[(no default)]{/dref/increase percent from=\meta{key or value}}
+\Option[(no default)]{/dref/decrease percent from=\meta{key or value}}
+
+In a situation, where a datapoint is the result of a changed experiment setup, the value normally shows an increased or decrease
+numerical value. This family of operations calculates this delta, assuming it is an increase or decrease. The factor
+operations scale the result to the base value, and the percent operations give this scaled value as a percentage.
+
+\begin{example}
+  \drefrel[increase from=500]{525}\\
+  \drefrel[increase factor from=500,fixed]{525}\\
+  \drefrel[increase percent from=500]{525}\,\%
+\end{example}
+\begin{codeexample}
+\begin{verbatim}
+  \drefrel[increase from=500]{525}\\
+  \drefrel[increase factor from=500,fixed]{525}\\
+  \drefrel[increase percent from=500]{525}\,\%
+\end{verbatim}
+\end{codeexample}
+
+\subsection{Helper Utilities}
+
+\Macro{\drefrow[\meta{options}]\{\meta{comma-separated list}\}\{\meta{key template}\}}
+\Macro{\drefrow*\{\meta{comma-separated list}\}\{\meta{template}\}}
+
+ Often different columns in a table have to be obtained from your data
+ points. Often those rows and columns are similar. Generating parts of
+ tables within \LaTeX is very tricky, so \dataref provides you
+ with \macro{\drefrow}. This macro iterates over a comma-separated list
+ 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.
+
+ Both, unstarred and starred variant take a template (a macro body) that is expanded once for every item in the given
+ list. The first replacement \verb|#1| is list item and the second \verb|#2| is the current index starting from 0. The
+ unstarred variant interprets the expanded result as a datapoint key and uses \macro\dref to expand it; the optional
+ parameter is passed through to every invocation of \macro\dref.
+ The starred variant does not wrap the result into \macro\dref, and, therefore, is more flexible.
+
+ \begin{example}
+   \begin{tabular}{|c|c|c|}\hline
+   \drefrow{dead after 24h,dead after 48h,recovered}%
+                           {/control group/#1}\\\hline
+   \drefrow{dead after 24h,dead after 48h,recovered}%
+                           {/med A/#1}\\\hline
+   \end{tabular}
+ \end{example}
+ \begin{codeexample}
+\begin{verbatim}
+\begin{tabular}{|c|c|c|}\hline
+  \drefrow{dead after 24h,dead after 48h,recovered}
+           {/control group/#1}\\\hline
+  \drefrow{dead after 24h,dead after 48h,recovered}%
+          {/med A/#1}\\\hline
+\end{tabular}
+\end{verbatim}
+ \end{codeexample}
+
+
+ \Macro[(@calc)]{\drefassert\{\meta{expr}\}}
+
+ Sometimes the underlying data changes while you are writing. But what
+ if your prose text relies on certain characteristics of the data. \macro{\drefassert} uses a pgfmath
+ expression that evaluates to \verb|true| or \verb|false|. When the
+ assertion holds (\verb|true|) nothing happens, only a terminal message
+ is printed. When it does not hold (\verb|false|) the compilation is aborted.
+
+\begin{example}
+\drefassert{data("/control group/mice count") > 30}
+Of the more than thirty infected mice...
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\drefassert{data("/control group/mice count") > 30}
+Of the more than thirty infected mice...
+\end{verbatim}
+\end{codeexample}
+
+ \Option[(default \textbf{true})]{/dref/noassert=\meta{true or false}}
+
+ The \textbf{noassert} deescalates all assertion errors to mere warnings. This option can also be given at the
+ \cmd{\usepackage} invication.
+
+\Option[(no default, initially \textbf{none}, choice)]{/dref/annotate=\meta{annotation type}}
+\Option[(choice item)]{/dref/annotate=none}
+\Option[(choice item)]{/dref/annotate=footnote}
+\Option[(choice item)]{/dref/annotate=pdfcomment}
+\Option[(choice item)]{/dref/annotate=typeout}
+
+While writing a document it is desirable to know, what key is used, while writing the text and generating the document.
+Therefore \dataref provides the possibility to annotate values. The default option \textbf{none} disables this kind of
+annotation. The \textbf{pdfcomment} option uses pdf annotations. Be aware that those annotations work properlyy only on
+a few selected PDF readers\footnote{In doubt use Acrobat}.
+
+\begin{example}[6cm]
+  \drefkeys{annotate=footnote}
+  \dref*{/control group/mice race}
+  \dref{/control group/mice count}
+  \drefcalc[annotate=pdfcomment]{100/3}
+\end{example}\begin{codeexample}
+\begin{verbatim}
+\drefkeys{annotate=footnote}
+\dref*{/control group/mice race}
+\dref{/control group/mice count}
+\drefcalc[annotate=pdfcomment]{100/3}
+\end{verbatim}
+\end{codeexample}
+
+
+ \subsection{Datagraphy}\label{sec:datagraphy}
+
+ \Macro{\drefusagereport}
+ \Option{[usagereport]}
+ \Option{[refall]}
+
+ With the \textbf{usagereport} package option enabled, \macro{\drefusagereport} generates a usagereport of all referenced
+ 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
+
+\end{document}
+
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% End:

Deleted: trunk/Master/texmf-dist/doc/latex/dataref/dataref.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty	2017-01-06 22:24:20 UTC (rev 42882)
+++ trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty	2017-01-06 22:25:07 UTC (rev 42883)
@@ -1,13 +1,5 @@
+%%  Copyright 2013-2017 Christian Dietrich
 %%
-%% This is file `dataref.sty',
-%% generated with the docstrip utility.
-%%
-%% The original source files were:
-%%
-%% dataref.dtx  (with options: `package')
-%% dataref.dtx
-%%  Copyright 2013 Christian Dietrich
-%% 
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
 %% of this license or (at your option) any later version.
@@ -15,16 +7,15 @@
 %%   http://www.latex-project.org/lppl.txt
 %% and version 1.3 or later is part of all distributions of LaTeX
 %% version 2005/12/01 or later.
-%% 
+%%
 %% This work has the LPPL maintenance status `maintained'.
-%% 
+%%
 %% The Current Maintainer of this work is Christian Dietrich
-%% 
+%%
 %% This work consists of the files dataref.dtx and dataref.ins
 %% and the derived file dataref.sty.
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
-\ProvidesPackage{dataref}
- [2015/09/17 v0.5 dataref]
+\ProvidesPackage{dataref}[2017/01/06 v0.6 dataref]
 
 \ifx\drefloaded\undefined
   \let\drefloaded=\relax
@@ -31,17 +22,17 @@
 \else
   \expandafter\endinput
 \fi
-\ifx\PackageError\undefined
-  \def\dref at error#1{\immediate\write-1{Package dref: Error! #1.}}%
-\else
-  \def\dref at error#1{\PackageError{dref}{#1}{}}%
-\fi
+
+\def\drefutil at packageerror#1#2#3{\errhelp{#3}\errmessage{Package #1 Error: #2}}
+\def\drefutil at packagewarning#1#2{\immediate\write17{Package #1: Warning! #2.}}
+\def\dref at error#1{\drefutil at packageerror{dref}{#1}{}}
+\def\dref at warning#1{\drefutil at packagewarning{dref}{#1}}
+
 \RequirePackage{pgf}
+\usepgflibrary{fpu}
 \RequirePackage{iftex}
 \RequirePackage{kvoptions}
-\usepgflibrary{fpu}
-\usepackage{etoolbox}
-\RequirePackage{xcolor}
+\RequirePackage{etoolbox}
 
 \SetupKeyvalOptions{
   family=dref,
@@ -55,72 +46,297 @@
 \DeclareBoolOption{ignoremissing}
 \DeclareBoolOption{noassert}
 \ProcessKeyvalOptions*
-\def\dref at set#1#2{%
-  \edef\dref at set@tmp{#2}%
-  \expandafter\pgfkeys at temptoks\expandafter{\dref at set@tmp}%
-  \expandafter\xdef\csname
-  pgfk@\dref at datapath#1\endcsname{\the\pgfkeys at temptoks}%
+
+% Load & Store Layer
+
+\def\dref at set#1#2#3{%
+  \edef\dref at set@path{#3}%
+  \edef\dref at set@value{#2}%
+  \expandafter\pgfkeys at temptoks\expandafter{\dref at set@value}%
+  \expandafter\xdef%
+      \csname pgfk@\dref at datapath\dref at set@path\endcsname%
+  {\the\pgfkeys at temptoks}%
+  % Setting the Unit is a little bit more tricky
+  %% Unit Path Assembly
+  \expandafter\def%
+  \expandafter\dref at set@unitpath%
+  \expandafter{%
+  \csname pgfk@\dref at datapath\dref at set@path @unit\endcsname}%
+  \expandafter\gdef\dref at set@unitpath{#1}%
   \ifdref at refall%
-     \expandafter\dref at found\expandafter{\dref at datapath#1}{0}
-     \expandafter\dref at referenced\expandafter{\dref at datapath#1}{0}%
+     \expandafter\dref at found\expandafter{\dref at set@path}{0}
+     \expandafter\dref at referenced\expandafter{\dref at set@path}{0}%
   \fi%
+  \dref at debug{\dref at set@path = \dref at set@value (\detokenize{#1})}%
 }
-\def\drefset#1#2{\dref at set{#1}{#2}}
 
-\def\dref at expandable#1{%
-  \pgfkeysifdefined{\dref at datapath\csuse{dref at prefix}#1}{%
-    \pgfkeysvalueof{\dref at datapath\csuse{dref at prefix}#1}%
+\def\dref at load#1#2#3{%
+  \edef\dref at load@path{#1}%
+  \pgfkeysifdefined{\dref at datapath\dref at load@path}{%
+    \pgfkeysgetvalue{\dref at datapath\dref at load@path}{#2}%
+    \pgfkeysifdefined{\dref at datapath\dref at load@path @unit}{%
+      \pgfkeysgetvalue{\dref at datapath\dref at load@path @unit}{#3}%
+    }{%
+      \def#3{}%
+    }%
   }{%
-    \ifdref at ignoremissing%
-      \dref at defaultvalue%
-    \else%
-      \typeout{Dref error: undefined key `#1'}\QUIT%
-    \fi%
+    \edef#2{\dref at defaultvalue}%
+    \def#3{}%
   }%
 }
-\def\dref at unexpandable#1{%
-  \def\drefcurrentkey{\dref at datapath\csuse{dref at prefix}#1}%
-  \pgfkeysifdefined{\drefcurrentkey}{%
-    \edef\dref at thepage{\arabic{page}}%
-    \immediate\write\@auxout{\noexpand\dref at found{\drefcurrentkey}{\dref at thepage}}%
+
+\def\drefifdefined#1{%
+  \pgfkeysifdefined{\dref at datapath\drefprefix #1}%{then}{else}
+}
+
+\def\dref at set@fromaux#1#2#3{%
+  \drefifdefined{#2}{%
+    \dref at warning{"\drefprefix #2" set before beginning of document, \string\drefsave{} is ignore}%
   }{%
-    \immediate\write\@auxout{\noexpand\dref at notfound{\drefcurrentkey}{\dref at thepage}}%
+    \dref at set{#1}{#2}{#3}%
   }%
-  \immediate\write\@auxout{\noexpand\dref at referenced{\drefcurrentkey}{\dref at thepage}}%
 }
-\newcommand{\drefifdefined}[3]{
-  \def\drefcurrentkey{\dref at datapath\csuse{dref at prefix}#1}%
-  \pgfkeysifdefined{\drefcurrentkey}{#2}{#3}%
+
+\def\drefkeys#1{\pgfkeys{/dref/.cd,#1}}
+\def\drefprefix{\pgfkeysvalueof{/dref/prefix}}
+\newif\ifdref at debug
+\def\dref at debug#1{\ifdref at debug \immediate\write17{Package dref: Debug: #1.}\fi}
+
+\drefkeys{
+  .is family,
+  .search also={/pgf/number format},
+  % The @init action is used to initialize all other actions
+  @[/.code={\begingroup%
+    \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}% No more dimensions too large
+    \def\drefunit{}% At first we are unitless
+    \aftergroup\edef%
+    \aftergroup\drefresult%
+    \aftergroup{%
+      \aftergroup\drefresult at smuggle%
+      \aftergroup}%
+    \aftergroup\expandafter%
+    \aftergroup\def%
+    \aftergroup\expandafter%
+    \aftergroup\drefunit%
+    \aftergroup\expandafter%
+    \aftergroup{%
+      \aftergroup\drefunit at smuggle%
+      \aftergroup}
+  },
+  @]/.code={% We smuggle \drefresult after the current group
+    \xdef\drefresult at smuggle{\drefresult}%
+    \xdef\drefunit at smuggle{\expandonce\drefunit}%
+    \endgroup%
+  },
+  @init/.style={},
+  % The \drefresult macro holds the current value,
+  % it can be set by value=
+  prefix/.initial={},
+  value/.code={\edef\drefresult{#1}\def\drefunit{}},
+  value=0,
+  path/.estore in={\drefcurrentpath},
+  @init/.append style={},
+  % \drefresult can be set by the @load action
+  @load key to/.code n args={3}{%
+    \dref at load{\drefprefix #1}{#2}{#3}%
+  },
+  @get key to/.style n args={3}{
+    @check key={#1},
+    @reference key={#1},
+    @load key to={#1}{#2}{#3},
+  },
+  @get/.style={%
+    @get key to={\drefcurrentpath}{\drefresult}{\drefunit},
+    unit/@format enable,
+  },
+  % For most commands, we want to check whether a key exists.
+  @check key/.code={%
+    \drefifdefined{#1}{}{%
+      \ifdref at ignoremissing%
+        \dref at warning{undefined key `\drefprefix #1'}%
+      \else%
+        \dref at error{undefined key `\drefprefix #1'}%
+      \fi%
+    }%
+  },
+  % The @set action is used to pipe out \drefresult, before we can
+  % print it. For example, we can use it to save the result to a new
+  % key.
+  @init/.append style={
+    @set/.code={},
+  },
+  set/.style={
+    @set/.append code={%
+      \expandafter\dref at set\expandafter{\drefunit}{\drefresult}{\drefprefix #1}%
+    }
+  },
+  save/.style={
+    set={#1},
+    @set/.append code={%
+      \immediate\write\@auxout{%
+        \noexpand\dref at set@fromaux{\expandonce\drefunit}{\drefresult}{\drefprefix #1}%
+      }%
+    }
+  },
+  to macro/.style={
+    @set/.append code={%
+      \aftergroup\edef%
+      \aftergroup#1%
+      \aftergroup{%
+        \aftergroup\drefresult%
+        \aftergroup}}
+  },
+  %
+  debug/.is if=dref at debug,
+  ignoremissing/.is if=dref at ignoremissing,
+  defaultvalue/.store in=\dref at defaultvalue,
 }
-\def\dref{\@ifstar\@@dref\@dref}
-\newcommand{\@dref}[2][]{% Unstarred
-  \edef\dref at argument{#2}%
-  \expandafter\dref at unexpandable\expandafter{\dref at argument}%
-  \pgfmathparse{\dref at expandable{#2}}%
-  \dref at format[#1]{\pgfmathresult}%
-  \dref at mkannotate{\textbackslash dref\{#2\}}%
+
+\csdef{dref at ifnum@0}{}
+\csdef{dref at ifnum@1}{}
+\csdef{dref at ifnum@2}{}
+\csdef{dref at ifnum@3}{}
+\csdef{dref at ifnum@4}{}
+\csdef{dref at ifnum@5}{}
+\csdef{dref at ifnum@6}{}
+\csdef{dref at ifnum@7}{}
+\csdef{dref at ifnum@8}{}
+\csdef{dref at ifnum@9}{}
+\csdef{dref at ifnum@-}{}
+\csdef{dref at ifnum@.}{}
+\def\dref at load@ifkey at firstchar#1#2\@nnil{#1}
+\drefkeys{%
+  @get key or value to/.code n args={3}{%
+    \edef\dref at load@path{#1}%
+    \edef\dref at firstchar{\expandafter\dref at load@ifkey at firstchar \dref at load@path\@nnil}%
+    \ifcsdef{dref at ifnum@\dref at firstchar}{%
+      \edef#2{\dref at load@path}%
+    }{%
+      \drefkeys{@get key to={#1}{#2}{#3}}%
+    }%
+  },
+  @get key or value/.style={
+    @get key or value to={\drefcurrentpath}{\drefresult}{\drefunit},
+    unit/@format enable,
+  },
 }
-\newcommand{\@@dref}[2][]{% Starred
-  \edef\dref at argument{#2}%
-  \expandafter\dref at unexpandable\expandafter{\dref at argument}%
-  \expandafter\gdef\expandafter\dref at dref@output\expandafter{\expandafter\dref at expandable\expandafter{\dref at argument}}%
-  \dref at dref@output%
-  \dref at mkannotate{\textbackslash dref*\{#2\}}%
+
+
+% Print layer
+\drefkeys{
+  @init/.append style={
+    @print result/.code={},
+    @print unit/.code={}
+  },
+  @print/.style={@print result, @print unit},
+  print default/.initial={pgf},
+  print/.is choice,
+  print/no/.style={
+    @print result/.code={},
+    @print unit/.code={}
+  },
+  print/default/.style={%
+    print default/.get=\dref at print@format,%
+    print/.expand once=\dref at print@format,
+  },
+  print/raw/.style={
+    @print result/.code={\drefresult}
+  },
+  print/typeout/.style={
+    @print result/.code={\typeout{#1\drefresult}},
+    @print unit/.code={\typeout{\expandonce\drefunit}},
+  },
+  print/show/.style={
+    @print result/.append code={\show\drefresult},
+  },
+  print/pgf/.style={
+    @print result/.code={%
+      \pgfmathprintnumber{\drefresult}%
+    }
+  },
+  print/siunitx/.style={
+    @print result/.code={%
+      \num{\drefresult}%
+    }
+  },
 }
+
+% Compatibility with underscore package
+\def\dref at normalunderscore{_}
+\edef\dref at catcode@underscore{\the\catcode`_}
+\catcode`_=13
+\def\dref at catcode@setup{%
+  \edef _{\dref at normalunderscore}%
+}
+\catcode`_=\dref at catcode@underscore
+
+
+\AtBeginDocument{%
+  \ifdim 13pt = \the\catcode`_pt%
+    % _ is an active character
+    \drefkeys{@[/.append code={%
+        \dref at catcode@setup%
+     }%
+   }%
+  \fi%
+}
+
+\newcommand{\drefset}[3][]{%
+  % I put this version here, since it
+  % provides a sped up mass setting of keys
+  \begingroup%
+    \ifdim 13pt = \the\catcode`_pt%
+      \dref at catcode@setup%
+    \fi%
+    \edef\drefresult{#3}%
+    \def\drefunit{}%
+    \drefkeys{#1}%
+    \expandafter\dref at set\expandafter{\drefunit}%
+       {\drefresult}{\drefprefix #2}%
+  \endgroup%
+}
+
+\newcommand{\drefsave}[3][]{%
+  \drefkeys{@[, @init, value={#3}, #1, save={#2}, @set, @]}%
+}
+
+\newcommand{\drefinput}[2][]{%
+  \begingroup
+  \drefkeys{prefix/.append={#1}}
+  \input{data/#2}
+  \endgroup
+}
+
+
+\def\drefref#1{\drefkeys{@reference key={#1}}}
+
+% From here on, everything should be implemented using pgfkeys
+\protected\def\dref{\@ifstar\dref at starred\dref at unstarred}
+\newcommand{\dref at unstarred}[2][]{%
+  \drefkeys{@[, @init, print=default, path={#2}, #1, @get, @calc, @print, @set,%
+    @annotate={\textbackslash dref[#1]\{#2\}}, @]%
+  }%
+}
+\newcommand{\dref at starred}[2][]{%
+  \drefkeys{@[, @init, print=raw,     path={#2}, #1, @get, @calc, @print, @set,%
+    @annotate={\textbackslash dref*[#1]\{#2\}}, @]%
+  }%
+}
+\def\drefgetvalue#1#2{%
+  \drefkeys{@[, at init, path={#1}, to macro={#2}, @get, @set, @]}%
+}
 \def\drefvalueof#1{%
-  \dref at expandable{#1}%
+  \pgfkeysvalueof{\dref at datapath \drefprefix #1}%
 }
-\def\drefref#1{%
-  \dref at unexpandable{#1}%
-}
+
 %% dref at ifstrmatch is copied from etextools, but etextools is
 %% incompatible with etoolbox
 %% \ifstrmatch{ pattern }{ string }{ true }{ false }
 \ifPDFTeX%
-\let\dref at strmatch\pdfmatch
+  \let\dref at strmatch\pdfmatch
 \fi
 \ifLuaTeX%
-\newcommand{\dref at strmatch}[2]{%
+ \newcommand{\dref at strmatch}[2]{%
   \directlua{%
     local match = string.find("\luaescapestring{#2}", "\luaescapestring{#1}");%
     if match then
@@ -160,6 +376,20 @@
     \dolistcsloop{dref at helps}%
   }%
 }
+\drefkeys{
+  @reference key/.code={%
+    \edef\dref at thepage{\arabic{page}}%
+    \drefifdefined{#1}{%
+      \immediate\write\@auxout{%
+        \noexpand\dref at found{\drefprefix #1}{\dref at thepage}}%
+    }{%
+      \immediate\write\@auxout{%
+        \noexpand\dref at notfound{\drefprefix #1}{\dref at thepage}}%
+    }%
+    \immediate\write\@auxout{%
+      \noexpand\dref at referenced{\drefprefix #1}{\dref at thepage}}%
+  }
+}
 \def\dref at notfound#1#2{
   \ifdref at usagereport%
     \dref at usagereport@notfound{#1}{#2}%
@@ -175,18 +405,9 @@
     \dref at usagereport@referenced{#1}{#2}%
   \else\relax\fi%
 }
-\def\dref at let#1{%
-  \def\@tmp##1=##2;{\pgfmathdeclarefunction*{##1}{0}{\pgfmathparse{##2}}}%
-  \renewcommand*{\do}[1]{\@tmp##1;}%
-  \ifstrempty{#1}{}{%
-    \docsvlist{#1}%
-  }%
-}
 
-\def\dreflet#1{%
-  \dref at let{#1}%
-}
 
+% The data("") || d() Parser
 \def\dref at parser#1#2{%
   \edef\@tempa{#1}%
   \csdef{dref at parser@result}{}%
@@ -221,77 +442,67 @@
 \csdef{dref at parser@d@(}{\dref at parser@tillparen}
 
 \def\dref at parser@tillquote#1")#2\@nnil{%
-  \drefref{\dref at data@math at prefix #1}%
-  \csxdef{dref at parser@result}{\csuse{dref at parser@result}(\drefvalueof{\dref at data@math at prefix #1})}%
+  \drefkeys{
+    @get key to={#1}{\dref at math@value}{\dref at math@unit},
+    unit/@combine=\dref at math@unit,
+  }%
+  \csxdef{dref at parser@result}{\csuse{dref at parser@result}(\dref at math@value)}%
   \csdef{dref at parser@state}{}%
   \ifblank{#2}{}{\dref at parser@parse#2\@nnil}}
 
 \def\dref at parser@tillparen#1)#2\@nnil{%
-  \drefref{\dref at data@math at prefix #1}%
-  \csxdef{dref at parser@result}{\csuse{dref at parser@result}(\drefvalueof{\dref at data@math at prefix #1})}%
+  \drefkeys{@get key to={#1}{\dref at math@value}{\dref at math@unit},
+            unit/@combine=\dref at math@unit}%
+  \csxdef{dref at parser@result}{\csuse{dref at parser@result}(\dref at math@value)}%
   \csdef{dref at parser@state}{}%
   \ifblank{#2}{}{\dref at parser@parse#2\@nnil}}%
 
 \def\dref at parser@end#1#2\@nnil{}
-\csdef{dref at parser@@}{\typeout{end}\dref at parser@end}
+\csdef{dref at parser@@}{\dref at parser@end}
 
-\newcommand{\dref at calc}[1]{%
-  %\typeout{Before: '#1'}%
-  \dref at parser{#1}{\dref at calc@@argA}%
-  %\typeout{After:  \dref at calc@@argA}%
-  \pgfmathparse{\dref at calc@@argA}%
+\drefkeys{
+  @init/.append style={%
+    @calc/.code={},%
+  },
+  @calc pgf/.style={
+    @calc/.append code={%
+      \dref at parser{#1}{\dref at calc@@ready}%
+      \pgfmathparse{\dref at calc@@ready}%
+      \dref at debug{#1 -> \dref at calc@@ready = \pgfmathresult}%
+      \edef\drefresult{\pgfmathresult}%
+     }
+  }
 }
 
-\pgfset{/dref/let/.code={\dref at let{#1}}}
-\pgfset{/dref/prefix/.code={\csdef{dref at prefix}{#1}}}
-\def\drefprefix#1{\csdef{dref at prefix}{#1}}
-\def\drefresult{0}
-\def\drefcalc{\@ifstar\@@drefcalc\@drefcalc}
-\newcommand{\@drefcalc}[2][]{% Unstarred
-  \begingroup%
-  \pgfset{/pgf/number format/.cd, #1}%
-  \dref at calc{#2}%
-  \pgfmathprintnumberto[fixed,assume math mode=true,precision=10,1000 sep={}]{\pgfmathresult}{\drefresult}%
-  \xdef\drefresult{\drefresult}%
-  \dref at format{\pgfmathresult}%
-  \dref at mkannotate{\textbackslash drefcalc\{#2\}}%
-  \endgroup%
+\protected\def\drefcalc{\@ifstar\drefcalc at starred\drefcalc at unstarred}
+\newcommand{\drefcalc at unstarred}[2][]{% Unstarred
+  \drefkeys{@[, at init, print=default, @calc pgf={#2}, #1, @calc, @print, @set,%
+    @annotate={\textbackslash drefcalc[#1]\{#2\}},@]}%
 }
-\newcommand{\@@drefcalc}[2][]{ % Starred
-   \begingroup%
-   \pgfset{/pgf/number format/.cd, #1}%
-   \dref at calc{#2}%
-   \pgfmathprintnumberto[fixed,assume math mode=true,precision=10,1000 sep={}]{\pgfmathresult}{\drefresult}%
-   \xdef\drefresult{\drefresult}%
-   \endgroup%
+\newcommand{\drefcalc at starred}[2][]{ % Starred
+  \drefkeys{@[, at init, @calc pgf={#2}, #1, @calc, @set,%
+    @annotate={\textbackslash \drefcalc*[#1]\{#2\}},@]%
+  }%
 }
-\newcommand{\dref at format}[2][]{%
-  \pgfmathprintnumber[#1]{#2}%
+
+\newcommand{\drefformat}[2][]{%
+  \drefkeys{@[, at init, print=default, value={#2}, #1, @calc, @print, @]}%
 }
-\newcommand{\drefformat}[2][]{\dref at format[#1]{#2}}
 
-\gdef\dref at data@math at prefix{}
-\pgfmathdeclarefunction{data}{1}{%
-        \begingroup%
-                \dref at unexpandable{\dref at data@math at prefix#1}%
-                \pgfmathparse{\dref at expandable{\dref at data@math at prefix#1}}%
-                \pgfmath at smuggleone\pgfmathresult%
-        \endgroup%
-}
 \long\def\drefprojection#1#2#3{%
   \begingroup%
-     \def\dref at data@math at prefix{#1}%
-     \def\rename##1##2{\dref at unexpandable{#1/##1}\drefset{#2/##2}{\dref at expandable{#1/##1}}}%
-     \def\id##1{\rename{##1}{##1}}%
-     \def\calc##1##2{%
-       \begingroup%
-          \drefcalc{##1}%
-          \xdef\dref at project@result{\drefresult}
-       \endgroup%
-       \drefset{#2/##2}{\dref at project@result}%
-      }%
-     #3%
-     \endgroup%
+  \def\rename##1##2{%
+    \drefkeys{@init, path={#1/##1}, set={#2/##2}, @get, @set}%
+  }%
+  \def\id##1{\rename{##1}{##1}}%
+  \def\calc##1##2{%
+    \edef\drefprojection at prefix{\drefprefix}%
+    \drefcalc[prefix={#1}]{##1}%
+    \edef\drefprefix{\drefprojection at prefix}%
+    \drefset{#2/##2}{\drefresult}%
+  }%
+  #3%
+  \endgroup%
 }
 
 
@@ -313,8 +524,8 @@
     }%
     \expandafter\def\expandafter\arglist\expandafter{#1}%
     \expandafter\docsvlist\expandafter{\arglist}%
-    \@tempcntb=0\relax
-    {\loop\ifnum\@tempcntb<\drefcellcount
+    \@tempcntb=0\relax%
+    {\loop\ifnum\@tempcntb<\drefcellcount%
       \advance\@tempcntb by 1\relax%
       \ifnum \@tempcntb = 1%
         \edef\@@next{\csuse{@cell\the\@tempcntb}}%
@@ -330,33 +541,27 @@
         \@@next}%
       \repeat}%
   }%
-  \typeout{LINE: \the\dref at toks}%
-  \expandafter\scantokens\expandafter{\the\dref at toks}}
+  \expandafter\scantokens\expandafter{\the\dref at toks}%
+}
 
-\long\def\drefrow{\@ifstar\@@drefrow\@drefrow}
-\def\@drefrow#1#2{\dref at makerow{#1}{\dref{#2}}} % Unstarred
-\def\@@drefrow#1#2{\dref at makerow{#1}{#2}} % Starred
+\long\def\drefrow{\@ifstar{\drefrow at starred}{\drefrow at unstarred}}
+\newcommand{\drefrow at unstarred}[3][]{\dref at makerow{#2}{\dref[#1]{#3}}\ignorespaces}
+\def\drefrow at starred#1#2{\dref at makerow{#1}{#2}\ignorespaces}
 
 \expandafter\ifstrequal\expandafter{\dref at annotate}{pdfcomment}{
   \RequirePackage{pdfcomment}
 }
 
-\def\dref at mkannotate@none#1{\relax}
-\def\dref at mkannotate@footnote#1{\footnote{\texttt{#1}}}
-\def\dref at mkannotate@pdfcomment#1{\pdfcomment[opacity=0.4,voffset=2ex]{#1}}
 
-\newcommand{\dref at mkannotate}[1]{%
-  \ifcsdef{dref at mkannotate@\dref at annotate}{%
-    \csuse{dref at mkannotate@\dref at annotate}{#1}%
-    }{%
-      \dref at error{Value for annotate not supported: '\dref at annotate'}%
-    }%
+\drefkeys{
+  annotate/.is choice,
+  annotate/none/.style={@annotate/.code={\relax}},
+  annotate/footnote/.style={@annotate/.code={\footnote{\texttt{##1}}}},
+  annotate/pdfcomment/.style={@annotate/.code={\pdfcomment[opacity=0.4,voffset=2ex]{##1}}},
+  annotate/typeout/.style={@annotate/.code={\typeout{##1}}},
+  annotate=\dref at annotate,
 }
 
-\newcommand{\drefannotate}[1]{%
-  \renewcommand{\dref at annotate}{#1}%
-}
-
 %% Usagereport
 \ifdref at usagereport
   \RequirePackage{xtab}
@@ -379,7 +584,7 @@
 \expandafter\def\expandafter\dref at usagereport@strippath@\dref at datapath#1\blanktest{#1}
 
 \newcommand{\dref at usagereport@strippath}[1]{%
-  \expandafter\dref at ifstrmatch\expandafter{\expandafter^\dref at datapath.*$}{#1}%
+  \expandafter\dref at ifstrmatch\expandafter{\expandafter^\dref at datapath.*$}{#1}%$
     {\dref at usagereport@strippath@#1\blanktest}%
     {#1}%
 }
@@ -402,7 +607,7 @@
     {\hypertarget{#1}{\dref at usagereport@strippath{#1}}}%
     {\dref at usagereport@strippath{#1}}}%
   & \dref at usagereport@formatreferencelist{#1}%
-  & \pgfkeysifdefined{#1}{\pgfkeysvalueof{#1}}{\textbf{\color{red}undefined}}%
+  & \drefifdefined{#1}{\dref*[@reference key/.code={}]{#1}}{\textbf{undefined}}%
 }
 
 \def\drefusagereportaftergroup{}
@@ -492,7 +697,7 @@
 }
 \newcommand{\drefusagereport}{%
   \ifdref at usagereport%
-  \ifcsvoid{dref at usagereport@keys}{\typeout{EMPTY}}{%
+  \ifcsvoid{dref at usagereport@keys}{}{%
   \begingroup%
   \renewcommand{\do}[1]{%
     \ifinlistcs{##1}{dref at usagereport@matchedkeys}{}{%
@@ -505,142 +710,243 @@
   }% csempty @keys
   \fi%
 }
+\drefkeys{
+  noassert/.is if=dref at noassert
+}
 \newcommand{\drefassert}[1]{%
   \begingroup%
     \drefcalc*{#1}%
-    \expandafter\ifstrequal\expandafter{\drefresult}{1}{%
-      \typeout{Assertion holds: #1}%
-    }{%
+    \ifdim\drefresult pt = 0pt%
       \ifdref at noassert%
-        \typeout{Assertion failed: #1}%
+        \dref at warning{Assertion failed: #1}%
       \else%
         \dref at error{Assertion failed: #1}%
-      \fi%
-   }%
+        \fi%
+     \else
+       \dref at warning{Assertion holds: #1}%
+     \fi%
   \endgroup%
 }
-\newif\if at dref@valuemustderef%
-\newif\if at dref@basemustderef%
-\newif\if at dref@increase%
-\newif\if at dref@product%
-\newif\if at dref@factor%
-\newif\if at dref@delta%
-\newif\if at dref@percent%
-\newif\if at dref@abs%
-\newif\if at dref@neg%
-\pgfkeys{%
-  \dref at datapath/.DUMMY/.initial=1
+\drefkeys{%
+  factor of/.style={%
+    @get key or value to={#1}{\drefrel at tmp}{\drefrel at tmpunit},
+    unit/@assert compatible=\drefrel at tmpunit,
+    @calc pgf/.expanded={(\noexpand\drefresult)/(\drefrel at tmp)},
+    @calc/.append code={\def\drefunit{}},
+  },
+  percent/.style={
+    @calc pgf={100 * (\drefresult)},
+  },
+  percent of/.style={
+    factor of=#1, percent,
+    @calc/.append code={\def\drefunit{}},
+  },
+  scale by/.style={
+    @get key or value to={#1}{\drefrel at tmp}{\drefrel at tmpunit},%
+    unit/@assert unitless=\drefrel at tmpunit,
+    @calc pgf/.expanded={(\drefrel at tmp) * (\noexpand\drefresult)},
+  },
+  product/.style={scale by={#1}},
+  divide by/.style={
+    @get key or value to={#1}{\drefrel at tmp}{\drefrel at tmpunit},%
+    unit/@assert unitless=\drefrel at tmpunit,
+    @calc pgf/.expanded={(\noexpand\drefresult) / (\drefrel at tmp)},
+  },
+  divide/.style={divide by},
+  product/.style={scale by={#1}},
+  increase factor from/.style={
+    @get key or value to={#1}{\drefrel at tmp}{\drefrel at tmpunit},
+    unit/@assert compatible=\drefrel at tmpunit,
+    @calc pgf/.expanded={((\noexpand\drefresult)-(\drefrel at tmp))/(\drefrel at tmp)},
+    @calc/.append code={\def\drefunit{}},
+  },
+  increase percent from/.style={increase factor from={#1}, percent},
+  decrease factor from/.style={increase factor from={#1}, negate},
+  decrease percent from/.style={increase factor from={#1}, negate, percent},
+  increase from/.style={
+    @get key or value to={#1}{\drefrel at tmp}{\drefrel at tmpunit},%
+    unit/@assert compatible=\drefrel at tmpunit,
+    @calc pgf/.expanded={((\noexpand\drefresult)-(\drefrel at tmp))},
+  },
+  decrease from/.style={increase from={#1}, negate},
+  abs/.style={
+    @calc pgf={abs(\drefresult)}
+  },
+  negate/.style={
+    @calc pgf={-1 * (\drefresult)}
+  },
 }
-\pgfkeys{%
-  /dref/.cd,%
-  value/.initial = /.DUMMY,%
-  base/.initial  = /.DUMMY,%
-  divide/.initial = 1,%
-  value plain/.is if=@dref at valuemustderef,%
-  value plain/.default=false,%
-  value plain=true,%
-  base plain/.is if=@dref at basemustderef,%
-  base plain/.default=false,%
-  base plain=true,%
-  factor/.is if=@dref at factor,%
-  factor/.default=true,%
-  factor=false,%
-  delta/.is if=@dref at delta,%
-  delta/.default=true,%
-  delta=false,%
-  scale/.is if=@dref at product,%
-  scale/.default=true,%
-  scale=false,%
-  product/.is if=@dref at product,%
-  product/.default=true,%
-  product=false,%
-  increase/.is if=@dref at increase,%
-  increase/.default=true,%
-  increase=false,%
-  overhead/.is if=@dref at increase,%
-  overhead/.default=true,%
-  overhead=false,%
-  percent/.is if=@dref at percent,%
-  percent/.default=true,%
-  percent=false,%
-  abs/.is if=@dref at abs,%
-  abs/.default=true,%
-  abs=false,%
-  negate/.is if=@dref at neg,%
-  negate/.default=true,%
-  negate=false,%
+
+\def\drefrel{\@ifstar\drefrel at starred\drefrel at unstarred}
+
+\newcommand{\drefrel at unstarred}[2][]{%
+  \drefkeys{@[,
+      @init,
+      path={#2}, print=default, #1,
+      @get key or value, @calc, @print, @set,
+    @],
+    @annotate={\textbackslash drefrel[#1]\{#2\}}}%
 }
 
-\def\drefrel{\@ifstar\@@drefrel\@drefrel}
+\newcommand{\drefrel at starred}[2][]{%
+  \drefkeys{
+    @[, @init,
+      path={#2}, #1,
+      @get key or value, @calc, @set,
+    @],
+    @annotate={\textbackslash drefrel[#1]\{#2\}},
+  }%
+}
 
-\newcommand{\@drefrel}[2][]{%
-  \@@drefrel[#1]{#2}%
-  \@@drefrel at result%
-  \dref at mkannotate{\textbackslash{}drefrel[#1]\{#2\}}%
+% Unit scaling
+
+\def\dref at unit@key#1#2{%
+  dref at unit@\expandafter\detokenize\expandafter{#1}@\expandafter\detokenize\expandafter{#2}}
+
+\def\dref at unit@new#1{%
+  \def\dref at unit@scala{}%
+  \def\dref at unit@new at outer##1/##2,##3\@nnil{%
+    \def\dref at outer{\dref at unit@new at outer##3\@nnil}%
+    \listadd{\dref at unit@scala}{##2}%
+    \ifx##3&&%
+       \def\dref at outer{}%
+    \fi%
+    \dref at outer%
+  }%
+  \dref at unit@new at outer#1,\@nnil%
+  \def\dref at unit@new at outer##1/##2,##3\@nnil{%
+    \def\dref at outer{\dref at unit@new at outer##3\@nnil}%
+    \pgfkeys{/dref/units/\detokenize{##2} to \detokenize{##2}/.initial={* 1},%
+      /dref/units/scala \detokenize{##2}/.initial/.expand once={\dref at unit@scala}}%
+    \ifx##3&&%
+       \def\dref at outer{}%
+    \else%
+       \def\dref at unit@factor{}%
+       \dref at unit@new at inner{##2}##3\@stop%
+    \fi%
+    \dref at outer%
+  }
+  \def\dref at unit@new at inner##1##2/##3,##4\@stop{%
+    \def\dref at inner{\dref at unit@new at inner{##1}##4\@stop}%
+    \ifx##4&&\def\dref at inner{}\else\fi%
+    \edef\dref at unit@factor{\dref at unit@factor * ##2}%
+    \pgfkeys{/dref/units/\detokenize{##1} to \detokenize{##3}/.initial/.expanded={* (1 \dref at unit@factor)},%
+             /dref/units/\detokenize{##3} to \detokenize{##1}/.initial/.expanded={/ (1 \dref at unit@factor)},%
+    }%
+    \dref at inner%
+  }%
+  \dref at unit@new at outer#1,\@nnil%
 }
 
-\newcommand{\@@drefrel}[2][]{%
-  \begingroup%
-  \pgfkeys{/pgf/fpu}%
-  \pgfkeys{/dref/.cd,#1}%
-  \pgfkeys{/dref/value=#2}%
-  \if at dref@valuemustderef%
-    \drefref{\pgfkeysvalueof{/dref/value}}%
-    \edef\drefvalue{\drefvalueof{\pgfkeysvalueof{/dref/value}}}%
-  \else%
-    \def\drefvalue{\pgfkeysvalueof{/dref/value}}%
-  \fi%
-  \if at dref@basemustderef%
-    \drefref{\pgfkeysvalueof{/dref/base}}%
-    \def\drefbase{\drefvalueof{\pgfkeysvalueof{/dref/base}}}%
-  \else%
-    \def\drefbase{\pgfkeysvalueof{/dref/base}}%
-  \fi%
-  \xdef\drefresult{\drefvalue}%
-  \if at dref@increase%
-     \pgfmathparse{((\drefvalue) - (\drefbase)) / (\drefbase)}%
-     \def\drefresult{\pgfmathresult}%
-  \else%
-     \if at dref@factor%
-         \pgfmathparse{(\drefvalue) / (\drefbase)}%
-         \def\drefresult{\pgfmathresult}%
-     \else%
-         \if at dref@delta%
-             \pgfmathparse{(\drefvalue) - (\drefbase)}%
-             \def\drefresult{\pgfmathresult}%
-         \else%
-            \if at dref@product%
-               \pgfmathparse{(\drefvalue) * (\drefbase)}%
-               \def\drefresult{\pgfmathresult}%
-            \else
-               \def\drefresult{\drefvalue}%
-            \fi
+\drefkeys{
+  unit/new scala/.code={%
+     \dref at unit@new{#1}%
+  },
+  unit/.style={
+    unit/@load={#1},
+    unit/@format enable,
+    @get/.append style={unit/@load={#1}}, % Override Unit from loads
+  },
+  unit/@load/.code={% #1 Is plain unit
+    \def\drefunit{#1}%
+  },
+  unit/@try override/.code={% #1 must be unit holding macro
+    \ifx#1\empty#1\else%
+       \expandafter\def\expandafter\drefunit\expandafter{#1}%
+    \fi%
+  },
+  unit/@format enable/.code={%
+    \ifx\drefunit\empty\drefunit\else%
+      \drefkeys{unit/format=default}%
+    \fi%
+  },
+  unit/@assert unitless/.code={%
+    \ifx\drefunit\empty\drefunit\else% We are unit less: good
+    \ifx#1\empty#1\else% Other has no unit, also good
+    \dref at error{At least one should be unitless:
+      \expandafter\detokenize\expandafter{\drefunit},
+      \expandafter\detokenize\expandafter{#1}}
+      % There is some unit here. That is BAD
+    \fi\fi%
+  },
+  unit/@assert compatible/.code={%
+    \ifx\drefunit\empty\drefunit\else% We are unit less: good
+    \ifx#1\empty#1\else% Other has no unit, also good
+      \ifx\drefunit#1\else% Bot equal: also good
+         \dref at error{Incompatible Units:
+           \expandafter\detokenize\expandafter{\drefunit}
+           != \expandafter\detokenize\expandafter{#1}}
          \fi%
-     \fi%
-  \fi%
-  % Percent
-  \if at dref@percent%
-      \pgfmathparse{(\drefresult)*100.0}%
-      \def\drefresult{\pgfmathresult}%
-  \fi%
-  % Absolute Value
-  \if at dref@abs%
-      \pgfmathparse{abs(\drefresult)}%
-      \def\drefresult{\pgfmathresult}%
-  \fi%
-  % Negative Value
-  \if at 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 at result}%
-  \xdef\drefresult{\drefresult}%
-  \xdef\@@drefrel at result{\@@drefrel at result}%
-  \endgroup%
+       \fi%
+    \fi%
+  },
+  unit/@combine/.style={
+    unit/@assert compatible={#1}, unit/@try override={#1}, unit/@format enable
+  },
+  unit/scale to/.code={%
+    \edef\dref at unit@key{/dref/units/\expandafter\detokenize\expandafter{\drefunit} to \detokenize{#1}}%
+    \drefkeys{%
+      \dref at unit@key/.get=\dref at unit@factor,%
+      @calc pgf/.expanded={((\noexpand\drefresult) \dref at unit@factor)},%
+      unit=#1%
+    }%
+  },
+  unit/scale to auto/.default=50,
+  unit/scale to auto/.style={% #1 is the optimal value
+    @calc/.append code={
+      \dref at ifunit{%Only do the scaling, if there is a unit
+      \edef\dref at unit@key{/dref/units/scala \expandafter\detokenize\expandafter{\drefunit}}%
+      % Get all other units in the same scala
+      \drefkeys{\dref at unit@key/.get=\dref at unit@scala}%
+      \expandafter\def\expandafter\drefunit at best\expandafter{\drefunit}%
+      \def\drefunit at bestvalue{\drefresult}%
+      \def\@@score####1{1 / ( abs(#1) - abs(####1))}%
+      \def\do####1{%
+        \edef\dref at unit@key{/dref/units/\expandafter\detokenize\expandafter{\drefunit} to \detokenize{####1}}%
+        \pgfkeys{\dref at unit@key/.get=\dref at unit@factor}%
+        \pgfmathparse{\@@score{\drefunit at bestvalue} < \@@score{\drefresult \dref at unit@factor}}%
+        %\typeout{\drefunit \pgfmathresult \detokenize{####1}}%
+        \ifdim\pgfmathresult pt=1.0 pt%
+          \pgfmathparse{(\drefresult) \dref at unit@factor}%
+          \edef\drefunit at bestvalue{\pgfmathresult}%
+          \def\drefunit at best{####1}%
+           %\typeout{\expandafter\detokenize\expandafter{\drefunit} to
+           %  \detokenize{####1} : \drefunit at bestvalue}%
+        \fi%
+      }%
+      \dolistloop\dref at unit@scala%
+      \edef\drefresult{\drefunit at bestvalue}%
+      \edef\drefunit{\expandonce{\drefunit at best}}%
+      }{}% ! \drefunit=\empty
+    }
+  },
+  unit/format default/.initial={plain},
+  unit/format/.is choice,
+  unit/format/no/.style={unit/format default=no, @print unit/.code={}},
+  unit/format/false/.style={unit/format default=no, @print unit/.code={}},
+  unit/format/plain/.style={
+    unit/format default=plain,
+    @print unit/.code={\dref at ifunit{\,\drefunit}{}}
+  },
+  unit/format/typeout/.style={
+    unit/format default=typeout,
+    @print unit/.code={\dref at ifunit{\expandafter\typeout\expandafter{\drefunit}}{}}
+ },
+  unit/format/siunitx/.style={
+    unit/format default=siunitx,
+    @print unit/.code={\dref at ifunit{\,\expandafter\si\expandafter{\drefunit}}{}}
+  },
+  unit/format/default/.style={%
+    unit/format default/.get=\dref at unit@format,
+    unit/format/.expand once=\dref at unit@format
+  },
 }
 
+\def\dref at ifunit#1#2{%
+  \expandafter\ifblank\expandafter{\drefunit}{#2}{#1}%
+}
+
+
 \endinput
 %%
 %% End of file `dataref.sty'.

Modified: trunk/Master/tlpkg/libexec/ctan2tds
===================================================================
--- trunk/Master/tlpkg/libexec/ctan2tds	2017-01-06 22:24:20 UTC (rev 42882)
+++ trunk/Master/tlpkg/libexec/ctan2tds	2017-01-06 22:25:07 UTC (rev 42883)
@@ -334,6 +334,7 @@
  'cwpuzzle',    "die 'skipping, in crossword package'",
  'cyklop',      "&MAKEcopy",
  'dantelogo',   "&MAKEflatten",
+ 'dataref',     "&MAKEflatten",
  'datatooltk',  "die 'skipping, Java installation'",
  'datepicker-pro',	"die 'skipping, per author (dpstory) request'",
  'datetime2-contrib',	"die 'skipping, use its subdirectories'",



More information about the tex-live-commits mailing list