8
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ Same on Win10 V11.1. $\endgroup$ – Kuba Apr 5 '17 at 9:34
  • $\begingroup$ Same with Mathematica 8.0.4 on Win7x64. $\endgroup$ – innaiz Apr 6 '17 at 13:37
3
$\begingroup$

One possible workaround is using

FromCharacterCode[{13}]

in place of

"\r"
$\endgroup$
  • $\begingroup$ 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: mathematica.stackexchange.com/a/86707/5478 $\endgroup$ – Kuba Apr 5 '17 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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