I'm writing a MatLab-LaTeX "interface", which includes a LaTeX command \data[options]{tag}
. It reads the value named tag
from a .csv file, and outputs it through siunitx
.
I want the user to be able to call the command with a key filename
to pick a .csv file ("data.csv" default), and pass any and all other options on to siunitx
, preferably with defaults.
Right now, hard-coding in a couple of options works, but it gives me no control in-document.
My code follows:
% datax.sty
\ProvidesPackage{datax}
\RequirePackage{csvsimple}
\RequirePackage{siunitx}
\RequirePackage{pgfkeys}
\makeatletter
\pgfqkeys{/data}%
{filename/.estore in = \@filename,%
filename/.default = data.csv%
}
\newcommand{\data}[2][]{%
\pgfqkeys{/siunitx}{/remainingkeys/.style={}}%
\pgfqkeys{/data}{filename}%
\pgfqkeys{/data}{#1}%
\csvreader[filter strcmp={\@datatag}{#2}]%
{\@filename}{1=\@datatag,2=\@datavalue,3=\@dataunit}%
{%
\SI[round-mode=figures,round-precision=3,scientific-notation=true] {\@datavalue}{\@dataunit}%
}%
}
\makeatother
,
% Inside document
The length was measured to \data[filename=newdata.csv,scientific-notation=false]{length}.
and
% newdata.csv
tag,value,unit
length,23.45,\meter