GeneralBuilding LaTeX Documents from PHP

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
OsakaWebbie
Posts: 9
Joined: Thu Apr 19, 2012 2:56 am

Building LaTeX Documents from PHP

Post by OsakaWebbie »

I'm using PHP to build a .tex file and then run uplatex (like latex but for Unicode Japanese) and then dvipdfmx to create a PDF file from database data.

Generating the tex file is working beautifully - the resulting /tmp/mytempname.tex file can by run from the command line, while in the /tmp directory, with "uplatex mytempfile" and the appropriate aux, div, and log files all appear.

But with my PHP code:

Code: Select all

exec("cd /tmp;uplatex -interaction=nonstopmode --output-directory=/tmp /tmp/mytempname", $output, $return);
if (!is_file("/tmp/mytempname.dvi")) {
  die("Error processing '/tmp/mytempname.tex':<br /><br /><pre>".print_r($output,TRUE)."</pre>");
}
Something is wrong, but the problem is that I'm blind to what is happening - no aux or dvi files are created, $output is empty, and there is no mytempname.log file anywhere on the system.

The tex file is okay - from the command line, while in the /tmp directory, I can run "uplatex mytempfile" and get a dvi file with no errors.

The /tmp directory's permissions are "drwxrwxrwt" (sticky bit set) - the code is able to create the tex file, so presumably there should be no problems creating the dvi files and such. I also tried including 'exec("cd /tmp;touch test.txt");' in my code, and that works fine.

I don't expect you to debug my PHP code - I know this is a LaTeX forum. But should I use different command line options for uplatex (don't worry about the "up" part - the options should be the same as for latex) to get some sort of error output or visibility?
Last edited by localghost on Mon May 07, 2012 6:16 pm, edited 4 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Re: Building LaTeX Documents from PHP

Post by nlct »

I can't give you much help, but I usually use "batchmode" rather than "nonstopmode" when spawning a latex process from another application. I've not used php, but I know latex's verbose output can cause a problem running the process from a java app (but maybe that's just a problem with java). You could also try searching for a file called texput.log, which is the name of the transcript file when there's no jobname set.

Regards
Nicola Talbot
User avatar
OsakaWebbie
Posts: 9
Joined: Thu Apr 19, 2012 2:56 am

Re: Building LaTeX Documents from PHP

Post by OsakaWebbie »

Thanks, Nicola. I found two files called texput.log, and only the one in /root/ was dated today. But it's a bit spooky, because the timestamp is while I was away from my computer for several hours!

Anyway, haunted servers aside, after quite a bit more research I found out what the problem was - the user that the PHP process is running as does not have the TexLive binary directory in its PATH! I had forgotten that I had used the root user's .bashrc file to add that directory to the front of $PATH. I don't know how to add a directory to the path of a user that doesn't even have a login shell (or preferably for all users in one shot), but I solved it by spelling out the path to the uplatex and dvipdfmx commands in my code.
Post Reply