在乳胶文档中插入文件中的值 [英] Insert values from a file in a latex document
本文介绍了在乳胶文档中插入文件中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有一个乳胶文档,我如何从文件中读取一些键-值对并将其插入文档中?
If a have a latex document, how can I read some key-value pairs from a file an insert them into the document?
类似这样的东西:
乳胶代码:
customer ID: ${customerID}
文本文件:
customerID=123456
然后生成的.pdf
文件应包含客户ID.
And the resulting .pdf
file should contain the customer ID.
推荐答案
我们总是可以编写一个perl脚本来扩展它们...
We can always write a perl script to expand them...
defs.txt:
customerID=123456
customerTel=22530000000
doc.tex:
\documentclass{article}
\begin{document}
latex
customer ID: ${customerID}
and ${address}
costum telphone ID: ${customerTel}
\end{document}
perl脚本tex-defs:
perl script tex-defs:
#!/usr/bin/perl -n
BEGIN{$tex=0;}
if(not $tex and /^(\w+)=(.*)/) { $v{$1}=$2 }
if(/\\documentclass\{/ ) { $tex=1 }
if($tex) { s/\$\{(\w+)\}/$v{$1} || "???$1"/ge; print }
测试(在chmod ...之后):
testing (after chmod...):
$ tex-defs defs.txt doc.tex
\documentclass{article}
\begin{document}
latex
customer ID: 123456
and ???address
costum telphone ID: 22530000000
\end{document}
这篇关于在乳胶文档中插入文件中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文