2011-03-19 151 views
0

我试图编译从PHP乳胶源文件,使用exec乳胶执行

echo shell_exec("/usr/texbin/pdflatex source.tex"); 

不幸的是,乳胶似乎没有看到所有包当它通过被称为PHP。

例如,我得到

LaTeX Error: File `customclass.cls' not found 

,当我尝试使用customclass,安装在我的本地texmf文件夹。其他地方安装的一些软件包也有同样的问题。

这肯定与路径变量或类似的东西有关设置,但我一直没能找到什么一个小时。

有人想法吗?

回答

1

PHP解释器可能像一些其他用户一样运行,如www-data或相关的东西:这意味着它不能看到安装在通常用户的texmf目录中的包(我假设这就是你的意思本地),因为用户的texmf仅在以该用户运行pdflatex时加载。

这似乎是一个潜在的解决方案来扩展LaTeX的路径,无论您的本地TEXMF,基于shell变量:http://www.tex.ac.uk/cgi-bin/texfaq2html?label=tempinst

+0

我曾尝试与路径变量打球,但我一直没能得到它的工作...对于eaemple与 '运行putenv(“TEXINPUTS = /路径为/ TEXMF /”); echo shell_exec(“/ usr/texbin/pdflatex source.tex”);' LaTeX不再找到'source.tex' ... – Klaus 2011-03-19 19:47:17

+0

是否putenv会写在TEXINPUTS之前的任何东西?对不起,我对PHP不太熟悉,putenv文档没有说。如果是这样,可能会有一个。在TEXINPUTS默认情况下,并设置它与putenv覆盖? – thenoviceoof 2011-03-19 22:07:16

1

你可以把你* .CLS文件到同一目录source.tex。如果你的目录改为“当前目录”,那么在启动latex时,它也会被latex解释器找到并用于编译你的Latex文件。

这也是与php一起使用的更好的解决方案,因为您不想让应用程序的用户将某些内容安装到www数据用户的主目录中。出于安全原因,这可能是被禁止的。

所以,解决的办法是:

  • 放source.tex到目录中称为latexfiles(或您选择的名称)
  • 把你的* .CLS到latexfiles文件
  • 使用下面的代码编译你的乳胶文件:
passthru('cd /path/to/latexfiles/; pdflatex source.tex', $r); 
echo $r; 
1

/Users/My/Sites/tex/index.php文件的来源是波纹管。例如,让它可以通过http://localhost/~My/tex/index.php链接到达。

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
     <meta http-equiv="content-type" content="text/html;charset=utf-8" /> 
     <title>PDF file compillation</title> 
</head> 
<body> 
<?php 
ini_set('safe_mode', 'Off'); 
$output = array(); 
/* 
    /usr/texbin/ - directory, where the pdftex exists 
    /Users/My/Sites/tex/output - directory for test.pdf and everything else. This directory have to have permissions to write. 
    /Users/My/Sites/tex/test.tex - source .tex file 
*/ 
exec("/usr/texbin/pdftex --shell-escape --synctex=1 -output-directory=/Users/My/Sites/tex/output /Users/My/Sites/tex/test.tex", $output); 
if($output){ 
    echo("<h3>Console output</h3><pre>".implode("\n", $output)."</pre>"); 
/* 
    /Users/My/Sites/tex/output/test.pdf - the result file after compilling 
*/ 
    echo('<p>Go to compilled <a href="http://localhost/~My/tex/output/test.pdf">PDF file</a></p>'); 
}else{ 
    echo('<h3>Error</h3><p>Shell script execution failed.</p>'); 
} 
?> 
</body> 
</html>