manuels / texlive.js

Compiling LaTeX (TeX live) in your browser
http://manuels.github.com/texlive.js/
GNU General Public License v2.0
1.25k stars 139 forks source link

bibtex / biblatex / citation support #7

Open ghost opened 11 years ago

ghost commented 11 years ago

I've been toying with getting this to work with some of my existing latex documents thus far and have had good success with copying in the relevant files and pointing texlive.js to them. A major roadblock however is going to be BibTeX. I've been using latex-mk and the compile sequence is a nasty combination of latex bibtex latex bibtex etc. However I see there is such a thing as biblatex. I'm not familiar with it so I thought I would ask if you see any roadblocks. Obviously the biber backend cannot be used since it is written in perl, but it seems that it would provide basic citation support nevertheless.

Alternately, bibtex is also written in WEB, so could presumably compiled to javascript as well.

ghost commented 11 years ago

I had good luck with getting biblatex up and running, up to this point:

! Package biblatex Error: File 'pdftex-input-file.bbl' not created by biblatex.

(I had put pdftex-input-file.bbl/aux in the root directory and pointed texlive.js to them).

Investigating further.

ghost commented 11 years ago

I was able to get it working by manually running bibtex offline and then copying the bbl/aux files to pdftex-input-file.bbl/aux and adding those to texlive.js

As far as I can tell there is no way around compiling bibtex to javascript. Should be possible with the same pipeline you used for pdflatex.

manuels commented 11 years ago

When I find the time, I will port bibtex to javascript. (http://www.tex.ac.uk/tex-archive/bibliography/bibtex/base/)

ivanistheone commented 11 years ago

Hi manuels,

I am very interested in learning more about the LLVM-->js conversion process. I would love it if you write a blog post on that subject. I think you have hit on a very important technique.

I would be interested to try and do the BibTeX port if you give me some pointers and reading material.

ghost commented 11 years ago

I am also interested in working on it. Is it web2c followed by emscripten? I'm wondering if it's actually a simple insertion of the emscripten commands at the right point of the build. I haven't yet inspected the subset of textlive distributed here in detail (it might make this easier?), although I did get a fully copy last night for testing with bibtex. bibtex may require more of the distribution than is provided here.

manuels commented 11 years ago

Hi,

@ivanistheone, have a look at www.emscripten.org. There is a lot of information and also a link to a tutorial, I think.

@brianmingus, in theory it would only be

emconfigure ./configure
emmake make

instead of

./configure
make

But practically, you must modify a lot of Makefiles and also the configure script, compile and link files on your own and look for nasty bugs (like missing features in emscripten that to do not cause the compilation to fail but endup in strange errors during runtime)

ghost commented 11 years ago

I managed to compile bibutils to javascript. bibtex is next.. ;-)

manuels commented 11 years ago

That's great! If you need help with bibtex, send me a message (or ask on irc in #emscripten, there is really great support)

ghost commented 11 years ago

Thanks I will keep that in mind. At some point yesterday I had a nice fat bibtex.js that didn't run. I think I'm still a ways away from getting all the dependencies in there correctly.

ghost commented 11 years ago

node bibtex.js test This is BibTeX, Version 0.99d (Web2C 2012)

still having some issues with kpathsea that are preventing bibtex from seeing files I embedded.. let me know if you have any advice on that.

ghost commented 11 years ago

http://brianmingus.github.com/bibtex.js/website/

soon.. i hope. even my compiled binaries can't find plain.bst, so once i figure that out offline we are good to go.

manuels commented 11 years ago

This looks great already! I had a short look at your code and could also not debug that plain.bst issue, yet. As soon as your code works, I will link it in my README.md

manuels commented 11 years ago

you can try to compile it with emcc ... -s FS_LOG=1

ghost commented 11 years ago

Great I will try that. I made good progress by modifying src/texk/kpathsea/texmf.cnf, whose paths were being embedded in build/texk/kpathsea/paths.h, and removing 'nonesuch' instances from paths.h.

manuels commented 11 years ago

it's really strange that I didn't run into any problems with kpathsea for pdftex. I really don't know why kpathsea is an issue for bibtex

ghost commented 11 years ago

I tried to remove kpathsea as a bibtex dependency and found that it doesn't contain hard coded paths at all, all of its paths are relative to what kpathsea finds. The C code is also really hard to understand, and the javascript is almost impossible. At any rate I would guess that pdftex doesn't depend on the results of kpathsea as much.

ghost commented 11 years ago

The FS_LOG variable was very helpful. In general I think I have everything working. It will just take more experimentation to get the web worker up to this level.

$ node bibtex.sa.js test
This is BibTeX, Version 0.99d (Web2C 2012)
The top-level auxiliary file: test.aux
The style file: plain.bst
Database file #1: refs.bib

You can see what I'm doing to get rid of all of the errors. pdftex.js would benefit from some of this, at least to the extent that it silences some of the extraneous output. For instance, you need to embed a /bin/this.program to get rid of the the lstat(/bin) error, and including texmf.cnf gets rid of the huge spew of path error messages at the start.

The ls-R file might prove useful. I haven't tried it yet, but it may allow for setting the paths kpathsea searches in an online fashion.

cp -r ../../../demo_files/{test.aux,plain.bst,refs.bib,ls-R,texmf.cnf,texmf-config,texmf-var,texmf,texmf-local,texmf-dist,bin} .
env EMCC_DEBUG=1 emcc -o bibtex.sa.js bibtex.o  lib/lib.a ../kpathsea/.libs/libkpathsea.a --embed-file test.aux --embed-file plain.bst --embed-file refs.bib --embed-file ls-R --embed-file texmf.cnf --embed-file texmf-var  --embed-file texmf --embed-file texmf-local --embed-file texmf-dist --embed-file bin  # -s FS_LOG=1                                                                                                                                                                                                                              
sed -ir 's/_putc/_fputc/' bibtex.sa.js
node bibtex.sa.js test
ghost commented 11 years ago

Here we go: http://brianmingus.github.com/bibtex.js/website/

manuels commented 11 years ago

Great work! I'll have a look at your suggestions for texlive.js. sounds good.