Coder Social home page Coder Social logo

relaxar / pdftex.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dmonad/pdftex.js

0.0 1.0 0.0 25.16 MB

Compile LaTeX directly in your browser!

Home Page: https://dmonad.github.io/pdftex.js

License: Other

Makefile 67.29% HTML 9.50% JavaScript 23.20%

pdftex.js's Introduction

pdftex.js

A pure javascript port of pdftex which compiles latex directly in your browser! - Demo

pdftex.js compiles latex code at near-native speed, and does not require a server. pdftex.js ships with custom service worker for caching dependencies.

Get Started

Install dependencies using bower, or download a GitHub release.

$ bower install --save pdftex.js

Include the main js file (also works well with module loaders)

<script src="bower_components/pdftex.js/pdftex.js"></script>

In order to locate the pdftex-worker you must set the location of the pdftex.js directory.

pdftex.setPdftexDir('/bower_components/pdftex.js/')

The texlive distribution is rather big, so you should use service worker to cache it. pdftex.js ships with an optimized (it's actually not difficult) service worker to cache the texlive distribution. I recommend to use it event if you are already implemented a service worker for your project (you can run them in parallel).

if ('serviceWorker' in navigator) {
  navigator.serviceWorker
  .register(
    './bower_components/pdftex.js/pdftex-service-worker.js',
    { scope: '/bower_components/pdftex.js/' }
  ).then(function (reg) {
    // registration worked
    console.log(
      'Pdftex service worker registration succeeded. Scope is ' +
      reg.scope
    )
    // Optionally you can preload the worker and the resources for a faster
    // initial compilation. You should only do that if the service worker is
    // activated
    if (reg.active != null) {
      pdftex.preload()
    }
  }).catch(function (error) {
    // registration failed
    console.log('Pdftex service worker registration failed with ' + error)
  })
}

Start a process

var latexSource = '\documentclass[12pt]{article} ..'
var compile = pdftex(latexSource)
compile.on('finish', function (event) {
  if (event.success) {
    console.log('Url to compiled latex document: ', event.url)
  }
})
compile.on('log', function (message) {
  console.log(message)
})

compile.on('err', function (message) {
  console.error(message)
})

The source code for the demo is also a good point to start

API

pdftex(latexSource: String, options : Object) : PdfTeXCompilation

Starts a compilation process. Calling it will terminate the previous compilation. Options may have the following properties:

  • debug : Boolean - If true, logs all messages to the console
PdfTeXCompilation

This is returned when calling pdftex(latexSource). Has the following methods:

  • on(eventName : String, eventHandler : Function) - Possible values for eventName:
    • 'log'
    • 'err'
    • 'finish' - Called when the compilation ends (succes or failure)
pdftex.preload()

Preload the worker and the resources for a faster initial compilation.

pdftex.setPdftexDir(dir : String)

Set the path to the pdftex.js directory. This is required in order to determine the location of the pdftex-worker.

Contribution

This project wouldn't be possible without [emscripten] (https://github.com/kripken/emscripten). @manuels did all the pioneering work on porting pdftex. [His project] (https://github.com/manuels/texlive.js) was very helpful in figuring out how emscripten works.

pdftex.js's People

Contributors

dmonad avatar

Watchers

 avatar

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.