I have:



If I enter e.g.

a b x^5 h m

the entry automatically gets sorted, as per screen grab:

enter image description here

What is the best way to keep symbols entered into InputField in the same order that you entered them so that they always display in that order?

What I am actually wanting to do is enter some text that contains things like subscripts and superscripts, integrals ... InputField[expr, String] is not the answer. On the other hand if I use

InputField[Dynamic[d], Hold[Expression]]

and then

d /. {Times -> List, Power -> Superscript} // ReleaseHold

I get a list that I can do things with:

enter image description here

For example I could wrap Row with a default spacer or TextCell and so on around it. But this seems quite an indirect way of doing things.


Adding HoldForm to the second argument to Dynamic doesn't appear to offer any advantage and as Andrew points out you can end up with nested HoldForm. So I think this is not a good solution -- maybe a backwards step actually.

enter image description here

For Andrew's solution, using Boxes in InputField doesn't, in itself, prevent ordering when you eventually release Hold (e.g. after using MakeExpression). i.e. I don't see how to avoid apply a hold of some type and removing Times to stop the ordering.

enter image description here

So using Boxes may in general provide more flexibility but I'm struggling to see how it adds anything for this specific problem.

  • $\begingroup$ Idiomatically, I'd be using HoldForm[] instead of Hold[]... $\endgroup$ Feb 18, 2012 at 1:35
  • $\begingroup$ You can't render an input field if you use HoldForm or HoldForm[Expression] $\endgroup$ Feb 18, 2012 at 2:01
  • 1
    $\begingroup$ Huh. That is rather peculiar behavior... $\endgroup$ Feb 18, 2012 at 2:05

2 Answers 2


You could do something like

InputField[Dynamic[d, (d = HoldForm @@ #) &], Hold[Expression]]

This will wrap the expression typed into the input field in HoldForm.

Mathematica graphics

  • 4
    $\begingroup$ Note, this leads to a new layer of HoldForm appearing after each edit. E.g. after a few edits you will have FullForm[d] => HoldForm[HoldForm[HoldForm[HoldForm[HoldForm[HoldForm[abc]]]]]]. $\endgroup$ Feb 18, 2012 at 21:15
  • 2
    $\begingroup$ I do see it in Mathematica 7 with these steps: Type Dynamic[FullForm[d]]. Now enter something like asdf into the InputField. Press Enter to trigger the Dynamic update. Now click inside the InputField, say after the "s". Press backspace, enter a different letter, and press Enter again. Repeat. I get another layer of HoldForm each time. $\endgroup$ Feb 18, 2012 at 21:55
  • $\begingroup$ This doesn't appear to have any advantage over using plain vanilla Dynamic[d] as per what I have described in the question. See edit. $\endgroup$ Feb 18, 2012 at 23:37
  • $\begingroup$ @Andrew okay, I see it now. $\endgroup$
    – Mr.Wizard
    Feb 19, 2012 at 0:01

Since you said you wanted text input containing subscripts, superscripts, etc, it sounds like you just want Mathematica's box language:

InputField[Dynamic[d], Boxes]

Now d is boxes, such as

In[39]:= FullForm[d]


You can convert them to expressions with MakeExpression or ToExpression, or interpret them any other way you need to.

  • $\begingroup$ Very good point - +1. $\endgroup$ Feb 18, 2012 at 21:46
  • $\begingroup$ That doesn't seem to prevent the automatic ordering when Hold is released. $\endgroup$ Feb 18, 2012 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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