Giter Site home page Giter Site logo

originalls / web2js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kisonecat/web2js

0.0 0.0 1.0 949 KB

Convert TeX's pascal to javascript

License: Other

Shell 7.70% JavaScript 18.41% Perl 8.29% C 0.24% Prolog 0.25% OpenEdge ABL 1.99% TeX 20.71% xBase 39.32% Makefile 0.63% Yacc 2.09% Roff 0.37%

web2js's Introduction

web2js

This is a Pascal compiler that targets WebAssembly, designed specifically to compile TeX so it can be run inside the browser. More specifically, this repository includes a TeX engine called jsTeX which is like LuaTeX but instead of embedding Lua it embeds JavaScript.

Importantly, the jsTeX engine passes the trip tests which you can verify by running make test.

There is a live demo and a short overview available at

J. Fowler, Both TEX and DVI viewers inside the web browser, TUGboat, Volume 40 (2019), No. 1.

Prerequisites

This projects depends on NodeJS for executing the javascript. To post-process the WebAssembly, you will need wasm-opt on your path.

You will need a full TeX installation (e.g., TeX Live) with access to kpsewhich in order that library.js can find the necessary TeX files. You also need tie and tangle to turn the WEB sources into Pascal which can be fed to the compiler.

The contents of the texk, triptrap, and etexdir subdirectories were copied from tug.org via

mkdir texk
rsync -a --delete --exclude=.svn tug.org::tldevsrc/Build/source/texk/web2c/tex.web texk
rsync -a --delete --exclude=.svn tug.org::tldevsrc/Build/source/texk/web2c/triptrap .
rsync -a --delete --exclude=.svn tug.org::tldevsrc/Build/source/texk/web2c/etexdir .

Getting started

After cloning this repository, run npm install.

Then run

make core.dump

to apply the changefiles, compile the resulting Pascal source to WebAssembly, and run initex.js to produce a format file and its corresponding memory dump.

Then you can run TeX on a file called sample.tex with

node tex.js sample.tex

jsTeX

The main innovation of jsTeX is \directjs primitive similar to LuaTeX's \directlua. For example,

\documentclass[12pt]{article}

\newcommand{\cubeit}[1]{\directjs{
  tex.print('$');
  tex.print(`#1^3 = ${#1*#1*#1}`);
  tex.print('$');
}}

\begin{document}

Let's multiply eight by eight by eight.  \cubeit{8}

\end{document}

Inside \directjs, the JavaScript function tex.print can be used to emit strings back into TeX for further processing.

web2js's People

Contributors

kisonecat avatar

Forkers

niqhtfire

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.