I have a problem with the build-in Information
function for user-defined symbols with custom StandardForm in Mathematica 12.1.1.0:
For example with the function definitions
ClearAll[CM];
CM[1, a__] := CM[a]
CM /: Format[CM[a_, b___], StandardForm] := Row[{a, b}, " "]
CM::usage = "CM";
the query Information[CM]
results in:
The definitions in the output are formatted using StandardForm without even displaying it correctly. The same problem occurs when one defines UpValues. At this point this makes the Information box just unreadable but it gets worse when using InterpretationBox
. With
ClearAll[CM];
CM[1, a__] := CM[a]
CM /: Format[CM[a_, b___], StandardForm] := With[{box = ToBoxes[Row[{a, b}," "]]},
RawBoxes[InterpretationBox[RowBox[{box}], CM[a, b]]]
];
CM::usage = "CM";
A call to Information[CM]
results in an infinite recursion and several warnings and errors:
Inspecting the FullForm
of the results of Information[CM]
reveals
InformationData[Association[
...
Rule["DownValues",Information`InformationValueForm[DownValues,CM,List[RuleDelayed[CM[1,Pattern[a,BlankSequence[]]],CM[a]]]]],
...
Rule["FormatValues",Information`InformationValueForm[FormatValues,CM,List[RuleDelayed[MakeBoxes[CM[Pattern[a,Blank[]],Pattern[b,BlankNullSequence[]]],StandardForm],Format[With[List[Set[box,ToBoxes[Row[List[a,b]," "]]]],RawBoxes[InterpretationBox[RowBox[List[box]],CM[a,b]]]],StandardForm]]]]],
...
]]
and with it the internal and of course undocumented function ...InformationValueForm
which is used to output the found definitions.
Is there a way to configure or manipulate Information
or the underlying InformationValueForm
to display the function definitions using Full- or InputForm? I was able to manipulate the FullForm output by converting the arguments of RuleDelayed
inside InformationValueForm
to Strings but I was not able to attach this fix to Information
or InformationValueForm
.
I do not understand the design decision behind using StandardForm in the output of Information
for user-defined functions and the whole situation is basically a bug in my opinion. The real issue are the infinite recursions and errors for more involved formatting functions which can crash the kernel and/or front-end. I tend to document my functions and I sometimes like to use Information
to remind myself of argument order. The rather unsatisfying workaround which I am currently using is to disable Information
for my formatted functions using UpValues:
CM /: Information[CM, opts___] := CM::usage;
This way I at least have access to the usage message but definitions, options and all the other Information
-data is not accessible using this workaround.