ToExpression

ToExpression[input]

gives the expression obtained by interpreting strings or boxes as Wolfram Language input.

ToExpression[input,form]

uses interpretation rules corresponding to the specified form.

ToExpression[input,form,h]

wraps the head h around the expression produced before evaluating it.

Details

Examples

open allclose all

Basic Examples  (5)

Convert a string to an expression, and evaluate the expression:

Interpret a TraditionalForm string:

Convert boxes to Wolfram Language input:

Convert MathML strings to expressions:

Convert TAdjustmentBox[E, BoxBaselineShift -> 0.5, BoxMargins -> {{-0.3, 0}, {0, 0}}]X strings to expressions:

Scope  (2)

Convert a string to an expression using TraditionalForm rules:

Convert the same string using StandardForm and InputForm rules:

Convert and evaluate a string representing multiple lines of code:

Generalizations & Extensions  (1)

Apply the head Hold to prevent evaluation:

Properties & Relations  (2)

ToExpression evaluates the expression, while MakeExpression does not:

Display an InterpretationBox:

The expression is the second argument of the InterpretationBox:

Possible Issues  (1)

Input containing invalid or incomplete syntax cannot be converted to expressions:

Introduced in 1988
 (1.0)
 |
Updated in 1996
 (3.0)
2003
 (5.0)
2004
 (5.1)