By default code copied from the FrontEnd is formatted with backslashes added at the ends of lines. For example, evaluating in a Notebook
Range[40]
and copying the output produces the following when pasted in a text editor:
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, \ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, \ 37, 38, 39, 40}
I would like to turn off addition of the backslashes at the ends of lines for the Copy
command by default while preserving the wrapping with custom PageWidth
.
For example with a PageWidth of 35:
SetOptions[$FrontEndSession, "ExportTypesetOptions" -> {"PageWidth" -> 35}]
copying the output of Range[40]
and pasting here should yield:
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40}
(Custom PageWidth
wrapping is applied but without backslashes at the ends of lines.)
Is it possible?
Update
Inside of the Notebook interface it is possible to achieve the desired formatting as follows:
CellPrint@TextCell[ToString[Range[40], InputForm], "Text",
TextJustification -> 1, PageWidth -> 330]
But I still can't figure out how to copy such output keeping this formatting...
Ctrl+C
), not programmatic copying viaCopyToClipboard
. $\endgroup$Ctrl
+Shift
+C
copies unformatted code without wrapping. I need formatted code but without backslashes. $\endgroup$a // f
will be converted tof[a]
. I need to preserve the appearance with customPageWidth
. $\endgroup$