To convert latex to pdf in PHP, first we need to download text live
http://www.tug.org/texlive/
xelatex executable from text live will be used in PHP
1) In temporary directory, we put the text template as a tex file and run xelatex to convert tex to pdf.
then display pdf file.
Note;
ob_get_contents — Return the contents of the output buffer
tempnam — Create file with unique file name
sys_get_temp_dir — Returns directory path used for temporary files
basename — Returns trailing name component of path
index.php
<?php
ob_start();
include 'latex_template.php';
$outputData .= ob_get_contents();
ob_end_clean();
$texFile = tempnam(sys_get_temp_dir(), 'test');
$base = basename($texFile);
rename($texFile, $texFile.".tex");
$texFile .= ".tex";
file_put_contents($texFile, $outputData);
chdir(dirname(realpath($texFile)));
$console = shell_exec("xelatex {$base}");
header("Content-type: application/pdf");
$pdf = dirname(realpath($texFile)).DIRECTORY_SEPARATOR.$base.".pdf";
readfile($pdf);
?>
latex_template.php
\documentclass[12pt]{article}
\usepackage{lingmacros}
\usepackage{tree-dvips}
\begin{document}
\section*{Notes for My Paper}
Don't forget to include examples of topicalization.
They look like this:
{\small
\enumsentence{Topicalization from sentential subject:\\
\shortex{7}{a John$_i$ [a & kltukl & [el &
{\bf l-}oltoir & er & ngii$_i$ & a Mary]]}
{ & {\bf R-}clear & {\sc comp} &
{\bf IR}.{\sc 3s}-love & P & him & }
{John, (it's) clear that Mary loves (him).}}
}
\subsection*{How to handle topicalization}
I'll just assume a tree structure like (\ex{1}).
{\small
\enumsentence{Structure of A$'$ Projections:\\ [2ex]
\begin{tabular}[t]{cccc}
& \node{i}{CP}\\ [2ex]
\node{ii}{Spec} & &\node{iii}{C$'$}\\ [2ex]
&\node{iv}{C} & & \node{v}{SAgrP}
\end{tabular}
\nodeconnect{i}{ii}
\nodeconnect{i}{iii}
\nodeconnect{iii}{iv}
\nodeconnect{iii}{v}
}
}
\subsection*{Mood}
Mood changes when there is a topic, as well as when
there is WH-movement. \emph{Irrealis} is the mood when
there is a non-subject topic or WH-phrase in Comp.
\emph{Realis} is the mood when there is a subject topic
or WH-phrase.
\end{document}
Video: PHP, convert latex to pdf