diff options
-rw-r--r-- | Master/texmf-dist/doc/latex/dataref/dataref.pdf | bin | 235912 -> 245285 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/dataref/dataref.dtx | 313 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/dataref/dataref.sty | 280 |
3 files changed, 358 insertions, 235 deletions
diff --git a/Master/texmf-dist/doc/latex/dataref/dataref.pdf b/Master/texmf-dist/doc/latex/dataref/dataref.pdf Binary files differindex 4aa3b957609..e7a0e3eb206 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 0f44412b029..8c645166e02 100644 --- a/Master/texmf-dist/source/latex/dataref/dataref.dtx +++ b/Master/texmf-dist/source/latex/dataref/dataref.dtx @@ -28,11 +28,11 @@ %</driver> %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{dataref} -%<package> [2014/08/20 v0.2 dataref] +%<package> [2014/10/09 v0.3 dataref] % %<*driver> \documentclass{ltxdoc} -\usepackage[usagereport]{dataref}[2014/08/20] +\usepackage[usagereport]{dataref}[2014/10/09] \EnableCrossrefs \CodelineIndex \RecordChanges @@ -93,7 +93,7 @@ % \providecommand*{\url}{\texttt} % \GetFileInfo{dataref.sty} % \title{The \textsf{dataref} package} -% \author{Christian Dietrich 2013 \url{stettberger@dokucode.de}\\ +% \author{Christian Dietrich 2013-2014\\ \url{stettberger@dokucode.de}\\ % \url{https://github.com/stettberger/dataref}} % \date{\filedate~\fileversion} % @@ -193,6 +193,8 @@ % \end{quote} % % \DescribeMacro{\drefcalc[\meta{format}]\{\meta{expr}\}} +% \DescribeMacro{data("\meta{key}")} +% \DescribeMacro{d(\meta{key})} % % 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 @@ -205,15 +207,13 @@ % \noindent It adds support for the \texttt{data} function within pgfmath, which % references symbolic data points. The keyname has to be in double % quotes to indicate a string, but you can easily define an appropriate -% macro that abstracts from \verb|data("")|. +% macro that abstracts from \verb|data("")|. As a quote-free +% alternative to the data command, \cmd{\drefcalc} provides also \verb|d(<key>|). % % % \begin{quote} -% \begin{verbatim}\drefcalc{data("/control group/recovered") / -% data("/control group/mice count")}\end{verbatim} -% $\Rightarrow$ \drefcalc{data("/control group/recovered") / data("/control group/mice count")}\\ -% \verb|\newcommand{\cg}[1]{data("/control group/#1")}|\newcommand{\cg}[1]{data("/control group/#1")}\\ -% \verb|\drefcalc{\cg{recovered}/\cg{mice count}}| $\Rightarrow$ \drefcalc{\cg{recovered}/\cg{mice count}} +% \verb|\drefcalc{data("/med A/mice count") * 100}| $\Rightarrow$ \drefcalc{data("/med A/mice count") * 100} +% \verb|\drefcalc{d(/med A/mice count) * 100}| $\Rightarrow$ \drefcalc{d(/med A/mice count) * 100} % \end{quote} % % \noindent The optional argument lets you give a number format, which is used for printing the @@ -223,7 +223,7 @@ % \verb|\drefcalc[precision=5,fixed]{1/3}| $\Rightarrow$ \drefcalc[fixed,precision=5]{1/3} % \end{quote} % -% \cmd{\drefcalc} works as well in a \cmd{/pgf/fpu} environment or a normal one. The FPU feature of +% \cmd{\drefcalc} works as well in a \textbf{/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. % @@ -311,9 +311,9 @@ % \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 +% \textbf{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 +% \textbf{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$ @@ -353,6 +353,16 @@ % \verb|\drefrel[delta,base=50,base plain,value plain]{45}| $\Rightarrow$ % \drefrel[delta,base=50,base plain,value plain]{45} % +% \DescribeMacro{/dref/scale} +% \DescribeMacro{/dref/product} +% +% Is a base-relation type. It calculates the product of value and base. +% +% \[\cmd{\drefresult} = \texttt{value} \cdot \texttt{base}\] +% +% \verb|\drefrel[scale,base=50,base plain,value plain]{45}| $\Rightarrow$ +% \drefrel[scale,base=100,base plain,value plain]{0.45} +% % % \DescribeMacro{/dref/percent} % % Is a post-processing type. It calculates the percent value from a fraction. @@ -390,6 +400,7 @@ % $\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 @@ -587,8 +598,8 @@ % \begin{macro}{\dref@expandable} % \begin{macrocode} \def\dref@expandable#1{% - \pgfkeysifdefined{\dref@datapath#1}{% - \pgfkeysvalueof{\dref@datapath#1}% + \pgfkeysifdefined{\dref@datapath\csuse{dref@prefix}#1}{% + \pgfkeysvalueof{\dref@datapath\csuse{dref@prefix}#1}% }{% \ifdref@ignoremissing% \dref@defaultvalue% @@ -604,11 +615,12 @@ % \begin{macro}{\dref@unexpandable} % \begin{macrocode} \def\dref@unexpandable#1{% - \def\drefcurrentkey{\dref@datapath#1}% + \def\drefcurrentkey{\dref@datapath\csuse{dref@prefix}#1}% \pgfkeysifdefined{\drefcurrentkey}{% - \immediate\write\@auxout{\noexpand\dref@found{\drefcurrentkey}{\thepage}}% + \edef\dref@thepage{\arabic{page}}% + \immediate\write\@auxout{\noexpand\dref@found{\drefcurrentkey}{\dref@thepage}}% }{% - \immediate\write\@auxout{\noexpand\dref@notfound{\drefcurrentkey}{\thepage}}% + \immediate\write\@auxout{\noexpand\dref@notfound{\drefcurrentkey}{\dref@thepage}}% \ifdref@ignoremissing% \typeout{Dref warning: undefined key `\drefcurrentkey'}% \dref@mkannotate{UNDEFINED: \drefcurrentkey}% @@ -616,7 +628,7 @@ \dref@error{Dref error: undefined key `\drefcurrentkey'}% \fi% }% - \immediate\write\@auxout{\noexpand\dref@referenced{\drefcurrentkey}{\thepage}}% + \immediate\write\@auxout{\noexpand\dref@referenced{\drefcurrentkey}{\dref@thepage}}% } % \end{macrocode} % \end{macro} @@ -624,7 +636,7 @@ % \begin{macro}{\drefifdefined} % \begin{macrocode} \newcommand{\drefifdefined}[3]{ - \def\drefcurrentkey{\dref@datapath#1}% + \def\drefcurrentkey{\dref@datapath\csuse{dref@prefix}#1}% \pgfkeysifdefined{\drefcurrentkey}{#2}{#3}% } % \end{macrocode} @@ -636,18 +648,18 @@ % \begin{macrocode} \def\dref{\@ifstar\@@dref\@dref} \newcommand{\@dref}[2][]{% Unstarred - \edef\dref@argument{#2} + \edef\dref@argument{#2}% \expandafter\dref@unexpandable\expandafter{\dref@argument}% \pgfmathparse{\dref@expandable{#2}}% \dref@format[#1]{\pgfmathresult}% - \dref@mkannotate{#2}% + \dref@mkannotate{\textbackslash dref\{#2\}}% } -\newcommand{\@@dref}[2][]{ % Starred - \edef\dref@argument{#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}% + \dref@mkannotate{\textbackslash dref*\{#2\}}% } % \end{macrocode} % \end{macro} @@ -759,72 +771,65 @@ % \begin{macro}{\drefcalc} % \begin{macrocode} - -\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@parser#1#2{% + \edef\@tempa{#1}% + \csdef{dref@parser@result}{}% + \csdef{dref@parser@state}{}% + \expandafter\dref@parser@parse\@tempa\@nnil% + \xdef#2{\csuse{dref@parser@result}}% } -\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@parser@parse#1#2\@nnil{% + %\typeout{#1 State: \csuse{dref@parser@state}}% + \ifblank{#1#2}{% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}\csuse{dref@parser@state}}% + }{% + \ifcsdef{dref@parser@\csuse{dref@parser@state}@#1}{% + \csuse{dref@parser@\csuse{dref@parser@state}@#1}#2\@nnil% + }{% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}\csuse{dref@parser@state}#1}% + \csdef{dref@parser@state}{}% + \ifblank{#2}{}{% + \dref@parser@parse#2\@nnil% + }% + }% + }% } -\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 -} +\csdef{dref@parser@@d}{\csdef{dref@parser@state}{d}\dref@parser@parse} +\csdef{dref@parser@d@a}{\csdef{dref@parser@state}{da}\dref@parser@parse} +\csdef{dref@parser@da@t}{\csdef{dref@parser@state}{dat}\dref@parser@parse} +\csdef{dref@parser@dat@a}{\csdef{dref@parser@state}{data}\dref@parser@parse} +\csdef{dref@parser@data@(}{\csdef{dref@parser@state}{data(}\dref@parser@parse} +\csdef{dref@parser@data(@"}{\dref@parser@tillquote} +\csdef{dref@parser@d@(}{\dref@parser@tillparen} -\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@parser@tillquote#1")#2\@nnil{% + \drefref{\dref@data@math@prefix #1}% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}(\drefvalueof{\dref@data@math@prefix #1})}% + \csdef{dref@parser@state}{}% + \ifblank{#2}{}{\dref@parser@parse#2\@nnil}} -\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@parser@tillparen#1)#2\@nnil{% + \drefref{\dref@data@math@prefix #1}% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}(\drefvalueof{\dref@data@math@prefix #1})}% + \csdef{dref@parser@state}{}% + \ifblank{#2}{}{\dref@parser@parse#2\@nnil}}% -\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\dref@parser@end#1#2\@nnil{} +\csdef{dref@parser@@}{\typeout{end}\dref@parser@end} \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} + %\typeout{Before: '#1'}% + \dref@parser{#1}{\dref@calc@@argA}% + %\typeout{After: \dref@calc@@argA}% + \pgfmathparse{\dref@calc@@argA}% } + \pgfset{/dref/let/.code={\dref@let{#1}}} +\pgfset{/dref/prefix/.code={\csdef{dref@prefix}{#1}}} +\def\drefprefix#1{\csdef{dref@prefix}{#1}} \def\drefresult{0} \def\drefcalc{\@ifstar\@@drefcalc\@drefcalc} \newcommand{\@drefcalc}[2][]{% Unstarred @@ -834,7 +839,7 @@ \pgfmathprintnumberto[fixed,assume math mode=true,precision=10,1000 sep={}]{\pgfmathresult}{\drefresult} \xdef\drefresult{\drefresult}% \dref@format{\pgfmathresult}% - \dref@mkannotate{#2}% + \dref@mkannotate{\textbackslash drefcalc\{#2\}}% \endgroup% } \newcommand{\@@drefcalc}[2][]{ % Starred @@ -891,29 +896,45 @@ % \begin{macrocode} \newtoks\dref@toks +\newcount\drefcellcount \newcommand{\dref@makerow}[2]{% {\global\dref@toks={}% - \@tempcnta=\z@% - \def\inner##1##2{#2}% - \renewcommand*{\do}[1]{% - \advance\@tempcnta\@ne% - \csdef{@cell\number\@tempcnta}{\inner{##1}{\number\@tempcntb}}% + \drefcellcount=\z@% + \def\do##1{% + \advance\drefcellcount\@ne% + \def\@tempa{\doX{##1}}% + \expandafter\@tempa\expandafter{\the\drefcellcount}% + }% + \def\doX##1##2{% + \csxdef{@cell\the\drefcellcount}{\detokenize{% + #2% + }}% }% \expandafter\def\expandafter\arglist\expandafter{#1}% \expandafter\docsvlist\expandafter{\arglist}% - \@tempcntb=\z@ - {\loop\ifnum\@tempcntb<\@tempcnta - \advance\@tempcntb\@ne - \edef\next{% - \ifnum\@tempcntb=\@ne\else&\fi - \csuse{@cell\number\@tempcntb}}% - \global\dref@toks=\expandafter{\the\expandafter\dref@toks\next}% - \repeat}% + \@tempcntb=0\relax + {\loop\ifnum\@tempcntb<\drefcellcount + \advance\@tempcntb by 1\relax% + \ifnum \@tempcntb = 1% + \edef\@@next{\csuse{@cell\the\@tempcntb}}% + \else% + \edef\@@next{&\csuse{@cell\the\@tempcntb}}% + \fi% + \global% + \dref@toks% + \expandafter=% + \expandafter{% + \the% + \expandafter\dref@toks% + \@@next}% + \repeat}% }% - \the\dref@toks} + \typeout{LINE: \the\dref@toks}% + \expandafter\scantokens\expandafter{\the\dref@toks}} + \long\def\drefrow{\@ifstar\@@drefrow\@drefrow} -\def\@drefrow#1#2{\dref@makerow{#1}{\drefvalueof{#2}}} % Unstarred +\def\@drefrow#1#2{\dref@makerow{#1}{\dref{#2}}} % Unstarred \def\@@drefrow#1#2{\dref@makerow{#1}{#2}} % Starred % \end{macrocode} % \end{macro} @@ -925,15 +946,17 @@ \RequirePackage{pdfcomment} } +\def\dref@mkannotate@none#1{\relax} +\def\dref@mkannotate@footnote#1{\footnote{\texttt{#1}}} +\def\dref@mkannotate@pdfcomment#1{\pdfcomment[opacity=0.4,voffset=2ex]{#1}} + \newcommand{\dref@mkannotate}[1]{% - \expandafter\ifstrequal\expandafter{\dref@annotate}{none}% - {\relax}% - {\expandafter\ifstrequal\expandafter{\dref@annotate}{footnote}% - {\footnote{#1}}% - {\expandafter\ifstrequal\expandafter{\dref@annotate}{pdfcomment}% - {\pdfcomment[opacity=0.4,voffset=2ex]{#1}}% - {\dref@error{Value for annotate not supported: '\dref@annotate'}% - }}}}% + \ifcsdef{dref@mkannotate@\dref@annotate}{% + \csuse{dref@mkannotate@\dref@annotate}{#1}% + }{% + \dref@error{Value for annotate not supported: '\dref@annotate'}% + }% +} \newcommand{\drefannotate}[1]{% \renewcommand{\dref@annotate}{#1}% @@ -945,7 +968,7 @@ %% Usagereport % \begin{macrocode} \ifdref@usagereport - \RequirePackage{longtable} + \RequirePackage{xtab} \RequirePackage{booktabs} \fi % \end{macrocode} @@ -997,12 +1020,19 @@ % % \begin{macro}{\dref@usagereport@keyheader} % \begin{macrocode} +\newif\ifdref@usagereport@keyheader@first +\dref@usagereport@keyheader@firsttrue \newcommand{\dref@usagereport@keyheader}[1]{% + \ifdref@usagereport@keyheader@first% + \global\dref@usagereport@keyheader@firstfalse% + \else% + \\% + \fi% \textbf{\ifdef{\hypertarget}% {\hypertarget{#1}{\dref@usagereport@strippath{#1}}}% {\dref@usagereport@strippath{#1}}}% & \dref@usagereport@formatreferencelist{#1}% - & \pgfkeysifdefined{#1}{\pgfkeysvalueof{#1}}{\textbf{\color{red}undefined}} \\% + & \pgfkeysifdefined{#1}{\pgfkeysvalueof{#1}}{\textbf{\color{red}undefined}}% } % \end{macrocode} % \end{macro} @@ -1010,9 +1040,19 @@ % % \begin{macro}{\dref@usagereport@forhelp} % \begin{macrocode} +\newif\ifdref@withhelp +\errorcontextlines=23 +\newlength{\dreflinewidth}% \newcommand{\dref@usagereport@forhelp}[1]{% \begingroup% - \noindent\csuse{dref@help@#1} + \dref@withhelpfalse% + \renewcommand{\do}[1]{% + \dref@help@match{#1}{##1}{% + \dref@withhelptrue% + }{}% + }% + \dolistcsloop{dref@usagereport@keys}% + \dref@usagereport@keyheader@firsttrue% \renewcommand{\do}[1]{% \dref@help@match{#1}{##1}{% \dref@usagereport@keyheader{##1}% @@ -1021,13 +1061,17 @@ }% }{}% }% - \begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule% - & Page(s) & Value \\ \midrule - \endhead - \bottomrule% - \endfoot - \dolistcsloop{dref@usagereport@keys}% - \end{longtable}% + \ifdref@withhelp + \tablehead{\hline & Page & Value \\\hline}% + \setlength\tabcolsep{3pt}% + \dreflinewidth=\linewidth% + \advance\dreflinewidth by -6\tabcolsep% + \begin{xtabular}{|p{0.7\dreflinewidth}|p{0.15\dreflinewidth}|p{0.15\dreflinewidth}|}% + \dolistcsloop{dref@usagereport@keys}\\\hline + \multicolumn{3}{|p{\linewidth}|}{\csuse{dref@help@#1}}\\\hline + \end{xtabular}% + \fi% + \endgroup% } % \end{macrocode} @@ -1036,19 +1080,32 @@ % % \begin{macro}{\dref@usagereport@withouthelp} % \begin{macrocode} +\newif\ifdref@withouthelp \newcommand{\dref@usagereport@withouthelp}{% + \begingroup% + \dref@withouthelpfalse% + \renewcommand{\do}[1]{% + \ifinlistcs{##1}{dref@usagereport@matchedkeys}{}{% + \dref@withouthelptrue% + }% + }% + \dolistcsloop{dref@usagereport@keys}% + \dref@usagereport@keyheader@firsttrue% \renewcommand{\do}[1]{% \ifinlistcs{##1}{dref@usagereport@matchedkeys}{}{% \dref@usagereport@keyheader{##1}% }% }% - \begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule% - Keys without Help & Page(s) & Value \\\midrule - \endhead - \bottomrule - \endfoot - \dolistcsloop{dref@usagereport@keys}% - \end{longtable}% + \ifdref@withouthelp% + \tablehead{\hline Keys without Description & Page & Value \\\hline}% + \setlength\tabcolsep{3pt}% + \dreflinewidth=\linewidth% + \advance\dreflinewidth by -6\tabcolsep% + \begin{xtabular}{|p{0.7\dreflinewidth}|p{0.15\dreflinewidth}|p{0.15\dreflinewidth}|}% + \dolistcsloop{dref@usagereport@keys}\\\hline + \end{xtabular}% + \fi% + \endgroup% } % \end{macrocode} % \end{macro} @@ -1060,15 +1117,12 @@ \ifdref@usagereport% \ifcsvoid{dref@usagereport@keys}{\typeout{EMPTY}}{% \begingroup% - \setlength{\LTleft}{2em}% - \setlength{\LTright}{0pt}% \renewcommand{\do}[1]{% \ifinlistcs{##1}{dref@usagereport@matchedkeys}{}{% \dref@usagereport@forhelp{##1}% }% }% \dolistcsloop{dref@helps} % For all help text - \setlength{\LTleft}{0em}% \dref@usagereport@withouthelp\relax \endgroup% }% csempty @keys @@ -1103,6 +1157,7 @@ \newif\if@dref@valuemustderef% \newif\if@dref@basemustderef% \newif\if@dref@increase% +\newif\if@dref@product% \newif\if@dref@factor% \newif\if@dref@delta% \newif\if@dref@percent% @@ -1128,6 +1183,12 @@ delta/.is if=@dref@delta,% delta/.default=true,% delta=false,% + scale/.is if=@dref@product,% + scale/.default=true,% + scale=false,% + product/.is if=@dref@product,% + product/.default=true,% + product=false,% increase/.is if=@dref@increase,% increase/.default=true,% increase=false,% @@ -1150,6 +1211,7 @@ \newcommand{\@drefrel}[2][]{% \@@drefrel[#1]{#2}% \@@drefrel@result% + \dref@mkannotate{\textbackslash{}drefrel[#1]\{#2\}}% } \newcommand{\@@drefrel}[2][]{% @@ -1182,7 +1244,12 @@ \pgfmathparse{(\drefvalue) - (\drefbase)}% \def\drefresult{\pgfmathresult}% \else% - \def\drefresult{\drefvalue}% + \if@dref@product% + \pgfmathparse{(\drefvalue) * (\drefbase)}% + \def\drefresult{\pgfmathresult}% + \else + \def\drefresult{\drefvalue}% + \fi \fi% \fi% \fi% diff --git a/Master/texmf-dist/tex/latex/dataref/dataref.sty b/Master/texmf-dist/tex/latex/dataref/dataref.sty index 1b9e1d2c32d..a08d450e1be 100644 --- a/Master/texmf-dist/tex/latex/dataref/dataref.sty +++ b/Master/texmf-dist/tex/latex/dataref/dataref.sty @@ -25,7 +25,7 @@ \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{dataref} - [2014/08/20 v0.2 dataref] + [2014/10/09 v0.3 dataref] \ifx\drefloaded\undefined \let\drefloaded=\relax @@ -70,8 +70,8 @@ \def\drefset#1#2{\dref@set{#1}{#2}} \def\dref@expandable#1{% - \pgfkeysifdefined{\dref@datapath#1}{% - \pgfkeysvalueof{\dref@datapath#1}% + \pgfkeysifdefined{\dref@datapath\csuse{dref@prefix}#1}{% + \pgfkeysvalueof{\dref@datapath\csuse{dref@prefix}#1}% }{% \ifdref@ignoremissing% \dref@defaultvalue% @@ -81,11 +81,12 @@ }% } \def\dref@unexpandable#1{% - \def\drefcurrentkey{\dref@datapath#1}% + \def\drefcurrentkey{\dref@datapath\csuse{dref@prefix}#1}% \pgfkeysifdefined{\drefcurrentkey}{% - \immediate\write\@auxout{\noexpand\dref@found{\drefcurrentkey}{\thepage}}% + \edef\dref@thepage{\arabic{page}}% + \immediate\write\@auxout{\noexpand\dref@found{\drefcurrentkey}{\dref@thepage}}% }{% - \immediate\write\@auxout{\noexpand\dref@notfound{\drefcurrentkey}{\thepage}}% + \immediate\write\@auxout{\noexpand\dref@notfound{\drefcurrentkey}{\dref@thepage}}% \ifdref@ignoremissing% \typeout{Dref warning: undefined key `\drefcurrentkey'}% \dref@mkannotate{UNDEFINED: \drefcurrentkey}% @@ -93,26 +94,26 @@ \dref@error{Dref error: undefined key `\drefcurrentkey'}% \fi% }% - \immediate\write\@auxout{\noexpand\dref@referenced{\drefcurrentkey}{\thepage}}% + \immediate\write\@auxout{\noexpand\dref@referenced{\drefcurrentkey}{\dref@thepage}}% } \newcommand{\drefifdefined}[3]{ - \def\drefcurrentkey{\dref@datapath#1}% + \def\drefcurrentkey{\dref@datapath\csuse{dref@prefix}#1}% \pgfkeysifdefined{\drefcurrentkey}{#2}{#3}% } \def\dref{\@ifstar\@@dref\@dref} \newcommand{\@dref}[2][]{% Unstarred - \edef\dref@argument{#2} + \edef\dref@argument{#2}% \expandafter\dref@unexpandable\expandafter{\dref@argument}% \pgfmathparse{\dref@expandable{#2}}% \dref@format[#1]{\pgfmathresult}% - \dref@mkannotate{#2}% + \dref@mkannotate{\textbackslash dref\{#2\}}% } -\newcommand{\@@dref}[2][]{ % Starred - \edef\dref@argument{#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}% + \dref@mkannotate{\textbackslash dref*\{#2\}}% } \def\drefvalueof#1{% \dref@expandable{#1}% @@ -170,71 +171,64 @@ \dref@let{#1}% } -\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@parser#1#2{% + \edef\@tempa{#1}% + \csdef{dref@parser@result}{}% + \csdef{dref@parser@state}{}% + \expandafter\dref@parser@parse\@tempa\@nnil% + \xdef#2{\csuse{dref@parser@result}}% } -\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@parser@parse#1#2\@nnil{% + %\typeout{#1 State: \csuse{dref@parser@state}}% + \ifblank{#1#2}{% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}\csuse{dref@parser@state}}% + }{% + \ifcsdef{dref@parser@\csuse{dref@parser@state}@#1}{% + \csuse{dref@parser@\csuse{dref@parser@state}@#1}#2\@nnil% + }{% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}\csuse{dref@parser@state}#1}% + \csdef{dref@parser@state}{}% + \ifblank{#2}{}{% + \dref@parser@parse#2\@nnil% + }% + }% + }% } -\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 -} +\csdef{dref@parser@@d}{\csdef{dref@parser@state}{d}\dref@parser@parse} +\csdef{dref@parser@d@a}{\csdef{dref@parser@state}{da}\dref@parser@parse} +\csdef{dref@parser@da@t}{\csdef{dref@parser@state}{dat}\dref@parser@parse} +\csdef{dref@parser@dat@a}{\csdef{dref@parser@state}{data}\dref@parser@parse} +\csdef{dref@parser@data@(}{\csdef{dref@parser@state}{data(}\dref@parser@parse} +\csdef{dref@parser@data(@"}{\dref@parser@tillquote} +\csdef{dref@parser@d@(}{\dref@parser@tillparen} -\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@parser@tillquote#1")#2\@nnil{% + \drefref{\dref@data@math@prefix #1}% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}(\drefvalueof{\dref@data@math@prefix #1})}% + \csdef{dref@parser@state}{}% + \ifblank{#2}{}{\dref@parser@parse#2\@nnil}} -\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@parser@tillparen#1)#2\@nnil{% + \drefref{\dref@data@math@prefix #1}% + \csxdef{dref@parser@result}{\csuse{dref@parser@result}(\drefvalueof{\dref@data@math@prefix #1})}% + \csdef{dref@parser@state}{}% + \ifblank{#2}{}{\dref@parser@parse#2\@nnil}}% -\def\dref@calc@parser@E#1")#2\@nnil{% - (\drefvalueof{\dref@data@math@prefix#1})\ifx&\else\dref@calc@parser@d #2\@nnil\fi% -} +\def\dref@parser@end#1#2\@nnil{} +\csdef{dref@parser@@}{\typeout{end}\dref@parser@end} \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} + %\typeout{Before: '#1'}% + \dref@parser{#1}{\dref@calc@@argA}% + %\typeout{After: \dref@calc@@argA}% + \pgfmathparse{\dref@calc@@argA}% } + \pgfset{/dref/let/.code={\dref@let{#1}}} +\pgfset{/dref/prefix/.code={\csdef{dref@prefix}{#1}}} +\def\drefprefix#1{\csdef{dref@prefix}{#1}} \def\drefresult{0} \def\drefcalc{\@ifstar\@@drefcalc\@drefcalc} \newcommand{\@drefcalc}[2][]{% Unstarred @@ -244,7 +238,7 @@ \pgfmathprintnumberto[fixed,assume math mode=true,precision=10,1000 sep={}]{\pgfmathresult}{\drefresult} \xdef\drefresult{\drefresult}% \dref@format{\pgfmathresult}% - \dref@mkannotate{#2}% + \dref@mkannotate{\textbackslash drefcalc\{#2\}}% \endgroup% } \newcommand{\@@drefcalc}[2][]{ % Starred @@ -286,44 +280,62 @@ \newtoks\dref@toks +\newcount\drefcellcount \newcommand{\dref@makerow}[2]{% {\global\dref@toks={}% - \@tempcnta=\z@% - \def\inner##1##2{#2}% - \renewcommand*{\do}[1]{% - \advance\@tempcnta\@ne% - \csdef{@cell\number\@tempcnta}{\inner{##1}{\number\@tempcntb}}% + \drefcellcount=\z@% + \def\do##1{% + \advance\drefcellcount\@ne% + \def\@tempa{\doX{##1}}% + \expandafter\@tempa\expandafter{\the\drefcellcount}% + }% + \def\doX##1##2{% + \csxdef{@cell\the\drefcellcount}{\detokenize{% + #2% + }}% }% \expandafter\def\expandafter\arglist\expandafter{#1}% \expandafter\docsvlist\expandafter{\arglist}% - \@tempcntb=\z@ - {\loop\ifnum\@tempcntb<\@tempcnta - \advance\@tempcntb\@ne - \edef\next{% - \ifnum\@tempcntb=\@ne\else&\fi - \csuse{@cell\number\@tempcntb}}% - \global\dref@toks=\expandafter{\the\expandafter\dref@toks\next}% - \repeat}% + \@tempcntb=0\relax + {\loop\ifnum\@tempcntb<\drefcellcount + \advance\@tempcntb by 1\relax% + \ifnum \@tempcntb = 1% + \edef\@@next{\csuse{@cell\the\@tempcntb}}% + \else% + \edef\@@next{&\csuse{@cell\the\@tempcntb}}% + \fi% + \global% + \dref@toks% + \expandafter=% + \expandafter{% + \the% + \expandafter\dref@toks% + \@@next}% + \repeat}% }% - \the\dref@toks} + \typeout{LINE: \the\dref@toks}% + \expandafter\scantokens\expandafter{\the\dref@toks}} + \long\def\drefrow{\@ifstar\@@drefrow\@drefrow} -\def\@drefrow#1#2{\dref@makerow{#1}{\drefvalueof{#2}}} % Unstarred +\def\@drefrow#1#2{\dref@makerow{#1}{\dref{#2}}} % Unstarred \def\@@drefrow#1#2{\dref@makerow{#1}{#2}} % Starred \expandafter\ifstrequal\expandafter{\dref@annotate}{pdfcomment}{ \RequirePackage{pdfcomment} } +\def\dref@mkannotate@none#1{\relax} +\def\dref@mkannotate@footnote#1{\footnote{\texttt{#1}}} +\def\dref@mkannotate@pdfcomment#1{\pdfcomment[opacity=0.4,voffset=2ex]{#1}} + \newcommand{\dref@mkannotate}[1]{% - \expandafter\ifstrequal\expandafter{\dref@annotate}{none}% - {\relax}% - {\expandafter\ifstrequal\expandafter{\dref@annotate}{footnote}% - {\footnote{#1}}% - {\expandafter\ifstrequal\expandafter{\dref@annotate}{pdfcomment}% - {\pdfcomment[opacity=0.4,voffset=2ex]{#1}}% - {\dref@error{Value for annotate not supported: '\dref@annotate'}% - }}}}% + \ifcsdef{dref@mkannotate@\dref@annotate}{% + \csuse{dref@mkannotate@\dref@annotate}{#1}% + }{% + \dref@error{Value for annotate not supported: '\dref@annotate'}% + }% +} \newcommand{\drefannotate}[1]{% \renewcommand{\dref@annotate}{#1}% @@ -331,7 +343,7 @@ %% Usagereport \ifdref@usagereport - \RequirePackage{longtable} + \RequirePackage{xtab} \RequirePackage{booktabs} \fi \newcommand{\dref@usagereport@notfound}[2]{} @@ -362,16 +374,33 @@ \dolistcsloop{dref@usagereport@referenced@#1}% \endgroup% } +\newif\ifdref@usagereport@keyheader@first +\dref@usagereport@keyheader@firsttrue \newcommand{\dref@usagereport@keyheader}[1]{% + \ifdref@usagereport@keyheader@first% + \global\dref@usagereport@keyheader@firstfalse% + \else% + \\% + \fi% \textbf{\ifdef{\hypertarget}% {\hypertarget{#1}{\dref@usagereport@strippath{#1}}}% {\dref@usagereport@strippath{#1}}}% & \dref@usagereport@formatreferencelist{#1}% - & \pgfkeysifdefined{#1}{\pgfkeysvalueof{#1}}{\textbf{\color{red}undefined}} \\% + & \pgfkeysifdefined{#1}{\pgfkeysvalueof{#1}}{\textbf{\color{red}undefined}}% } +\newif\ifdref@withhelp +\errorcontextlines=23 +\newlength{\dreflinewidth}% \newcommand{\dref@usagereport@forhelp}[1]{% \begingroup% - \noindent\csuse{dref@help@#1} + \dref@withhelpfalse% + \renewcommand{\do}[1]{% + \dref@help@match{#1}{##1}{% + \dref@withhelptrue% + }{}% + }% + \dolistcsloop{dref@usagereport@keys}% + \dref@usagereport@keyheader@firsttrue% \renewcommand{\do}[1]{% \dref@help@match{#1}{##1}{% \dref@usagereport@keyheader{##1}% @@ -380,42 +409,56 @@ }% }{}% }% - \begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule% - & Page(s) & Value \\ \midrule - \endhead - \bottomrule% - \endfoot - \dolistcsloop{dref@usagereport@keys}% - \end{longtable}% + \ifdref@withhelp + \tablehead{\hline & Page & Value \\\hline}% + \setlength\tabcolsep{3pt}% + \dreflinewidth=\linewidth% + \advance\dreflinewidth by -6\tabcolsep% + \begin{xtabular}{|p{0.7\dreflinewidth}|p{0.15\dreflinewidth}|p{0.15\dreflinewidth}|}% + \dolistcsloop{dref@usagereport@keys}\\\hline + \multicolumn{3}{|p{\linewidth}|}{\csuse{dref@help@#1}}\\\hline + \end{xtabular}% + \fi% + \endgroup% } +\newif\ifdref@withouthelp \newcommand{\dref@usagereport@withouthelp}{% + \begingroup% + \dref@withouthelpfalse% + \renewcommand{\do}[1]{% + \ifinlistcs{##1}{dref@usagereport@matchedkeys}{}{% + \dref@withouthelptrue% + }% + }% + \dolistcsloop{dref@usagereport@keys}% + \dref@usagereport@keyheader@firsttrue% \renewcommand{\do}[1]{% \ifinlistcs{##1}{dref@usagereport@matchedkeys}{}{% \dref@usagereport@keyheader{##1}% }% }% - \begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule% - Keys without Help & Page(s) & Value \\\midrule - \endhead - \bottomrule - \endfoot - \dolistcsloop{dref@usagereport@keys}% - \end{longtable}% + \ifdref@withouthelp% + \tablehead{\hline Keys without Description & Page & Value \\\hline}% + \setlength\tabcolsep{3pt}% + \dreflinewidth=\linewidth% + \advance\dreflinewidth by -6\tabcolsep% + \begin{xtabular}{|p{0.7\dreflinewidth}|p{0.15\dreflinewidth}|p{0.15\dreflinewidth}|}% + \dolistcsloop{dref@usagereport@keys}\\\hline + \end{xtabular}% + \fi% + \endgroup% } \newcommand{\drefusagereport}{% \ifdref@usagereport% \ifcsvoid{dref@usagereport@keys}{\typeout{EMPTY}}{% \begingroup% - \setlength{\LTleft}{2em}% - \setlength{\LTright}{0pt}% \renewcommand{\do}[1]{% \ifinlistcs{##1}{dref@usagereport@matchedkeys}{}{% \dref@usagereport@forhelp{##1}% }% }% \dolistcsloop{dref@helps} % For all help text - \setlength{\LTleft}{0em}% \dref@usagereport@withouthelp\relax \endgroup% }% csempty @keys @@ -438,6 +481,7 @@ \newif\if@dref@valuemustderef% \newif\if@dref@basemustderef% \newif\if@dref@increase% +\newif\if@dref@product% \newif\if@dref@factor% \newif\if@dref@delta% \newif\if@dref@percent% @@ -463,6 +507,12 @@ delta/.is if=@dref@delta,% delta/.default=true,% delta=false,% + scale/.is if=@dref@product,% + scale/.default=true,% + scale=false,% + product/.is if=@dref@product,% + product/.default=true,% + product=false,% increase/.is if=@dref@increase,% increase/.default=true,% increase=false,% @@ -485,6 +535,7 @@ \newcommand{\@drefrel}[2][]{% \@@drefrel[#1]{#2}% \@@drefrel@result% + \dref@mkannotate{\textbackslash{}drefrel[#1]\{#2\}}% } \newcommand{\@@drefrel}[2][]{% @@ -517,7 +568,12 @@ \pgfmathparse{(\drefvalue) - (\drefbase)}% \def\drefresult{\pgfmathresult}% \else% - \def\drefresult{\drefvalue}% + \if@dref@product% + \pgfmathparse{(\drefvalue) * (\drefbase)}% + \def\drefresult{\pgfmathresult}% + \else + \def\drefresult{\drefvalue}% + \fi \fi% \fi% \fi% |