tags:

views:

291

answers:

2

What is the best library to do this?

I am surprised this question has not been asked before. Is it impossible? That would be surprising too.

Thanks for your help.

A: 

It is not impossible to do this. (Java is Turing complete ...). But it is (IMO) unlikely that you will find an existing library to process TeX / LaTeX in Java, and impractical for you to implement this yourself.

I'd look for command-line applications that convert TeX / LaTeX to something (e.g. pdf or postscript), and then that something to png page images. Then I'd create a wrapper script that combines the applications as required, and use Process.exec(...) to run the script.

EDIT

If you are just wanting to render LaTeX mathematical equations, try the options suggested by the answers linked by @RD1.

Stephen C
+1  A: 

http://stackoverflow.com/questions/456002/displaying-fancy-equations-with-java http://stackoverflow.com/questions/556060/generate-images-for-formulas-in-java

Roughly I'd say your options are:

  • Use one of the Java libraries mentioned for the first question, if they suit the your application and the form of the Latex (e.g., is it whole documents with macros, style files and BibTex or just single equations).
  • Execute texvc as an external program (as Wikipedia/MediaWiki does), or link to the OCaml code via JNI.

EDIT

As Stephen C said, these are only for fragments of Latex. If you want to convert a full Latex document, you'll need a full Latex implementation - none of the above. And those need to be somewhat large and complex because they are full "development environments" for typesetting documents by writing Latex code. If this is what you need, you don't have much choice but to use one of the standard Latex distributions via exec (and I guess fail gracefully if the Latex interpreter reports errors in the Latex code).

That said, there have been at least a couple of attempts to port Latex to Java (including two called "JavaTex"). Most likely these aren't in a state that would suit you - but see the summary of some recent attempts to judge for yourself:

http://www.monperrus.net/martin/running+tex+on+a+java+virtual+machine

RD1