14
$\begingroup$

I always use InputForm to check the result object,such as Dataset or Graphics or other objects.But if you are in the result of InputForm,you cannot use the Front-End function of balance the bracket. Note this gif

enter image description here

When I double click the input line, I will select all content just in this bracket.But when I'm in result of InputForm,I will select all line. Of course I can copy the output of InputForm as another new input,but which will make the notebook more mess.

Any method can make the output of InputForm support the function of balance the bracket?

$\endgroup$
  • 8
    $\begingroup$ Use expr //InputForm //SequenceForm $\endgroup$ – Carl Woll Jul 2 '17 at 23:50
  • $\begingroup$ @CarlWoll Fun,that is a workaround deserved to be accepted..Thanks very very much... $\endgroup$ – yode Jul 2 '17 at 23:57
  • 1
    $\begingroup$ I tend to use output // InputForm // List. Although it adds an extra pair of enclosing braces, I find it a small price to pay to use those features you desire. $\endgroup$ – MarcoB Jul 3 '17 at 3:42
  • $\begingroup$ @MarcoB Yes,I'd like to use your solution.Thanks.Of course,output // InputForm // f is enogh for me. $\endgroup$ – yode Jul 3 '17 at 3:53
  • $\begingroup$ Strongly related: (a/55545). $\endgroup$ – Alexey Popkov Jul 4 '17 at 14:14
11
$\begingroup$

Per my comment, I like using expr //InputForm //SequenceForm, but another similar possibility is to use a custom head with a custom MakeBoxes rule. For instance, let's call the custom form myInputForm. Then, we can define:

myInputForm /: MakeBoxes[myInputForm[expr_], StandardForm] := MakeBoxes[InputForm[expr]]

We also need to add myInputForm to $OutputForms:

Unprotect[$OutputForms];

AppendTo[$OutputForms, myInputForm];

Protect[$OutputForms];

Now, myInputForm gets stripped before being stored in Out. For instance:

Interpolation[{1,2,3,4}]
% //myInputForm
% //Head

InterpolatingFunction[{{1, 4}}, <>]

InterpolatingFunction[{{1, 4}}, { 5, 3, 0, {4}, {4}, 0, 0, 0, 0, Automatic, {}, {}, False}, {{1, 2, 3, 4}}, {{ 1}, {2}, {3}, {4}}, {Automatic}]

InterpolatingFunction

| improve this answer | |
$\endgroup$
13
$\begingroup$

If you have Version 11 you can use the function PrettyForm instead of processing InputForm output to get the desired result:

Needs["GeneralUtilities`"]

Interpolation[{1, 2, 3, 4}] // PrettyForm

enter image description here

ListLinePlot[Range[5]^2] // PrettyForm

Mathematica graphics

For earlier versions you can also wrap InputForm with DisplayForm:

ListLinePlot[Range[5]^2] // InputForm // DisplayForm

Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ Well,I learn a ton of *Form today.Thanks. :) $\endgroup$ – yode Jul 3 '17 at 12:17
  • $\begingroup$ @yode, does PrettyForm work in your desktop version? if not i I will delete that part. $\endgroup$ – kglr Jul 3 '17 at 12:20
  • $\begingroup$ @kglr it does, nice find. $\endgroup$ – Kuba Jul 3 '17 at 12:26
8
$\begingroup$

Carl's tip seems to be the best quick solution.

Very often I find syntax/style highlighting very useful too so I use:

CellPrint[ExpressionCell[InputForm@#, "Input"]] &

to get everything what Input cells offer:

Plot[x, {x, 0, 1}, PlotPoints -> 10, MaxRecursion -> 1
] // CellPrint[ExpressionCell[InputForm@#, "Input"]] &

enter image description here

related:

How to see a code preview (in Experimental`Explore[] or related GUI)

How to use an ExpressionCell to display e.g. an Input cell inside a generated output?

| improve this answer | |
$\endgroup$
  • 5
    $\begingroup$ I'm not a huge fan of this because of the combination of CellPrint and the "Input" style. This creates Input cells which have GeneratedCell->True and CellAutoOverwrite->True (this is documented behavior of CellPrint). If you start using these cells for real, then you may have unpleasant side effects...like your Input cells disappearing when you evaluate inputs above them. If you really want Input cells, I'd recommend a NotebookWrite based solution. The equivalent formulation would be NotebookWrite[EvaluationNotebook[], Cell[BoxData[ToString[#, InputForm]], "Input"]] &. $\endgroup$ – John Fultz Jul 9 '17 at 5:19
  • $\begingroup$ @JohnFultz valid points but wasn't the problem for me so far as I used it only for preview or manual gutting. $\endgroup$ – Kuba Jul 10 '17 at 10:54
  • 3
    $\begingroup$ Many (many, many) years ago, we made a big mistake and had cells written by NotebookWrite have GeneratedCell->True. It caused a whole class of mysterious-to-our-users bugs where cells would just seem to "randomly" disappear after evaluation and data was getting lost. It took quite a long time after we fixed NotebookWrite to stop seeing user reports like this. So, hopefully, you'll understand my sensitivity about the subject. $\endgroup$ – John Fultz Jul 31 '17 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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