From 140b6ff99d0a085bc04019ed910de8adf571e45a Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 12 Nov 2011 23:36:55 +0000 Subject: csvsimple (11nov11) git-svn-id: svn://tug.org/texlive/trunk@24575 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/csvsimple/csvsimple.sty | 94 +++++++++++++++------- 1 file changed, 66 insertions(+), 28 deletions(-) (limited to 'Master/texmf-dist/tex/latex/csvsimple') diff --git a/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty b/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty index 67f48ed1692..d2945adf221 100644 --- a/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty +++ b/Master/texmf-dist/tex/latex/csvsimple/csvsimple.sty @@ -1,4 +1,4 @@ -%% The LaTeX package csvsimple - version 1.03 (2011/11/04) +%% The LaTeX package csvsimple - version 1.04 (2011/11/11) %% csvsimple.sty: Simple LaTeX CSV file processing %% %% ------------------------------------------------------------------------------------------- @@ -18,7 +18,7 @@ %% This work consists of all files listed in README %% \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{csvsimple}[2011/11/04 version 1.03 LaTeX CSV file processing] +\ProvidesPackage{csvsimple}[2011/11/11 version 1.04 LaTeX CSV file processing] \RequirePackage{pgfkeys,ifthen} @@ -115,12 +115,23 @@ \def\csv@current@col{\csname csvcol\roman{csvcol}\endcsname} -% head names +% auto head names +\def\set@csv@autohead{% + \toks0=\expandafter{\csname\csv@current@col\endcsname}% + \toks1=\expandafter{\csname csvcol\roman{csvcol}\endcsname}% + \edef\csv@temp{\noexpand\gdef\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\noexpand\gdef\the\toks0{}}}% + \csv@temp% +} + + +% head names and numbers \def\set@csv@head{% \toks0={\gdef##1}% \toks1=\expandafter{\csname csvcol\roman{csvcol}\endcsname}% - \edef\temp{\noexpand\pgfkeysdef{/csv head/\csv@current@col}{\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\the\toks0{}}}}% - \temp% + \edef\csv@temp{\noexpand\pgfkeysdef{/csv head/\csv@current@col}{\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\the\toks0{}}}}% + \csv@temp% + \edef\csv@temp{\noexpand\pgfkeysdef{/csv head/\thecsvcol}{\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\the\toks0{}}}}% + \csv@temp% } % head line @@ -131,6 +142,7 @@ \setcounter{csvcol}{0}% \loop% \stepcounter{csvcol}% + \csv@opt@headtocolumnames% \set@csv@head% \ifnum\thecsvcol<\csv@columncount\repeat% \toks@=\expandafter{\csv@columnnames}% @@ -139,6 +151,26 @@ \csv@posthead% } +% head numbers for no head +\def\set@csv@nohead{% + \toks0={\gdef##1}% + \toks1=\expandafter{\csname csvcol\roman{csvcol}\endcsname}% + \edef\csv@temp{\noexpand\pgfkeysdef{/csv head/\thecsvcol}{\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\the\toks0{}}}}% + \csv@temp% +} + +% no head line +\def\csv@noheadline{% + \setcounter{csvcol}{0}% + \loop% + \stepcounter{csvcol}% + \set@csv@nohead% + \ifnum\thecsvcol<\csv@columncount\repeat% + \toks@=\expandafter{\csv@columnnames}% + \edef\csv@processkeys{\noexpand\pgfkeys{/csv head/.cd,\the\toks@}}% + \csv@processkeys% +} + % check filter \def\csv@checkfilter{% \csv@prefiltercommand% @@ -191,6 +223,7 @@ % options \csvset{default,every csv,#1}% \csv@prereading% + \csv@table@begin% \setcounter{csvinputline}{0}% % start reading \openin\csv@file=\csv@filename\relax% @@ -245,6 +278,7 @@ \closein\csv@file% \@endloophook% \csv@latepostlastline% + \csv@table@end% \csv@postreading% } @@ -275,19 +309,23 @@ \def\temp{#1}\toks1=\expandafter{\temp}% \xdef\csv@columnnames{\the\toks0,\the\toks1}% }, - command/.gstore in=\csv@body, + command/.gstore in=\csv@body,% check column count/.code={\ifthenelse{\equal{#1}{true}}{% \global\let\csv@opt@checkcolumncount=\csv@checkcolumncount}{% \global\let\csv@opt@checkcolumncount=\csv@nocheckcolumncount}}, - check column count/.default=true, + check column count/.default=true,% on column count error/.gstore in=\csv@columncounterror, head/.code={\ifthenelse{\equal{#1}{true}}{% \global\let\csv@opt@processheadline=\csv@processheadline% \pgfkeysalso{check column count}}{% - \global\let\csv@opt@processheadline=\csv@empty% + \global\let\csv@opt@processheadline=\csv@noheadline% \pgfkeysalso{check column count=false,late after head=}}}, - head/.default=true, - column count/.gstore in=\csv@columncount, + head/.default=true,% + head to column names/.code={\ifthenelse{\equal{#1}{true}}{% + \global\let\csv@opt@headtocolumnames=\set@csv@autohead}{% + \global\let\csv@opt@headtocolumnames=\csv@empty}},% + head to column names/.default=true,% + column count/.gstore in=\csv@columncount,% filter/.code={% \def\temp{#1}\toks@=\expandafter{\temp}% \xdef\csv@iffilter{\noexpand\ifthenelse{\the\toks@}}}, @@ -310,6 +348,8 @@ after table/.gstore in=\csv@posttable, table head/.gstore in=\csv@tablehead, table foot/.gstore in=\csv@tablefoot, + @table/.code 2 args={\gdef\csv@table@begin{#1}\gdef\csv@table@end{#2}}, + no table/.style={@table={}{}}, % % default for reset default/.style={ @@ -317,6 +357,8 @@ command=\csvline, column names reset, head, + head to column names=false, + column count=10, on column count error=, nofilter, before filter=, @@ -330,7 +372,8 @@ before table=, after table=, table head=, - table foot= + table foot=, + no table }, default, % @@ -342,17 +385,22 @@ filter equal/.style 2 args={filter=\equal{#1}{#2}}, filter not equal/.style 2 args={filter=\not\equal{#1}{#2}}, tabular/.style={ - before reading=\csv@pretable\begin{tabular}{#1}\csv@tablehead, - after reading=\csv@tablefoot\end{tabular}\csv@posttable, + @table={\csv@pretable\begin{tabular}{#1}\csv@tablehead}{\csv@tablefoot\end{tabular}\csv@posttable}, late after line=\\}, centered tabular/.style={ - before reading=\begin{center}\csv@pretable\begin{tabular}{#1}\csv@tablehead, - after reading=\csv@tablefoot\end{tabular}\csv@posttable\end{center}, + @table={\begin{center}\csv@pretable\begin{tabular}{#1}\csv@tablehead}{\csv@tablefoot\end{tabular}\csv@posttable\end{center}}, late after line=\\}, longtable/.style={ - before reading=\csv@pretable\begin{longtable}{#1}\csv@tablehead, - after reading=\csv@tablefoot\end{longtable}\csv@posttable, + @table={\csv@pretable\begin{longtable}{#1}\csv@tablehead}{\csv@tablefoot\end{longtable}\csv@posttable}, late after line=\\}, + tabbing/.style={ + @table={\csv@pretable\begin{tabbing}\csv@tablehead}{\csv@tablefoot\end{tabbing}\csv@posttable}, + late after line=\\, + late after last line=}, + centered tabbing/.style={ + @table={\begin{center}\csv@pretable\begin{tabbing}\csv@tablehead}{\csv@tablefoot\end{tabbing}\csv@posttable\end{center}}, + late after line=\\, + late after last line=}, autotabular/.style={ file=#1, after head=\csv@pretable\begin{tabular}{|*{\csv@columncount}{l|}}\csv@tablehead, @@ -367,17 +415,7 @@ table head=\hline\csvlinetotablerow\\\hline\endhead\hline\endfoot, late after line=\\, late after last line=\csv@tablefoot\end{longtable}\csv@posttable, - command=\csvlinetotablerow}, - tabbing/.style={ - before reading=\csv@pretable\begin{tabbing}\csv@tablehead, - after reading=\csv@tablefoot\end{tabbing}\csv@posttable, - late after line=\\, - late after last line=}, - centered tabbing/.style={ - before reading=\begin{center}\csv@pretable\begin{tabbing}\csv@tablehead, - after reading=\csv@tablefoot\end{tabbing}\csv@posttable\end{center}, - late after line=\\, - late after last line=} + command=\csvlinetotablerow} } \def\csvautotabular#1{\csvloop{autotabular={#1}}} -- cgit v1.2.3