對於其他人搜索
CLSI似乎是管理它的方式。有一個仍維持開源API來編譯LaTeX文件:CLSI ShareLaTeX
由於mike42 編譯膠乳PHP ...的另一個非常有趣example這實際上是在我的情況要走的路...是這樣的代碼最終像這樣生成一個.tex
文件,該文件是一個有效的LaTeX的文件和一個有效的PHP文件在一次:
% This file is a valid PHP file and also a valid LaTeX file
% When processed with LaTeX, it will generate a blank template
% Loading with PHP will fill it with details
\documentclass{article}
% Required for proper escaping
\usepackage{textcomp} % Symbols
\usepackage[T1]{fontenc} % Input format
% Because Unicode etc.
\usepackage{fontspec} % For loading fonts
\setmainfont{Liberation Serif} % Has a lot more symbols than Computer Modern
% Make placeholders visible
\newcommand{\placeholder}[1]{\textbf{$<$ #1 $>$}}
% Defaults for each variable
\newcommand{\test}{\placeholder{Data here}}
% Fill in
% <?php echo "\n" . "\\renewcommand{\\test}{" . LatexTemplate::escape($data['test']) . "}\n"; ?>
\begin{document}
\section{Data From PHP}
\test{}
\end{document}
如果PHP安全模式被禁止,並且服務器有xelatex/pdflatex安裝執行直接在文件上執行命令...
首先填寫的 LaTeX的代碼需要通過做這樣的事情被儲存在臨時文件:
/**
* Generate a PDF file using xelatex and pass it to the user
*/
public static function download($data, $template_file, $outp_file) {
// Pre-flight checks
if(!file_exists($template_file)) {
throw new Exception("Could not open template");
}
if(($f = tempnam(sys_get_temp_dir(), 'tex-')) === false) {
throw new Exception("Failed to create temporary file");
}
$tex_f = $f . ".tex";
$aux_f = $f . ".aux";
$log_f = $f . ".log";
$pdf_f = $f . ".pdf";
// Perform substitution of variables
ob_start();
include($template_file);
file_put_contents($tex_f, ob_get_clean());
}
之後選擇的發動機應執行生成輸出文件:
// Run xelatex (Used because of native unicode and TTF font support)
$cmd = sprintf("xelatex -interaction nonstopmode -halt-on-error %s",
escapeshellarg($tex_f));
chdir(sys_get_temp_dir());
exec($cmd, $foo, $ret);
// No need for these files anymore
@unlink($tex_f);
@unlink($aux_f);
@unlink($log_f);
// Test here
if(!file_exists($pdf_f)) {
@unlink($f);
throw new Exception("Output was not generated and latex returned: $ret.");
}