# TagBox + InterpretationBox vs ConvertTo/StandardForm

There appears to be a problem with a menu command Convert To / StandardForm (Crtl+Shift+N) with respect to InterpretationBox which contains TagBox (which is how Column/Grid and friends are typeset).

Here's an example:

obj /: MakeBoxes[obj[arg__], fmt_] := With[
{appearance = MakeBoxes[Panel[Column[{arg}], "obj"], fmt]}
, InterpretationBox[appearance, obj[arg]]
]

obj[1, 2, 3, 4]


% // InputForm


obj[1, 2, 3, 4]

So far everything is ok. But select the Input cell containing intial obj and use the menu command. This is what happens:

I find it unexpected because all round trips like

ToExpression@MakeBoxes@obj[1, 2, 3, 4]


work well.

Question: Is this expected? If yes, what would be a general fix to the typesetting idiom presented above?

Few workarounds are presented in: Make a custom object look like MatrixForm of a matrix?, where this issue came up. But they are not general enough.

The issue was noticed by xzczd and investigated by jkuczm but without any final conclusion.

This report finally found its way to me, and this is not a bug. I'm sorry support gave you incorrect information.

This has nothing to do with the particular boxes involved, but rather with your use of the typeset generators Panel and Column. Most typeset generators, Graphics expression, and certain other symbols have "conditional text formatting rules". Specifically, they check the value of BoxFormUseTextFormattingQ when converting to a box from. This variable defaults to being True in input cells and False in output, though this can be changed somewhere in the options inspector. The theory is, if you did Convert To StandardForm on code (say, your MakeBoxes rule), you wouldn't necessarily want to go to a form where it can really be easily edited.

So, if you want to create a box structure that always uses box formatting, you can block the variable to False like so:

obj /: MakeBoxes[obj[arg__], fmt_] := With[
{appearance = Block[
{BoxFormUseTextFormattingQ = False},
MakeBoxes[Panel[Column[{arg}], "obj"], fmt]
]},
InterpretationBox[appearance, obj[arg]]
]


Workarounds for existing structures would be to use Evaluate in Place rather than Convert To StandardForm (since many of the heads to use this have no evaluation semantics), or change the value of the option "UseTextFormattingWhenConvertingInput" to False.

• The solution doesn't seem to work if I modify Panel[Column[{arg}], "obj"] to MatrixForm[{arg}]? – xzczd Jun 26 '18 at 6:44
• Grumble Grumble. Yes, the *Forms are special because of the wrapper stripping behavior. You can make it work by adding Internal\$ConvertForms = {} to the Block` variable list. – Itai Seggev Jun 26 '18 at 23:52