I know

{1, 1} // Apply[Defer@*Plus]

can return


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.

  • $\begingroup$ How about 1+1//HoldForm//TeXForm $\endgroup$ – Bill Watts Apr 7 at 7:25

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.

  • Extract has a similar 3rd argument
  • LinkRead has a similar 2nd argument
  • Read has Read[file, Hold[Expression]]
  • etc.
| improve this answer | |

will return

(* Hold[1/Sqrt[5] + 1/Sqrt[5]] *)

which I assume is what you need?

| improve this answer | |
  • 1
    $\begingroup$ 16 second difference :-) $\endgroup$ – Szabolcs Apr 7 at 7:47

Another way:(from QQ: 2716697201)

ToExpression["1+1", TeXForm] // Trace // #[[2]] &

whose FullForm is


| improve this answer | |
  • 2
    $\begingroup$ You really should not do this though. $\endgroup$ – Szabolcs Apr 7 at 7:42
  • 1
    $\begingroup$ I agree. That's pretty inventive, but it's a dark, dark art. $\endgroup$ – Victor K. Apr 7 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.