Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a TeX API for C++?

I want to preview TeX formulas in my User Interface. After a long time searching, it seems to me that there is no other possibility than

  • write the formula into a .tex file
  • call tex with system() and write a dvi file
  • call e.g. dvipng with system() and write a png file
  • load this file into the GUI
  • clean up(erase all these files).

I think that the performance of this way doing it is not a problem, since there are only formulas to render and not whole documents. But setting up the environment automatically for the TeX system seems to be a bigger problem. So, is there a possibility to include TeX as an API in my program? Thanks a lot!

like image 998
nobbi Avatar asked Apr 30 '09 09:04

nobbi


4 Answers

There's a C API for TeX called MimeTeX but the resulting image is... not a nice as it could be.

If you're OK with Java, there's JLatexMath

And if you'd like a WPF version, one is under development at WPFMath

like image 164
Scott Weinstein Avatar answered Oct 11 '22 01:10

Scott Weinstein


Couldn't you encapsulate those steps in a single shell script (i.e. which takes the formula and png filename as arguments)? The script could then also handle setting up the environment for TeX. Your program just calls the script with the system() call.

like image 30
jon-hanson Avatar answered Oct 11 '22 02:10

jon-hanson


I'm not sure, but think MathType's Component will overkill.

Also have a look at sideshare and see flash video to get more information about sitmo, mathMagig, Edoboard and their API tools.

good lucks.

like image 28
sorush-r Avatar answered Oct 11 '22 02:10

sorush-r


For Edoboard and Tutorsbox.com we do the following:

Keep a blacklist of LaTeX commands to avoid:

TEX_BLACKLIST = ["\\def", "\\let", "\\futurelet",
    "\\newcommand", "\\renewcommand", "\\else", "\\fi", "\\write",
    "\\input", "\\include", "\\chardef", "\\catcode", "\\makeatletter",
    "\\noexpand", "\\toksdef", "\\every", "\\errhelp", "\\errorstopmode",
    "\\scrollmode", "\\nonstopmode", "\\batchmode", "\\read", "\\csname",
    "\\newhelp", "\\relax", "\\afterground", "\\afterassignment",
    "\\expandafter", "\\noexpand", "\\special", "\\command", "\\loop",
    "\\repeat", "\\toks", "\\output", "\\line", "\\mathcode", "\\name",
    "\\item", "\\section", "\\mbox", "\\DeclareRobustCommand", "\\[", "\\]"];

We then do system call "latex and textopng".

That as an API REST plus some caching and here you go :) As an upgrade we will soon convert those LaTeX images as SVG.

like image 34
coulix Avatar answered Oct 11 '22 02:10

coulix