1

This is copy from cell Ctrl+C.

(added in SE, no newline)sampleList1 = {"compute", "Tes", ".", ".a", ".m", "a", "z", "T", ".T", "wha", "{"};

Add indent by four/eight spaces

sampleList1 = {"compute", "Tes", ".", ".a", ".m", "a", "z", "T", ".T",
(here newline)"wha", "{"};

Delete the newline by Backspace

sampleList1 = {"compute", "Tes", ".", ".a", ".m", "a", "z", "T", ".T", "wha", "{"};

My question is: Are there some reasons for this newline?

One guess is that the page width of edit window is not the same to that of preview window at least in my current Explorer Chrome.

enter image description here enter image description here enter image description here

At present I wish it will not generate the newline in that place but generate where the page width of preview window is not sufficed. enter image description here

5
  • 1
    Well, this is primarily because the frontend copies code with arbitrary line breaks and indentation and what you see in your notebook is not what is copied (or I've never been able to figure out a pattern for it). If you use any decent text editor to write your code or write it inside code cells in the notebook, you shouldn't run into this issue.
    – rm -rf Mod
    Jun 15, 2013 at 2:03
  • @rm-rf ah, so it is. Copy directly from Code style cell seems like copy as plaintext. And I find copy from Input cell will preserve spaces in codes, but encounter the newline problem. f[space in SE]@@[space in SE]list except f@list. I'm trying use this to copy from input cell. First@FrontEndExecute[FrontEnd`ExportPacket[CellExpression,"InputText"], when I use "PlainText", then no newline problem, but also without spaces between codes. Any suggestions? Jun 15, 2013 at 2:28
  • Re: preserve spaces in code — input cells will insert additional spaces to code (i.e., not added by the user) and will sometimes refuse to add additional spaces/tabs where you want it to. So it's not necessarily "preserving" it, because I don't know what's there underneath the hood to begin with. Code cells, on the other hand, will preserve everything in it — the catch is that you'll have to enter spaces around operators yourself.
    – rm -rf Mod
    Jun 15, 2013 at 2:54
  • You can determine the column at which the Front End wraps lines in copied test with this system option: ExportTypesetOptions -> {"PageWidth" -> 90} -- I use 90 based on this. Also see this question on Main.
    – Mr.Wizard
    Jun 15, 2013 at 3:35
  • @Mr.Wizard nice, it works. Jun 16, 2013 at 3:02

0

You must log in to answer this question.

Browse other questions tagged .