Skip to content
Engelbert Niehaus edited this page Oct 8, 2019 · 18 revisions

Welcome to the texlive.js wiki!

Demo

If you want to check, how you can compile a LaTeX source document in a browser please checkout the

FAQ

How can I build it myself?

Just install Emscripten, checkout this project using Git and run make.

Adding custom files/images

If you want to add a file (for example an image) to your latex document, you can add these files to the virtual filesystem of the LaTeX compiler. Note that this filesystem is always UNIX-like, even if the browser runs on Windows. So use slashes (/) instead of backslashes (\). Adding files can be achieved by using the wrappers for emscripten's Filesystem API

For example, the LaTeX command

\includegraphics{/images/my_kitten}

will try to include an image file named mykitten.jpg in the directory /images. This file must be mapped to an URL. Say, the compiler should automatically download the image /images/mykitten.jpg from the URL http://www.kittens.net/cute_kitten2312.jpg. Then you must call these commands before invoking pdftex.compile():

pdftex.FS_createPath('/', 'images', /*canRead=*/true, /*canWrite=*/true).then(function() {
  pdftex.FS_createLazyFile('/images', 'mykitten.jpg', 'http://www.kittens.net/cute_kitten2312.jpg', /*canRead=*/true, /*canWrite=*/true).then(function() {
    pdftex.compile(...);
  });
});

As you can see, these wrapper functions return promises. Note that the same-origin policy applies.

The state of the virtual filesystem is only saved in memory and will be reset for each PDFTeX instance (and after the page is reloaded, of course).

What are these binary files?

The LaTeX compiler PDFTeX is written using WEB. When compiling PDFTeX the Makefile would originally generate some tools and use them (ctangle, ctangleboot, fixwrites, splitup, tangle, tangleboot, tie and web2c) to convert the WEB code to C. Since we are generating javascript instead binaries, we need these binary copies of these tools.

I'm getting an error message like "! LaTeX Error: File '...' not found."

Looks like the module you want to use is not installed. To keep the filesize low, TeXliveJS only installs the basic scheme of TeXlive. Checkout the ./texlive: section of the Makefile and the TeXlive documentation to figure out how to install specific modules and write a HOWTO to this page where you explain how you did it (because I could not figure out how to do this). You could also use the the full scheme.

HOWTO

  • Grab .tds.zip of package from CTAN
  • Unzip the .tds.zip package to ./texlive/texmf-dist/
  • Update ./texlive.lst and ./texlive/texmf-dist/ls-R by running the following (I have this saved as ./updatepackages.sh)
#! /bin/bash
find texlive -type d -exec echo {}/. \; | sed 's/^texlive//g' >texlive.lst
find texlive -type f | sed 's/^texlive//g' >>texlive.lst
cd texlive/texmf-dist/
ls -R -1 > ls-R

I'm getting the error message "Cannot enlarge memory arrays in asm.js."

Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 67108864, or (2) set Module.TOTAL_MEMORY before the program runs.

Option 1) You used an instance of PDFTeX twice. E.g. you did the following:

var pdftex = new PDFTeX();
pdftex.compile();
pdftex.compile();

instead create a new instance each time you want to compile:

var pdftex = new PDFTeX();
pdftex.compile();
pdftex = new PDFTeX();
pdftex.compile();

Option 2) Your LaTeX document requires a lot of memory. You can adjust the memory PDFTeX will use by calling pdftex.set_TOTAL_MEMORY(memsize_in_bytes). This call will return a promise.