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.
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
- form can be InputForm, StandardForm, TeXForm, TraditionalForm, or MathMLForm.
- ToExpression["string"] uses InputForm interpretation rules.
- ToExpression[boxes] uses StandardForm interpretation rules.
- ToExpression prints a message and returns $Failed if it finds a syntax error. ToExpression does not call $SyntaxHandler. »
- The input given in ToExpression can correspond to multiple Wolfram Language expressions. ToExpression processes each one in turn, just like Get. »
- ToExpression[input,form,Hold] can be used to convert input to an expression, but with the expression wrapped in Hold to prevent evaluation. »
- ToExpression uses any relevant definitions given for MakeExpression.
Examples
open all close allBasic Examples (5)
Convert a string to an expression, and evaluate the expression:
ToExpression["1+1"]Interpret a TraditionalForm string:
ToExpression["sin(x)", TraditionalForm]Convert boxes to Wolfram Language input:
ToExpression[RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}]]Convert MathML strings to expressions:
ToExpression["<math><msup><mi>x</mi><mn>2</mn></msup></math>", MathMLForm]Convert
strings to expressions:
ToExpression["\\frac{x}{\\sqrt{5}}", TeXForm]Scope (2)
Convert a string to an expression using TraditionalForm rules:
ToExpression["sin(x)", TraditionalForm]Convert the same string using StandardForm and InputForm rules:
ToExpression["sin(x)", StandardForm]ToExpression["sin(x)", InputForm]Convert and evaluate a string representing multiple lines of code:
ToExpression["a=3
b=2
a^2+b^3"]Generalizations & Extensions (1)
Apply the head Hold to prevent evaluation:
ToExpression["1+1", StandardForm, Hold]Properties & Relations (2)
ToExpression evaluates the expression, while MakeExpression does not:
ToExpression[FractionBox["25", "100"], StandardForm]MakeExpression[FractionBox["25", "100"], StandardForm]Display an InterpretationBox:
DisplayForm[InterpretationBox[SuperscriptBox["x", "2"], var]]The expression is the second argument of the InterpretationBox:
ToExpression[%]See Also
Interpreter Symbol MakeExpression ToString ToBoxes SyntaxQ SyntaxLength Read Get ImportString
Function Repository: StringTemplateInput ConvertStringsToSymbols
Tech Notes
History
Introduced in 1988 (1.0) | Updated in 1996 (3.0) ▪ 2003 (5.0) ▪ 2004 (5.1)
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_2026_toexpression, author="Wolfram Research", title="{ToExpression}", year="2004", howpublished="\url{https://reference.wolfram.com/language/ref/ToExpression.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_toexpression, organization={Wolfram Research}, title={ToExpression}, year={2004}, url={https://reference.wolfram.com/language/ref/ToExpression.html}, note=[Accessed: 12-June-2026]}