summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/datatool/datatool.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/datatool/datatool.sty')
-rw-r--r--Master/texmf-dist/tex/latex/datatool/datatool.sty232
1 files changed, 190 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/latex/datatool/datatool.sty b/Master/texmf-dist/tex/latex/datatool/datatool.sty
index b8d1237baf7..5101274b157 100644
--- a/Master/texmf-dist/tex/latex/datatool/datatool.sty
+++ b/Master/texmf-dist/tex/latex/datatool/datatool.sty
@@ -7,7 +7,7 @@
%% datatool.dtx (with options: `datatool.sty,package')
%%
%% datatool.dtx
-%% Copyright 2012 Nicola Talbot
+%% Copyright 2013 Nicola Talbot
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
@@ -21,7 +21,7 @@
%%
%% The Current Maintainer of this work is Nicola Talbot.
%%
-%% This work consists of the files datatool.dtx and datatool.ins and the derived files datatool-base.sty, datatool-fp.sty, datatool-pgfmath.sty, datatool.sty, databib.sty, databar.sty, datapie.sty, dataplot.sty, person.sty, databib.bst.
+%% This work consists of the files datatool.dtx and datatool.ins and the derived files datatool-base.sty, datatool-fp.sty, datatool-pgfmath.sty, datatool.sty, datagidx.sty, databib.sty, databar.sty, datapie.sty, dataplot.sty, person.sty, databib.bst.
%%
%% \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
@@ -39,7 +39,7 @@
%% Grave accent \` Left brace \{ Vertical bar \|
%% Right brace \} Tilde \~}
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{datatool}[2012/09/25 v2.11 (NLCT)]
+\ProvidesPackage{datatool}[2013/01/15 v2.13 (NLCT)]
\RequirePackage{xkeyval}
\RequirePackage{ifthen}
\RequirePackage{xfor}
@@ -112,7 +112,7 @@
\define@choicekey{datatool.sty}{math}[\val\nr]{fp,pgfmath}{%
\renewcommand*\@dtl@mathprocessor{#1}%
}
-\newcommand*{\@dtl@mathprocessor}{fp}
+\providecommand*{\@dtl@mathprocessor}{fp}
\ProcessOptionsX
\@dtl@construct@lopoffs
\RequirePackage{datatool-base}
@@ -164,6 +164,53 @@
database doesn't exist}{}{}%
}%
}
+\newcommand*{\DTLgnewdb}[1]{%
+ \DTLifdbexists{#1}%
+ {%
+ \PackageError{datatool}{Database `#1' already exists}{}%
+ }%
+ {%
+ \dtl@message{Creating database `#1'}%
+ \expandafter\global\expandafter\newtoks\csname dtldb@#1\endcsname
+ \expandafter\global\expandafter\newtoks\csname dtlkeys@#1\endcsname{}%
+ \expandafter\global\expandafter\newcount\csname dtlrows@#1\endcsname
+ \expandafter\global\expandafter\newcount\csname dtlcols@#1\endcsname
+ }%
+}
+\newcommand*{\DTLgdeletedb}[1]{%
+ \DTLifdbexists{#1}%
+ {%
+ \dtlforeachkey(\@dtl@key,\@dtl@col,\@dtl@type,\@dtl@head)\in{#1}\do
+ {%
+ \expandafter\global\expandafter\let\csname dtl@ci@#1@\@dtl@key\endcsname\undefined
+ }%
+ \expandafter\global\expandafter\let\csname dtldb@#1\endcsname\undefined
+ \expandafter\global\expandafter\let\csname dtlkeys@#1\endcsname\undefined
+ \expandafter\global\expandafter\let\csname dtlrows@#1\endcsname\undefined
+ \expandafter\global\expandafter\let\csname dtlcols@#1\endcsname\undefined
+ }%
+ {%
+ \PackageError{Can't delete database `#1':
+ database doesn't exist}{}{}%
+ }%
+}
+\newcommand*{\DTLgcleardb}[1]{%
+ \DTLifdbexists{#1}%
+ {%
+ \dtlforeachkey(\@dtl@key,\@dtl@col,\@dtl@type,\@dtl@head)\in{#1}\do
+ {%
+ \expandafter\global\expandafter\let\csname dtl@ci@#1@\@dtl@key\endcsname\undefined
+ }%
+ \expandafter\global\csname dtldb@#1\endcsname{}%
+ \expandafter\global\csname dtlkeys@#1\endcsname{}%
+ \expandafter\global\csname dtlrows@#1\endcsname=0\relax
+ \expandafter\global\csname dtlcols@#1\endcsname=0\relax
+ }%
+ {%
+ \PackageError{Can't clear database `#1':
+ database doesn't exist}{}{}%
+ }%
+}
\newcommand*{\DTLrowcount}[1]{%
\expandafter\number\csname dtlrows@#1\endcsname
}
@@ -189,7 +236,7 @@
\newcommand*{\@DTLnewrow}[1]{%
\DTLifdbexists{#1}%
{\@sDTLnewrow{#1}}%
- {\PackageErrors{datatool}{Can't add new row to database `#1':
+ {\PackageError{datatool}{Can't add new row to database `#1':
database doesn't exist}{}}%
}
\newcommand*{\@sDTLnewrow}[1]{%
@@ -487,7 +534,7 @@
{\noexpand\@dtl@key}{\noexpand\@dtl@type}%
{\noexpand\@dtl@colhead}{\noexpand\@dtl@before}%
{\noexpand\@dtl@after}{\the\csname dtlkeys@#1\endcsname}%
- {\number#2}}
+ {\number#2}}%
\@dtl@dogetprops
\@dtl@colhead={#3}%
\edef\@dtl@colnum{\number#2}\relax
@@ -537,7 +584,7 @@
}%
\dtl@dogetentry
\ifx\dtl@entry\dtlnovalue
- \@dtl@setnewvalue{#3}%
+ \@dtl@setnewvalue{#3}%
\toks@gconcat@middle@cx{dtldb@#1}%
{\dtlbeforerow}%
{%
@@ -617,16 +664,22 @@
\global\let#1=\DTLnumbernull
\fi
}
-\newcommand*{\DTLstringnull}{NULL}
-\newcommand*{\DTLnumbernull}{0}
+\newcommand*{\DTLstringnull}{\@dtlstringnull}
+\newcommand*{\@dtlstringnull}{NULL}
+\newcommand*{\DTLnumbernull}{\@dtlnumbernull}
+\newcommand*{\@dtlnumbernull}{0}
\newcommand*{\DTLifnull}[3]{%
- \ifx\DTLstringnull#1\relax
+ \ifx#1\dtlnovalue
#2%
\else
- \ifx\DTLnumbernull#1\relax
+ \ifx#1\DTLstringnull
#2%
\else
- #3%
+ \ifx#1\DTLnumbernull
+ #2%
+ \else
+ #3%
+ \fi
\fi
\fi
}
@@ -1202,7 +1255,7 @@
\gdef\DTLiflastrow##1##2{%
\expandafter\ifnum
\csname c@DTLrow\romannumeral\dtlforeachlevel\endcsname
- =\csname dtlcols@#2\endcsname\relax
+ =\csname dtlrows@#2\endcsname\relax
##1%
\else
##2%
@@ -1355,7 +1408,7 @@
\gdef\DTLiflastrow##1##2{%
\expandafter\ifnum
\csname c@DTLrow\romannumeral\dtlforeachlevel\endcsname
- =\csname dtlcols@#2\endcsname\relax
+ =\csname dtlrows@#2\endcsname\relax
##1%
\else
##2%
@@ -1608,7 +1661,7 @@
}
\newcommand{\DTLaddentryforrow}[5]{%
\DTLifdbexists{#1}%
- {
+ {%
\def\@dtl@notdone{\PackageError{datatool}{Unable to add entry
given by key `#4': condition not met for any row in database
`#1'}{}}%
@@ -1641,9 +1694,9 @@
\dtl@dogetentry
\ifx#1\dtlnovalue
\ifnum0\dtltype=0\relax
- \let#1=\DTLstringnull
+ \let#1=\@dtlstringnull
\else
- \let#1=\DTLnumbernull
+ \let#1=\@dtlnumbernull
\fi
\fi
\global\let#1#1%
@@ -1711,8 +1764,8 @@
\newcommand*{\dtldisplaystartrow}{}
\newcommand*{\DTLdisplaydb}[2][]{%
- \def\@dtl@doamp{\gdef\@dtl@doamp{&}}
- \def\@dtl@resetdoamp{\gdef\@dtl@doamp{\gdef\@dtl@doamp{&}}}
+ \def\@dtl@doamp{\gdef\@dtl@doamp{&}}%
+ \def\@dtl@resetdoamp{\gdef\@dtl@doamp{\gdef\@dtl@doamp{&}}}%
\edef\@dtl@maxcols{\expandafter\number
\csname dtlcols@#2\endcsname}%
\DTLnumitemsinlist{#1}{\@dtl@tmp}%
@@ -1726,7 +1779,7 @@
{}%
{%
\dtladdalign\@dtl@tabargs\@dtl@type\@dtl@idx\@dtl@maxcols
- }
+ }%
}%
\edef\@dtl@dobegintab{\noexpand\begin{tabular}[\dtldisplayvalign]{\@dtl@tabargs}}%
\@dtl@dobegintab
@@ -1793,8 +1846,8 @@
\def\@dtl@lastfoot{\@nil}%
\def\@dtl@omitlist{}%
\setkeys{displaylong}{#1}%
- \def\@dtl@doamp{\gdef\@dtl@doamp{&}}
- \def\@dtl@resetdoamp{\gdef\@dtl@doamp{\gdef\@dtl@doamp{&}}}
+ \def\@dtl@doamp{\gdef\@dtl@doamp{&}}%
+ \def\@dtl@resetdoamp{\gdef\@dtl@doamp{\gdef\@dtl@doamp{&}}}%
\@dtl@resetdostartrow
\edef\@dtl@maxcols{\expandafter\number
\csname dtlcols@#2\endcsname}%
@@ -2104,6 +2157,7 @@
}%
}%
\ifnum\@dtl@elements=0\relax
+ \PackageError{datatool}{Unable to evaluate mean: no data}{}%
\else
\edef\@dtl@n{\number\@dtl@elements}%
\DTLdiv{#4}{#4}{\@dtl@n}%
@@ -2383,23 +2437,20 @@
\newtoks\@dtl@list
\newcommand*{\DTLsort}{\@ifstar\@sDTLsort\@DTLsort}
\newcommand{\@DTLsort}[3][]{%
- \DTLifdbexists{#3}%
- {%
- \edef\@dtl@replacementkeys{#1}%
- \edef\@dtl@sortorder{#2}%
- \let\@dtl@comparecs=\dtlcompare
- \dtl@sortdata{#3}%
- }%
- {%
- \PackageError{datatool}{Database `#3' doesn't exist}{}%
- }%
+ \dtlsort[#1]{#2}{#3}{\dtlicompare}%
}
-\newcommand{\@sDTLsort}[3][]{%
+\newcommand*{\@sDTLsort}[3][]{%
+ \dtlsort[#1]{#2}{#3}{\dtlicompare}%
+}
+\newcommand{\dtlsort}[4][]{%
\DTLifdbexists{#3}%
{%
+ \ifnum\DTLrowcount{#3}>100\relax
+ \typeout{Sorting `#3' - this may take a while.}%
+ \fi
\edef\@dtl@replacementkeys{#1}%
\edef\@dtl@sortorder{#2}%
- \let\@dtl@comparecs=\dtlicompare
+ \let\@dtl@comparecs=#4%
\dtl@sortdata{#3}%
}%
{%
@@ -2411,7 +2462,7 @@
\newcommand*{\dtl@sortdata}[1]{%
\def\@dtl@sortedlist{}%
\edef\@dtl@dbname{#1}%
- \@dtlforeachrow(\@dtl@rowAnum,\@dtl@rowAcontents)\in{#1}\do{%
+ \@dtlforeachrow(\@dtl@rowAnum,\@dtl@rowAcontents)\in\@dtl@dbname\do{%
\@dtl@rowa=\expandafter{\@dtl@rowAcontents}%
\def\@dtl@newlist{}%
\@dtl@insertdonefalse
@@ -2421,7 +2472,8 @@
\db@row@id@w \@nil\db@row@id@end@%
\db@row@id@w \@nil\db@row@id@end@%
\db@row@elt@end@%
- \@@{\@dtl@rowBnum}{\@dtl@rowBcontents}{%
+ \@@{\@dtl@rowBnum}{\@dtl@rowBcontents}%
+ {%
\@dtl@rowb=\expandafter{\@dtl@rowBcontents}%
\dtlrownum=\@dtl@rowBnum
\if@dtl@insertdone
@@ -2475,7 +2527,8 @@
{\@dtl@sortedlist}%
}
\newcommand{\@dtl@sortcriteria}[2]{%
- \@for\@dtl@level:=\@dtl@sortorder\do{%
+ \@for\@dtl@level:=\@dtl@sortorder\do
+ {%
\expandafter\@dtl@getsortdirection\@dtl@level=\relax
\let\@dtl@keya=\@dtl@key
\let\@dtl@keyb=\@dtl@key
@@ -2554,7 +2607,7 @@
\PackageError{datatool}{Invalid sort direction
`\@dtl@sortdirection'}{The sort direction can only be
one of `ascending' or `descending'}%
- \def\@dtl@sortdirection{-1}
+ \def\@dtl@sortdirection{-1}%
\fi
\fi
}%
@@ -2714,6 +2767,97 @@
database}{}%
}%
}
+\newcommand*{\dtl@saverawdbhook}{}
+\newcommand*{\DTLsaverawdb}[2]{%
+ \DTLifdbexists{#1}%
+ {%
+ \openout\@dtl@write=#2\relax
+ \protected@write{\@dtl@write}{}{%
+ \string\DTLifdbexists{#1}\expandafter\@gobble\string\%^^J%
+ {%
+ \string\PackageError{datatool}{Database `#1' ^^Jalready exists}{}%
+ \expandafter\@gobble\string\%^^J%
+ \string\aftergroup\string\endinput
+ }%
+ {%
+ }\expandafter\@gobble\string\%
+ }%
+ {%
+ \def\db@row@elt@w{\expandafter\@gobble\string\%^^J\string\db@row@elt@w\space}%
+ \def\db@row@elt@end@{\expandafter\@gobble\string\%^^J\string\db@row@elt@end@\space}%
+ \def\db@row@id@w{\expandafter\@gobble\string\%^^J\string\db@row@id@w\space}%
+ \def\db@row@id@end@{\expandafter\@gobble\string\%^^J\string\db@row@id@end@\space}%
+ \def\db@col@elt@w{\expandafter\@gobble\string\%^^J\string\db@col@elt@w\space}%
+ \def\db@col@elt@end@{\expandafter\@gobble\string\%^^J\string\db@col@elt@end@\space}%
+ \def\db@col@id@w{\expandafter\@gobble\string\%^^J\string\db@col@id@w\space}%
+ \def\db@col@id@end@{\expandafter\@gobble\string\%^^J\string\db@col@id@end@\space}%
+ \def\db@plist@elt@w{\expandafter\@gobble\string\%^^J\string\db@plist@elt@w\space}%
+ \def\db@plist@elt@end@{\expandafter\@gobble\string\%^^J\string\db@plist@elt@end@\space}%
+ \def\db@key@id@w{\expandafter\@gobble\string\%^^J\string\db@key@id@w\space}%
+ \def\db@key@id@end@{\expandafter\@gobble\string\%^^J\string\db@key@id@end@\space}%
+ \def\db@type@id@w{\expandafter\@gobble\string\%^^J\string\db@type@id@w\space}%
+ \def\db@type@id@end@{\expandafter\@gobble\string\%^^J\string\db@type@id@end@\space}%
+ \def\db@header@id@w{\expandafter\@gobble\string\%^^J\string\db@header@id@w\space}%
+ \def\db@header@id@end@{\expandafter\@gobble\string\%^^J\string\db@header@id@end@\space}%
+ \protected@write{\@dtl@write}{}{\string\bgroup\string\makeatletter}%
+ \protected@write{\@dtl@write}{}{\string\dtl@message{Reconstructing database
+ ^^J`#1'}\expandafter\@gobble\string\%}%
+ \protected@write{\@dtl@write}{}{%
+ \string\expandafter
+ \string\global\string\expandafter^^J\string\newtoks
+ \string\csname\space dtlkeys@#1\string\endcsname}%
+ \protected@write{\@dtl@write}{}{%
+ \string\expandafter
+ \string\global^^J
+ \string\csname\space dtlkeys@#1\string\endcsname
+ =\expandafter\@gobble\string\{\expandafter\@gobble\string\%}%
+ \expandafter\protected@xdef\csname dtl@rawwritedbkeys@#1\endcsname{%
+ \the\csname dtlkeys@#1\endcsname}%
+ \protected@write{\@dtl@write}{}{\csname dtl@rawwritedbkeys@#1\endcsname}%
+ \protected@write{\@dtl@write}{}{\expandafter\@gobble\string\}\expandafter\@gobble\string\%}%
+ \dtl@saverawdbhook
+ \protected@write{\@dtl@write}{}{%
+ \string\expandafter\string\global
+ \string\expandafter^^J\string\newtoks
+ \string\csname\space dtldb@#1\string\endcsname}%
+ \protected@write{\@dtl@write}{}{%
+ \string\expandafter
+ \string\global^^J\string\csname\space dtldb@#1\string\endcsname
+ =\expandafter\@gobble\string\{\expandafter\@gobble\string\%}%
+ \expandafter\protected@xdef\csname dtl@rawwritedb@#1\endcsname{\the\csname dtldb@#1\endcsname}%
+ \protected@write{\@dtl@write}{}{\csname dtl@rawwritedb@#1\endcsname}%
+ \protected@write{\@dtl@write}{}{\expandafter\@gobble\string\}\expandafter\@gobble\string\%}%
+ \protected@write{\@dtl@write}{}{\string\expandafter\string\global^^J
+ \string\expandafter\string\newcount
+ \string\csname\space dtlrows@#1\string\endcsname}%
+ \protected@write{\@dtl@write}{}{\string\expandafter\string\global^^J
+ \string\csname\space dtlrows@#1\string\endcsname
+ =\expandafter\number\csname dtlrows@#1\endcsname\string\relax}%
+ \protected@write{\@dtl@write}{}{\string\expandafter\string\global^^J
+ \string\expandafter\string\newcount
+ \string\csname\space dtlcols@#1\string\endcsname}%
+ \protected@write{\@dtl@write}{}{\string\expandafter\string\global^^J
+ \string\csname\space dtlcols@#1\string\endcsname
+ =\expandafter\number\csname dtlcols@#1\endcsname\string\relax}%
+ \dtlforeachkey(\@dtl@key,\@dtl@col,\@dtl@type,\@dtl@head)\in{#1}\do
+ {%
+ \edef\dtl@tmp{%
+ \string\expandafter^^J
+ \string\gdef
+ \string\csname\space dtl@ci@#1@\@dtl@key\string\endcsname
+ {\csname dtl@ci@#1@\@dtl@key\endcsname}\expandafter\@gobble\string\%
+ }%
+ \expandafter\write\expandafter\@dtl@write\expandafter{\dtl@tmp}%
+ }%
+ \protected@write{\@dtl@write}{}{\string\egroup}%
+ }%
+ \closeout\@dtl@write
+ }%
+ {%
+ \PackageError{datatool}{Can't save database `#1': no such
+ database}{}%
+ }%
+}
\newread\@dtl@read
\newcount\dtl@entrycr
\define@boolkey{loaddb}[dtl]{noheader}[true]{}
@@ -2748,13 +2892,15 @@
}%
{%
\dtl@trim#2%
- }
+ }%
}
\newcommand*{\@dtl@readrawline}[2]{%
\@dtl@rawread#1 to #2%
\dtl@trim#2%
\dtl@domappings\@dtl@line
}
+\newif\ifDTLnewdbonload
+\DTLnewdbonloadtrue
\newcommand*{\DTLloaddb}{%
\let\@dtl@doreadline\@dtl@readline
\@dtlloaddb
@@ -2772,7 +2918,9 @@
\advance\dtl@omitlines by \m@ne
\read\@dtl@read to \@dtl@line
\repeat
- \DTLnewdb{#2}%
+ \ifDTLnewdbonload
+ \DTLnewdb{#2}%
+ \fi
\ifeof\@dtl@read
\PackageWarning{datatool}{File `#3' has no data}%
\else
@@ -2983,8 +3131,8 @@
\def\@dtl@rawmappings{{#1}{#2}}%
}%
{%
- \def\@dtl@tmp{{#1}{#2}}
- \protected@edef\@dtl@rawmappings{\the\@dtl@toks,\@dtl@tmp}
+ \def\@dtl@tmp{{#1}{#2}}%
+ \protected@edef\@dtl@rawmappings{\the\@dtl@toks,\@dtl@tmp}%
}%
}
\newcommand*{\@dtl@rawmappings}{}