Known issues with copying code from Mathematica to other platforms?

假装没事ソ 提交于 2019-11-30 09:00:20

Copying Mathematica code to the Usenet Mathematica group sometimes scatters all kinds of weird characters throughout your code (you never knew when it would happen to you). The workaround would be either:

  1. Cell > Convert To > InputForm and then do a copy

  2. Edit > Copy As > Plain Text or Input Text

The latter doesn't work in this case. It's still a mathematically incorrect conversion that you'll get. The former does seem to work.

Update
If you ever encounter strange characters in posts in the Mathematica newsgroup (e.g., as in here) the following function will decode it (in all the cases that I tested).

translateQuotedPrintable[str_String] := 
  StringReplace[str, {"=" ~~ c1:HexadecimalCharacter~~c2:HexadecimalCharacter :> 
    FromCharacterCode[FromDigits[c1 <> c2, 16], "Math1"],"=" ~~ EndOfLine -> ""}]

Just paste the whole posting between quotes in translateQuotedPrintable[" ... "] and the post will be cleaned up.

For the curious: the encoding that you may see in these usenet postings is called Quoted Printable. It is used to convert character encodings that differ from the standard 7-bit ASCII set to ASCII. Many common MMA symbols, like the Rule symbol, are encoded this way if not previously converted to ASCII by InputForm cs. To decode a code one needs to know the original character set because QP only yields the hexadecimal position in the character set. In MMA's case this will most commonly be Math1.

Copying the example to e-mail ALSO fails, and that -- if it carries over to other examples -- seems very bad for Mathgroup, SO, and any other text-based discussion forum. Copy As>Plain Text and Copy As>Input Form both work properly, but I've done it the easy way thousands of times, and never knew it could fail this way, WITHOUT strange hexadecimal characters.

This is a good example of how MMA is set up to resolve mathematical ambiguity introduced in typesetting. (+1)

The reason it fails is that you've not yet evaluated the original expression. When you evaluate, Mathematica correctly parses the "/" between the two chunks and the output can be copied and pasted (correctly).

Perhaps WRI should make it so that 'Copy' forces the parsing mechanism to occur prior to clip-boarding the expression --- i.e., some sort of 'soft' evaluation. Thoughts?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!