I know
{1, 1} // Apply[Defer@*Plus]
can return
1+1
But if I want hold the form from TeXForm,what should I do?
ToExpression["1+1", TeXForm]
will return 2 . But I don't know how to Defer the Plus
.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI know
{1, 1} // Apply[Defer@*Plus]
can return
1+1
But if I want hold the form from TeXForm,what should I do?
ToExpression["1+1", TeXForm]
will return 2 . But I don't know how to Defer the Plus
.
Use the 3rd argument of ToExpression
.
ToExpression["1+1", TeXForm, Hold]
If the TeX string is coming from untrusted sources, it is better to use HoldComplete
for complete safety. Try this: ToExpression["\\text{Evaluate}(\\text{Print}(gotcha))", TeXForm, Defer]
.
Every function that extracts an expression that might evaluate has some facilities to keep the result held.
ToExpression["\\frac{1}{\\sqrt{5}}+\\frac{1}{\\sqrt{5}}",TeXForm,Hold]
will return
(* Hold[1/Sqrt[5] + 1/Sqrt[5]] *)
which I assume is what you need?
Another way:(from QQ: 2716697201)
ToExpression["1+1", TeXForm] // Trace // #[[2]] &
whose FullForm is
HoldForm[Plus[1,1]]
1+1//HoldForm//TeXForm
$\endgroup$