I looked at similar questions, but could not find an answer.
I need to convert Latex that represent pure mathematical expressions generated by Maple to Mathematica. I do not want to actually use these expressions in Mathematica. But just to convert them to Mathematica syntax, then save them back as plain strings for other purposes.
Some of the Maple expressions (in Latex) do not map to same Mathematical functions as defined by Mathematica.
But that is OK, I do not need to use them any way in Mathematica. But the problem is when I use r=ToExpression[s, TeXForm]
, where s
is the Latex string generated by Maple, depending on s
, Mathematica can complain if the generated expression is not understood by Mathematica.
Even though I just want to do ToString[InpuForm[r]]
right after that, and save r
as string for other purposes.
But to go from Latex to string, I have to go through ToExpression
first.
I do not know how to use Hold or Inactive or such to do this.
Is there a way to do this conversion without this error being generated? Here is an example
s="-{{\\rm e}^{2}}{\\it Ei} \\left( 1,-2t+2 \\right)";(*generated by Maple*)
r=ToExpression[s,TeXForm];
ToString[InputForm[r]]
The above is all what I need. Even if it is not valid Mathematica command, it is ok.
Most of the Maple latex output is converted OK, since these are just pure mathematical expressions (do not contain actual Maple commands or such), so about 90% of them cause no problem (they are all antiderivatives results from integration test).
Version 11.1
ps., I looked at converting-expression-into-string-without-evaluating-it but could not make it work for the above example. I still get the error message.
ps. Currently I do the following, as temporary (may be permanent?) solution
s="-{{\\rm e}^{2}}{\\it Ei} \\left( 1,-2t+2 \\right)";
Quiet[r=ToExpression[s,TeXForm]]; (*suppress error message*)
ToString[InputForm[r]]
Quiet
for now. Since as I said, I am not going to use the result. I tried your method, but I must did something wrong, and could not understand how to use it. I can close this question if it is not useful for others. $\endgroup$ToExpression
but wrap it in aHold
so it doesn't evaluate. Then you'd do like:Replace[MakeExpression[s_],HoldComplete[r_]:>ToString[Unevaluated[r],InputForm
. Up to you over whether you think it's worth leaving open or not, I think. $\endgroup$MakeExpression
andToHeldExpression
do not acceptTeXForm
as the second argument. $\endgroup$