2011-03-19 103 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>