# How use TraditionalForm input in InputField?

Inside a Manipulate, I'd like one of the controls to be an InputField and to allow the input entered to be in traditional form. Is this possible?

For example, in the output from

  Manipulate[func /. x -> val,
{{val, 0, "x"}}, {{func, x, "f(x)"}},
ControlType -> InputField]


I'd like to be able to type, say, cos(x) in the second input field and have it interpreted, of course, as Cos[x].

• related 26983 – Kuba Mar 2 '15 at 14:48

Manipulate[ToExpression[func, TraditionalForm] /. x -> val, {{val, Pi, "x"}, InputField},
{{func, "", "f(x)"}, InputField[##, String] &}]


• Should I be able to surmise such an answer from the documentation? – murray Mar 2 '15 at 19:43
• That's an interesting mathematical value, resulting from $\sin(\pi/5) = \sqrt{(5-\sqrt{5})/8}$. – murray Mar 2 '15 at 19:48
• @murray, thank you for the Accept. Re documentation, the key piece is from TraditionalForm >> Details and Options. We can get the uninteresting values using Manipulate[N@ToExpression[func, ...] or Manipulate[1. ToExpression[func, ...]:) – kglr Mar 2 '15 at 20:03
• The ToExpression[..., TraditionalForm] part I already knew about. What I did not know was the legality of a control of type {{expr, default, "label"}, InputField[#, String]&}. So applying such a ToExpression construct to the input read didn't occur to me. Of course this did appear in mathematica.stackexchange.com/questions/26983/…. – murray Mar 2 '15 at 20:15
• murray, InputField[##, String, options]& is a special case of the general syntax for Manipulate controls {{u, init,label}, controlfunction[##, options]&}. A reference is in Advanced Manipulate Functionality >> Custom Control Appearances. – kglr Mar 2 '15 at 20:51

The accepted answer uses a String type InputField, so that you can't enter 2D input. The following Manipulate version allows 2D input:

Manipulate[