将文件中的值插入乳胶文档中

Mih*_*238 3 pdf latex pdf-generation pdflatex

如果有乳胶文档,我如何从文件中读取一些键值对并将它们插入到文档中?

像这样的东西:

乳胶代码:

customer ID: ${customerID}
Run Code Online (Sandbox Code Playgroud)

文本文件:

customerID=123456
Run Code Online (Sandbox Code Playgroud)

生成的.pdf文件应包含客户 ID。

Fed*_*ico 6

只需在序言中使用以下代码导入 .dat 文件:

% package to open file containing variables
\usepackage{datatool, filecontents}
\DTLsetseparator{,}% Set the separator between the columns.

% import data
\DTLloaddb[noheader, keys={thekey,thevalue}]{mydata}{../mydata.dat}
% Loads mydata.dat with column headers 'thekey' and 'thevalue'
\newcommand{\var}[1]{\DTLfetch{mydata}{thekey}{#1}{thevalue}}
Run Code Online (Sandbox Code Playgroud)

请注意,在此示例中keys, 和values之间使用逗号分隔。我的 .dat 文件如下所示:

number_participants,21
total_score,32.55
Run Code Online (Sandbox Code Playgroud)

然后在 LaTeX 文档的正文中,只需使用以下命令引用变量:\var{variable_name}

欲了解更多信息,请观看此视频