1
$\begingroup$

If we take the (simple) example

x = 1;
y = 2;
z = 3;

x + y + z

we get the (complete screen) result when copying into a more basic interface, such as a web forum or text editor

In[1]:= x = 1;
y = 2;
z = 3;

In[4]:= x + y + z

Out[4]= 6

Is there any clever way to modify this output (preferably during the copy/paste operation) to become

x = 1;
y = 2;
z = 3;

x + y + z

> 6

(or some other 'minimalistic' output indicator than '>'), removing the input labels as well as reducing the output labels. It would be very convenient to have when pasting Mathematica code/output in web forums as well as in the verbatim environment in LaTeX. TIA.

$\endgroup$
3
$\begingroup$

You can disable copying of the cell labels on the global level:

SetOptions[$FrontEnd, {
  "ExportTypesetOptions" -> {"PageWidth" -> 90, "IncludeCellLabels" -> False}, 
  "ExportMultipleCellsOptions" -> {"IncludeCellLabels" -> False}}]

(I also set copied page width to be suitable for StackExchange).

This setting will persists between FrontEnd sessions.


As regards to prepending >  to the output expression (I would recommend prepending >      to have it formatted as code of the output), it can be achieved by low-level Notebook programming. Here is a start:

SetOptions[EvaluationNotebook[], CellEpilog :> Module[{out = NextCell[], boxes, newboxes},
    If[CurrentValue[out, GeneratedCell],
     boxes = NotebookRead@out;
     newboxes = boxes /. {BoxData[s_String] :> BoxData[">     " <> s]};
     NotebookWrite[out, newboxes];
     ]]];

Now any simple output will be prepended by >     .

|improve this answer|||||
$\endgroup$

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