如何从 LaTeX 执行 shell 脚本? [英] How to execute shell script from LaTeX?

查看:24
本文介绍了如何从 LaTeX 执行 shell 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 LaTeX 中执行以下操作:

I'm trying to do the following in LaTeX:

documentclass{article}
egin{document}
execute{/usr/local/bin/my-shell-script.sh}
end{document}

想法是在 .tex 文档处理的那一刻执行 /usr/local/bin/my-shell-script.sh 并将其输出注入LaTeX溪流.有可能吗?

The idea is to execute /usr/local/bin/my-shell-script.sh at the moment of .tex document processing and inject its output into LaTeX stream. Is it possible at all?

PS.通过我制作的包可能:iexec

PS. It's possible through the package I've made: iexec

推荐答案

我会做类似以下的事情(部分是出于 Roman 的建议):让你的 LaTeX 文件成为

I would do something like the following (partially motivated by what Roman suggested): make your LaTeX file be

documentclass{article}
egin{document}
input{scriptoutput.tex}
end{document}

并使用

/usr/local/bin/my-shell-script.sh > scriptoutput.tex

如果你想让它在必要时自动运行,你可以将它编码到一个 makefile 中.或者,您可以使用 TeX write18命令,

You could encode this in a makefile if you want to have it run automatically when necessary. Alternatively, you could use the TeX write18 command,

documentclass{article}
immediatewrite18{/usr/local/bin/my-shell-script.sh > scriptoutput.tex}
egin{document}
input{scriptoutput.tex}
end{document}

我认为每次编译文档时都会自动运行 shell 脚本.immediate 是必要的,以确保在 LaTeX 遇到命令时运行脚本,而不是等到输出页面被写入.(有关发货例程的更多信息,请参阅这个问题.)

and I think that would automatically run the shell script each time you compile the document. The immediate is necessary to ensure that the script is run when LaTeX encounters the command, rather than waiting until a page of output is written. (See this question for more on the shipout routine.)

这篇关于如何从 LaTeX 执行 shell 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆