8

Bug introduced in 8.0 or earlier and persisting through 11.1


When saving notebooks, the Front End destroys "\r" appearing in code and converts it to "\n". Here are minimal steps to reproduce the issue:

  1. Enter this in a notebook, then evaluate it:

    DynamicModule[{},
     "Empty",
     Initialization :> "\r\n"
    ]
    
  2. Save the notebook.

  3. Open the notebook in a text editor and look at its expression. I see

    Initialization:>"\n\n"
    

    The \r has been changed to an \n.

I observe this on OS X with M9.0.1–M11.1.0. Do other people see it? Is it a bug? Is there a simple workaround?

In my actual use case, I have StringReplace[..., {"\r\n" -> "\n", "\r" -> "\n"}] in Initialization. This gets mangled and made non-functional by this problem.


Reported as CASE:3873908.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263

1 Answers1

3

One possible workaround is using

FromCharacterCode[{13}]

in place of

"\r"
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • Another one, also reducing the size of the palette: With[{init = Compress @ Unevaluated @ (Print @ Style["test\r", ShowStringCharacters -> True])}, DynamicModule[{}, "Empty", Initialization :> (Uncompress@init)] ]. Probably blocked context would be on point. Another closely related solution: http://mathematica.stackexchange.com/a/86707/5478 – Kuba Apr 05 '17 at 09:40