The Interpretation of Textual Forms

Converting from strings or boxes to expressions.

This takes a string and interprets it as an expression:

ToExpression["2 + 3 + x/y"]

Here is the box structure corresponding to the textual form of an expression in (RefLink[StandardForm, paclet:ref/StandardForm]):

ToBoxes[2+x^2,StandardForm]

(RefLink[ToExpression, paclet:ref/ToExpression]) interprets this box structure and yields the original expression again:

ToExpression[%]

In any Wolfram System session, the Wolfram System is always effectively using (RefLink[ToExpression, paclet:ref/ToExpression]) to interpret the textual form of your input as an actual expression to evaluate.

If you use the notebook front end for the Wolfram System, then the interpretation only takes place when the contents of a cell are sent to the kernel, say for evaluation. This means that within a notebook there is no need for the textual forms you set up to correspond to meaningful Wolfram System expressions; this is only necessary if you want to send these forms to the kernel.

The hierarchy of forms for standard Wolfram System input.

Here is an expression entered in (RefLink[FullForm, paclet:ref/FullForm]):

Plus[1,Power[x,2]]

Here is the same expression entered in (RefLink[InputForm, paclet:ref/InputForm]):

1+x^2

And here is the expression entered in (RefLink[StandardForm, paclet:ref/StandardForm]):

1+(x^2)

Built into the Wolfram System is a collection of standard rules for use by (RefLink[ToExpression, paclet:ref/ToExpression]) in converting textual forms to expressions.

These rules define the grammar of the Wolfram System. They state, for example, that x+y should be interpreted as (RefLink[Plus, paclet:ref/Plus])[x,y], and that (x^y) should be interpreted as (RefLink[Power, paclet:ref/Power])[x,y]. If the input you give is in (RefLink[FullForm, paclet:ref/FullForm]), then the rules for interpretation are very straightforward: every expression consists just of a head followed by a sequence of elements enclosed in brackets. The rules for (RefLink[InputForm, paclet:ref/InputForm]) are slightly more sophisticated: they allow operators such as +, =, and ->, and understand the meaning of expressions where these operators appear between operands. (RefLink[StandardForm, paclet:ref/StandardForm]) involves still more sophisticated rules, which allow operators and operands to be arranged not just in a one-dimensional sequence, but in a full two-dimensional structure.

The Wolfram System is set up so that (RefLink[FullForm, paclet:ref/FullForm]), (RefLink[InputForm, paclet:ref/InputForm]), and (RefLink[StandardForm, paclet:ref/StandardForm]) form a strict hierarchy: anything you can enter in (RefLink[FullForm, paclet:ref/FullForm]) will also work in (RefLink[InputForm, paclet:ref/InputForm]), and anything you can enter in (RefLink[InputForm, paclet:ref/InputForm]) will also work in (RefLink[StandardForm, paclet:ref/StandardForm]).

If you use a notebook front end for the Wolfram System, then you will typically want to use all the features of (RefLink[StandardForm, paclet:ref/StandardForm]). If you use a text-based interface, however, then you will typically be able to use only features of (RefLink[InputForm, paclet:ref/InputForm]).

When you use (RefLink[StandardForm, paclet:ref/StandardForm]) in a Wolfram System notebook, you can enter directly two-dimensional forms such as (x^2) or annotated graphics. But (RefLink[InputForm, paclet:ref/InputForm]) allows only one-dimensional forms.

If you copy a (RefLink[StandardForm, paclet:ref/StandardForm]) expression whose interpretation can be determined without evaluation, then the expression will be pasted into external applications as (RefLink[InputForm, paclet:ref/InputForm]). Otherwise, the text is copied in a linear form that precisely represents the two-dimensional structure using ∖!∖(…∖). When you paste this linear form back into a Wolfram System notebook, it will automatically "snap" into two-dimensional form.

Importing from other textual forms.

(RefLink[StandardForm, paclet:ref/StandardForm]) and its subsets (RefLink[FullForm, paclet:ref/FullForm]) and (RefLink[InputForm, paclet:ref/InputForm]) provide precise ways to represent any Wolfram System expression in textual form. And given such a textual form, it is always possible to convert it unambiguously to the expression it represents.

(RefLink[TraditionalForm, paclet:ref/TraditionalForm]) is an example of a textual form intended primarily for output. It is possible to take any Wolfram System expression and display it in (RefLink[TraditionalForm, paclet:ref/TraditionalForm]). But (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) does not have the precision of (RefLink[StandardForm, paclet:ref/StandardForm]), and as a result there is in general no unambiguous way to go back from a (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) representation and get the expression it represents.

Nevertheless, (RefLink[ToExpression, paclet:ref/ToExpression])[input,(RefLink[TraditionalForm, paclet:ref/TraditionalForm])] takes text in (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) and attempts to interpret it as an expression.

This takes a string and interprets it as (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) input:

ToExpression["f(6)",TraditionalForm]

In (RefLink[StandardForm, paclet:ref/StandardForm]) the same string would mean a product of terms:

ToExpression["f(6)",StandardForm]

When (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) output is generated as the result of a computation, the actual collection of boxes that represent the output typically contains special (RefLink[Interpretation, paclet:ref/Interpretation]) objects or other specially tagged forms that specify how an expression can be reconstructed from the (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) output.

The same is true of (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) that is obtained by explicit conversion from (RefLink[StandardForm, paclet:ref/StandardForm]). But if you edit (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) extensively, or enter it from scratch, then the Wolfram System will have to try to interpret it without the benefit of any additional embedded information.