michael-brade / LaTeX.js

JavaScript LaTeX to HTML5 translator
https://latex.js.org
MIT License
736 stars 58 forks source link

more packages? #109

Open mr-hyperboloid opened 4 years ago

mr-hyperboloid commented 4 years ago

Hey, this project is unique! I am using the compiled docs directory as a basis for my project because it's easier. Can you please tell me how can I add more (latex) packages without recompiling? Is this possible at all?

Thank you for the answers!

michael-brade commented 4 years ago

Hi! Yeah, sorry about that... it is work in progress. I am not sure yet how you could be doing it with the docs directory, but if you are using the CLI, all you need is a subfolder called packages with <package>.js files in it. Then the \usepackage{<package>} macro should pick it up. I haven't tested it yet since we switched to rollup, and rollup added a nice feature for dynamic includes lately. So I will improve it soon.

mr-hyperboloid commented 4 years ago

Thank you very much for your answer! I have looked into the "packages" dir, but it seems that the files there are of some unusual extension ".ls" as well as their format inside only resembles LaTeX. I am not really experienced into the neither the realm of js nor tex, but I wanted to use the package amsmath, which can be downloaded from CTAN in a zip file containing ".ins", ".dtx", ".tex" and other file formats which seem to be written in ordinary TeX. Is there some kind of translator between the formats or can the clean TeX be pasted and used like a native LaTeX.js package? How do you port a LaTeX package (a directory containing ins/dtx/tex files) to LaTeX.js (ls files)?

michael-brade commented 4 years ago

Actually, .ls is LiveScript, which transpiles to JavaScript. So you could also use plain .js files, or any other language that transpiles to JavaScript. However, if you don't know JavaScript, then it's going to be a big challenge ;-) Those files in packages and classes have to be JavaScript because they have to use the API of LaTeX.js. And no, I don't have a translator from TeX to LaTeX.js/JavaScript, every single LaTeX macro has to be rewritten in JavaScript individually--that's the work we have to do in creating this project :-)

Now, the good news is: a lot of amsmath is probably already working because when switching to math mode in LaTeX.js, you are using KaTeX, and that is emulating amsmath. The bad news is that environments are not supported yet (see https://github.com/KaTeX/KaTeX/issues/2042). As soon as they are, I can support them in LaTeX.js as well.