tags:

views:

57

answers:

1

I'm new to node.js but I think It could be good for an asynchronous latex compile engine.

In other words I'd like to know if could be possible, and how, to compile a document via node.js and pdflatex. The remote application would send the document as a JSON data structure, toghether with a template name for the end document layout.

The node.js will handle the compilation in pdf, taking the template from the file system.

Do you know if something similar, already exist?

A: 

You can spawn own child processes and thus also start latex processing. By registering appropriate listeners, you can detect the process completition or failure output:

var sys   = require('sys'),
    spawn = require('child_process').spawn,
    pdflatex    = spawn('pdflatex', ['-output-directory', '/target/dir/','input.tex']);


pdflatex.on('exit', function (code) {
  console.log('child process exited with code ' + code);
});

EDIT: For creating the intermediary latex file using the provided data, I'd suggest to use a node.js template engine like mu/mustache.

So you could then pump the chunks of the template engine process as stdin to your spawned pdflatex process.

PartlyCloudy
wonderful! THX.
microspino