Code Monkey home page Code Monkey logo

node-latex's Introduction

node-latex

Simple LaTeX wrapper for node.js

Installation

First, you need to install latex. On any Debian based system, you can do this with the following command:

sudo apt-get install texlive

On OS X, you will need to install MacPorts first. Once that is set up, you can then do:

sudo port install texlive

For Windows, you can try using cygwin though I have not tested this.

Once you have a working version of latex, you can install node-latex using the following command:

npm install latex

Usage

Here is an example of how to use the library in one line:

require("latex")([
  "\\documentclass{article}",
  "\\begin{document}",
  "hello world",
  "\\end{document}"
]).pipe(process.stdout)

This will spit out a formatted PDF article to stdout that says "hello world". The result of calling the function is returned as a stream and can be processed using other tools. If you want to convert the result into an image or pdf, you can use graphics magic.

require("latex")(doc[, options])

The only exported function from node-latex is a function that takes as input a raw LaTeX document and returns a stream representing the document state. The type of doc must be one of the following:

  • A string
  • A Buffer
  • An array of strings and/or Buffers
  • A readable Stream

In addition, you can also specify the following additional parameters via the options struct:

  • command: An optional override for the latex command. By default calls latex.
  • format: Either "pdf" or "dvi". By default returns a pdf.

The function returns a readable Stream object representing a LaTeX encoded document in either PDF or DVI format. If there were errors in the syntax of the document, they will be raised as errors on this Stream object.

Credits

(c) 2013 Mikola Lysenko. MIT License

node-latex's People

Contributors

mikolalysenko avatar mrkev avatar saadq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-latex's Issues

format parameter

What is the reason for the format parameter? It should be enough to choose the TeX compiler (latex, pdflatex, xelatex, lualatex, etc.).
...Rolf

Missing latex error

I got the following error when trying to run a script.

$ node index.js
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn ENOENT
    at exports._errnoException (util.js:742:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1028:32)
    at child_process.js:1109:20
    at process._tickCallback (node.js:343:11)

After some digging I found out it was because something went wrong with my latex installation, and so there was no latex application that could be found. IMO this error should be better handled. I can see an error like this being fairly common: handling it to log a No latex installation found or something would be greatly appreciated!

Graphics rendering

Hi guys,

I'm trying to use LaTeX's graphicx package to include a JPEG image in a template, but the package doesn't seem to render that image. I might be omitting something of course, but I have included my code below for your consideration.

`var fs = require('fs');

var input = process.argv[2];
var output = process.argv[3];
var trog = [];

fs.readFile(input, 'utf8', function (err, data) {
if (err) throw err;
console.log('>>> Tex file imported.');
trog.push(data);
var options = { 'command': 'pdflatex' };
require('latex')(trog, options).pipe(fs.createWriteStream(output));
console.log('>>> Tex file built.');
});`

My tex file is as follows:

\documentclass{article} \usepackage{graphicx} \begin{document} \begin{center} \includegraphics[scale=1]{logo.jpg} \newline \Large NOTICE \end{center} \sffamily Account Number: \textit{12345678} \newline \newline MR A TEST \newline 2 THE STREET \newline FARNBERRY \newline CLOUD TOWN \newline GU15 3AA \newline \newline Amount: 1078.52 \newline Financial Year: \textbf{2017} \newline \newline \small{Footer text} \end{document}

If I run compile this tex file from the terminal using the command pdflatex the image renders fine. Are you able to help me in rendering the included image please?

Thanks.

Handle multi-pass documents

It looks like this library can't render documents that need to be run through latex multiple times (many of them).

latexmx seems to be a LaTeX wrapper that does this, but it needs specific command-line arguments.

update npm package

There is an old version of library in npm. For example, there is no errors messages when latex is not installed.

temporary directory clean up

The current version of "node-latex" uses version 0.5.x of the module "temp". This version automatically removed the tempory directory at exit (maybe your explicit remove calls aren't necessary?). Sometimes for debugging it would be helpful if the temporary directory is not deleted at the end. I suggest an additional parameter "keep" for the options object which defaults to false. In the current version of "temp" "track()" or "cleanup()" must be called explicitly for clean up. Thanks.

...Rolf

Why use .log and .tex external files?

This will not work as long as we'll want to produce 2 LaTeX simultaneously - as well as it needlessly accesses the filesystem (which may fail for whatever reasons).

No "done" notification

User does not really know if the processing has been done correctly - only gets notified if an error occurs. A notification of "ready" after LaTeX has completed its processing would be handy.

Usage with .cls?

Hi, thanks for writing this module. Here is an example of how I am using this:

var fs = require('fs');
var latex = require('latex');

var string = getTexDocument(); // Returns a string of .tex code
var writeStream = fs.createWriteStream('doc.pdf');
latex(string).pipe(writeStream);

This works for most situations, but what do I need to do if the string is a TeX document that wants to use a CLS file? Is there something I can do to pass CLS code as a string as well to make this work? Thanks!

temporary directory

As the the temporary directory you have /tmp. I think a better choice would be the content of process.env['TMPDIR'] with fall back to /tmp and additional it should be possible to set the temporary directory in the options object.
...Rolf

Referenced relative files not resolved

Since the latex is compiled inside a temporary directory, latex commands that reference relative files are not resolved. Examples are include and input.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.