LaTeX 在 php 中的执行和路径问题
我正在尝试使用 exec 从 php 编译乳胶源文件:
echo shell_exec("/usr/texbin/pdflatex source.tex");
不幸的是,当通过 php 调用乳胶时,乳胶似乎看不到所有包。
例如,
LaTeX Error: File `customclass.cls' not found
当我尝试使用安装在本地 texmf
文件夹中的 customclass
时,就会出现此问题。安装在其他地方的一些软件包也存在同样的问题。
这肯定与路径变量或类似的设置有关,但我一个小时都找不到什么。
有人有主意吗?
I am trying to compile a latex source file from php, using exec
:
echo shell_exec("/usr/texbin/pdflatex source.tex");
Unfortunately, latex doesn't seem to see all packages when it is called via php.
For example, I get
LaTeX Error: File `customclass.cls' not found
when I try to use customclass
, installed in my local texmf
folder. There is also the same problem for some packages installed elsewhere.
This has certainly something to do with a path variable or something like that to set up, but I haven't been able to find what for an hour.
Has someone an idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PHP 解释器可能以其他用户身份运行,例如 www-data 或相关的东西:这意味着它看不到安装在您常用用户的 texmf 目录中的包(我假设这就是您所说的本地),因为仅当 pdflatex 以该用户身份运行时,才会加载用户的 texmf。
这似乎是一个潜在的解决方案,可以根据 shell 变量将 LaTeX 路径扩展到本地 texmf 所在的位置: 临时安装(La)TeX 文件(来自 TeX FAQ)。
The PHP interpreter is probably running as some other user, like www-data or something related: this means that it can't see the packages installed in your usual user's texmf directory (I'm assuming that's what you mean by local), because the user's texmf is only loaded when pdflatex is run as that user.
This seems like a potential solution to extending the LaTeX path to wherever your local texmf is, based on shell variables: Temporary installation of (La)TeX files (from the TeX FAQ).
您可以将 *.cls 文件放入与 source.tex 相同的目录中。如果您随后将目录更改为“当前目录”,则在启动 Latex 时,Latex 解释器也会找到该目录并用于编译 Latex 文件。
这也是与 php 一起使用的更好的解决方案,因为您不希望应用程序的用户将某些内容安装到 www-data 用户的主目录中。出于安全原因,这可能会被禁止。
因此,解决方案是:
You can put your *.cls files into the same directory as source.tex. If your then change the directory to be the "current directory", when starting latex, then it also will be found by the latex interpreter and used for compiling your Latex file.
This is also a better solution for using with with php, as you would not want to make the user of your application install something into the home directory of www-data user. This might be forbidden for security reasons.
So, the solution is:
/Users/My/Sites/tex/index.php
文件的来源如下。例如,让它可以通过http://localhost/~My/tex/index.php
链接访问。The source of
/Users/My/Sites/tex/index.php
file is bellow. For example let it be reachable byhttp://localhost/~My/tex/index.php
link.