Producing cleaner Mathematica output

Here is an approach using CellEvaluationFunction:

Use the Options Inspector and set CellEvaluationFunction to:

(Map[ToExpression, Row[Apply[Riffle[#, "\", \""]& , #]]]& )

This is best combined with style sheets to define a style that automatically uses this function. (Ask if you need help setting this up.)

To use this more simply, or simply to try it out, evaluate this to create a new Input cell, then type your input into that cell:

CellPrint[
 Cell[BoxData[""], "Input", 
  CellEvaluationFunction ->
   (ToExpression /@ Row[Riffle[#, "\", \""] & @@ #] &)]]

The result should look like this:

Mathematica graphics


I highly doubt something that answers your question is useful in any way, since your plan is to strip output of syntactically relevant information, but here we go:

Mathematica provides a few commands that are applied to input/output automatically:

$Post

$Post is automatically applied to all expressions before their output is printed. This alters the data, e.g. setting $Post = N will generate numerical data only.

{1 + 1, 1 + 2}

(* Print lists in column form *)
$Post = If[Head[#] === List, Column[#]] &;

{1 + 1, 1 + 2}    
(* You can't add 1 to a column :-( *)
% + 1

(* Reset the variable to default *)
$Post =.
{1 + 1, 1 + 2}

Output

$PrePrint

$PrePrint is similar to $Post, only that it does not affect output but only the printed version, i.e. the visualization. Setting this to N will preserve the normal Mathematica workflow in the back end, only the display is different.

{1 + 1, 1 + 2}

(* Print lists in column form *)
$PrePrint = If[Head[#] === List, Column[#]] &;

{1 + 1, 1 + 2}
(* Only printing is affected, you can still
   do normal arithmetic with the output *)
% + 1

(* Reset the variable to default *)
$PrePrint =.
{1 + 1, 1 + 2}

Output

$Pre

$Pre is applied after the input has been put in. Make sure make sure to include a Hold somewhere, otherwise it's pretty much the same as $Post (see remarks in the documentation).


You could use Format

Format[myInput[a___]] := DisplayForm@RowBox[Riffle[{a}, ","]]

Then

myInput[a = 1 + 1, b = 1 + 2]

(* 
 ==> 2, 3
*)

More complicated input:

myInput[D[Cos[Log[x]^2], x], Integrate[Sin[1/x], x], Integrate[Log[Cos[x]], x]]

Mathematica graphics

TraditionalForm:

myInput[D[Cos[Log[x]^2], x], Integrate[Sin[1/x], x], Integrate[Log[Cos[x]], x]] 
      // TraditionalForm

Mathematica graphics

Tags:

Formatting