Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is It possible to compile a latex document via node.js?

Tags:

node.js

latex

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?

like image 406
microspino Avatar asked Aug 14 '10 10:08

microspino


People also ask

How do I compile a LaTeX file?

In order to compile a LaTeX file, simply press \ll while editing the file. This runs latex on the current file and displays the errors in a |quickfix-window| below the file being edited.

What does node JS compile to?

Two of the most commonly used packages used to compile JavaScript files into executables are: nexe: It is a simple command-line utility that compiles your Node. js application into a single executable file. By default, it converts it into a Windows executable.


1 Answers

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.

like image 160
b_erb Avatar answered Nov 13 '22 16:11

b_erb