如何使用数据工具中的值作为 Latex 文档中的参数

如何使用数据工具中的值作为 Latex 文档中的参数
\documentclass[a4paper,12pt]{article} % Format de page
\usepackage{pst-bar,pst-plot,pstricks-add}
\usepackage{datatool, filecontents}
\DTLsetseparator{ = }% Set the separator between the columns. Could be
% anything you like. Whitespaces are not trimmed, so you have to set
%them as part of the separator.

\begin{filecontents*}{mydata.dat}
foo = 10
bar = 20
"x" = 30
chartwidth = 250
\end{filecontents*}

\begin{document}
\thispagestyle{empty}
\psset{xunit=1 mm,yunit=1 mm}

\DTLloaddb[noheader, keys={thekey,thevalue}]{mydata}{mydata.dat}
% Loads mydata.dat with column headers 'thekey' and 'thevalue'

\newcommand{\missingvariable}[1]{\DTLfetch{mydata}{thekey}{#1}{thevalue}}

\def\chartwidth{\missingvariable{chartwidth}}

\begin{pspicture}(0,0)(\chartwidth,75)
  \psaxes[Dx=20,dx=1 cm,Ox=0,Dy=0.005,dy=1 cm,tickstyle=below,ticksize=5pt](10,10)(\chartwidth,71)
\end{pspicture}

\end{document} 

答案1

我最终使用了 readray 包并且它起作用了。

\documentclass[a4paper,12pt]{article} % Format de page
\usepackage{pst-bar,pst-plot,pstricks-add}
\usepackage{filecontents}
\usepackage{readarray}

\begin{filecontents*}{personalinfo.csv}
100
\end{filecontents*}

\readarraysepchar{\\}
\readdef{personalinfo.csv}\myrawdata
\setsepchar{\\/,}

\readlist*{\mydata}{\myrawdata}

\def\largeur{\mydata[1,1]}

\begin{document}
\thispagestyle{empty}
\psset{xunit=1 mm,yunit=1 mm}
\largeur
\begin{pspicture}(0,0)(\largeur,75)
\psaxes[Dx=20,dx=1 cm,Ox=0,Dy=0.005,dy=1 cm,tickstyle=below,ticksize=5pt](10,10)(\largeur,75)
\end{pspicture}
\end{document}

相关内容