Bug introduced in V10 and partially fixed in V11.1.1
TLDR
Various of expressions which have fancy typeset form or are designed as UI elements won't survive ToExpression @* ToBoxes
round-trip. And they should.
Examples
InterpolatingFunction
(new)MakeExpression[#, StandardForm] & @ ToBoxes @ Interpolation[ {{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}} ] // Shallow
ErrorBox[ErrorBox[TagBox[<<5>>]]]
ToExpression::esntx: Could not parse TagBox[<<1>>] as input.
InputField
ToExpression @ ToBoxes @ InputField[Dynamic[x]]
$Failed
ToExpression::notstrbox: InputFieldBox[x] is not a string or a box. ToExpression can only interpret strings or boxes as Wolfram Language input.
I don't expect
InputField[Dynamic[x]]
but at least something which is a proper expression, e.g. button works:ToExpression @ ToBoxes @ Button[Dynamic[x]] // InputForm
Button[Dynamic[x], Evaluator -> None, Appearance -> Automatic, Method -> "Preemptive"]
Things get weirder,
MakeExpression
can handleInputField
case:InputForm @ MakeExpression[ #, StandardForm ] & @ ToBoxes @ InputField[Dynamic[x]]
HoldComplete[InputField[Dynamic[x]]]
FileNameSetter
InputForm@MakeExpression[ #, StandardForm ] & @ ToBoxes @ FileNameSetter[Dynamic[x]]
ErrorBox[RowBox[{"FileNameSetterBoxes", "[", ErrorBox[Dynamic[x]], ",", "Open", ",", All, "]"}]]
Syntax::sntxf: "FileNameSetterBoxes[" cannot be followed by "x,Open,All]".
Question
Are those bugs or have I missed something. Please help me understand that. :)
x = Dynamic[y]; MakeExpression@MakeBoxes@FileNameSetter[x]
andx = Dynamic[y]; ToExpression@MakeBoxes@FileNameSetter[x]
do work. $\endgroup$MakeExpression@MakeBoxes@FileNameSetter[Dynamic[f]]
andToExpression@ToBoxes@FileNameSetter[Dynamic[f]]
works in Mathematica version 9.0.1. $\endgroup$ToBoxes@FileNameSetter[Dynamic[f]]
creates anInterpretationBox
. Since version 10 aTemplateBox
is created. $\endgroup$CurrentValue[{StyleDefinitions, "FileNameSetterBoxes"}]
. Which the FE understands, but the kernel does not. So this does properly roundtrip to output cells and back to input cells, but not through the more constrainedMakeBoxes
/MakeExpression
roundtrip. $\endgroup$