Converting a string formula to TeX

  • Thread starter humberto.bortolossi
  • Start date
H

humberto.bortolossi

Greetings!

I would like to know if there is a java library (free or not) that
converts a string formula to TeX code. For instance, "(a + b)/2" is
converted to "\frac{a + b}{2}".

Thanks in advance, Humberto.
 
A

Adrian Petrescu

Greetings!

I would like to know if there is a java library (free or not) that
converts a string formula to TeX code. For instance, "(a + b)/2" is
converted to "\frac{a + b}{2}".

Thanks in advance, Humberto.

I looked around for "ascii2tex" or something like that, but couldn't
find anything. I very much doubt there's a Java library for it; but if
you could be much more specific about which transformations you'd like
to see happen, I could probably hack up a parser and code generator to
do what you'd need.

The idea intrigues me because it could be combined with things like IM
LaTeX plugins to make it even easier to converse in maths ;)

Cheers,
Adrian
 
R

Robert Dodier

I would like to know if there is a java library (free or not) that
converts a string formula to TeX code. For instance, "(a + b)/2" is
converted to "\frac{a + b}{2}".

One route could be to parse the string into MathML, or some
other tree structure, and then generate the TeX from that.

Something that's is pretty far out there, but which might be helpful
if you end up writing your own code & you need some inspiration,
is the TeX output system of the symbolic computation program,
Maxima. Input strings are parsed into Lisp S-expressions
(comparable to MathML representation) and then TeX is generated
by walking the parsed expression and generating TeX output for
each bit according to properties assigned to each atom.

If you find that someone has invented a TeX output
system for Java, I'd be interested to hear about it.

FWIW

Robert Dodier
 
R

Roedy Green

I would like to know if there is a java library (free or not) that
converts a string formula to TeX code. For instance, "(a + b)/2" is
converted to "\frac{a + b}{2}".

Another way of looking at your problem is you are inventing yet
another mathematical notation that you want to interconvert with Tex,
Maple, MathLab etc. Yours looks a bit like FORTRAN/Pascal/C++/Java.

So look for an expression parser or perhaps an entire language parser,
and strip it down for your needs. Once you get the parse tree you are
90% of the way there. You can spit out the information in any format
you please. There are some aesthetic decisions to make, so you might
need to make the process interactive where the user chooses between
visualised alternatives. You use that history to refine the automatic
rules.

see http://mindprod.com/jgloss/parser.html
 
S

Stefan Ram

I would like to know if there is a java library (free or not) that
converts a string formula to TeX code. For instance, "(a + b)/2" is
converted to "\frac{a + b}{2}".

»\frac« is used in LaTeX, but not in TeX.

»(a+b)/2« already /is/ TeX (one also might use »a+b\over 2« in TeX).

Many Java expressions and operators do not have a unique mathematical
correspondent. So careful interpretation by a human is often required.
 
S

Stefan Ram

Many Java expressions and operators do not have a unique mathematical
correspondent. So careful interpretation by a human is often required.

For example, after »int a, b;« the mathematical term that is
written as »\frac{a + b}{2}« in LaTeX would be a wrong
translation of the Java expression »( a + b )/2«.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top