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:

Wolfram Research (1988), ToExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/ToExpression.html (updated 2004).

Text

Wolfram Research (1988), ToExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/ToExpression.html (updated 2004).

CMS

Wolfram Language. 1988. "ToExpression." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2004. https://reference.wolfram.com/language/ref/ToExpression.html.

APA

Wolfram Language. (1988). ToExpression. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ToExpression.html

BibTeX

@misc{reference.wolfram_2024_toexpression, author="Wolfram Research", title="{ToExpression}", year="2004", howpublished="\url{https://reference.wolfram.com/language/ref/ToExpression.html}", note=[Accessed: 17-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_toexpression, organization={Wolfram Research}, title={ToExpression}, year={2004}, url={https://reference.wolfram.com/language/ref/ToExpression.html}, note=[Accessed: 17-November-2024 ]}