# Tag Info

28

Since a native method is not forthcoming, I shall post my file based circumvention, for Windows. You will need to have this utility in the command path (it apparently is stock with Windows 7). copyUnicode[expr_] := Run["clip <", Export["$Clipboard.temp", ToString[expr, InputForm], "Text", CharacterEncoding -> "Unicode"] ]; Usage: expr ... 20 Declaration: This method for Windows is based on the .NET code from Todd Gayley's this wonderful answer. My .NET knowledge is absolutely ZERO, all credit goes to Todd. Code: The main idea is to extract the "Input"-style code string, convert it to the UTF-16 little endian form, which is the standard byte order in Windows, feed the bytes to system clipboard ... 15 Paste is a command that, as a side-effect, inserts the contents of the clipboard into the current notebook selection. The return value is always Null, which means that Paste cannot be used for our purpose without some awkward notebook manipulation. There is an undocumented way to access the clipboard: ClipboardNotebook. NotebookGet[ClipboardNotebook[]] ... 14 Here are two functions that'll do what you need. putClipboardImage[img_Image] := Module[{nb}, nb = CreateDocument[{}, Visible -> False, WindowSelected -> False]; NotebookWrite[nb, Cell[BoxData@ToBoxes@Image[img, Magnification -> 1]]]; SelectionMove[nb, All, CellContents]; FrontEndTokenExecute[nb, "CopySpecial", "MGF"]; ... 12 Edit 2: A new version of the Mac solution with button is listed below Fixed problem with pasting into textarea In some applications on Mac, copying as Unicode from Mathematica already works without having to do any postprocessing. However, it doesn't work in textarea fields in web browsers. Nevertheless, if you're willing to do a few additional mouse ... 12 Here is a considerable simplification of Liam's accepted answer. It avoids the need to create and compile a C# program. This is basically just a small modification to Simon Woods' answer, so that it writes directly to the clipboard instead of creating a temporary file on disk. This avoids the need to clean up the file afterward. Needs["NETLink"] ... 10 Something like this? It does just what you suggested: export the file and then place a FileDrop reference to it on the clipboard. Needs["NETLink"]; InstallNET[]; LoadNETType["System.Windows.Forms.DataFormats"]; LoadNETType["System.Windows.Forms.Clipboard"]; exportToClipboard[graphics_] := Module[{dob, file}, file = FileNameJoin[{$TemporaryDirectory, ...

9

Here's how to add a permanent menu item and keyboard shortcut for Silvia's solution. (This can be easily adapted to Jens' solution for Mac OS.) 1. Add Package Copy Silvia's first code block that starts with Needs["NETLink"] to a file and save it as UniCodeCopy.m in one of the directories included in $Path. 2. Initialize the Front End Save the ... 9 Here's a version that doesn't require a temporary file. Linux (needs xclip) SetAttributes[copyUnicode, HoldAll]; copyUnicode[expr_] := With[{ stream = OpenWrite["!xclip -in -selection clipboard", CharacterEncoding -> "UTF-8"] }, WriteString[stream, ToString[Unevaluated@expr, InputForm]]; Close@stream; ]; Example: executing the cell ... 8 I use a small web application for when there are too many to convert by hand. 8 The following code copies the actua PNG image to the clipboard with transparency. This varies from the other answer in that it actual stores the entire image instead of a reference to the file. This code will likely work with more applications then the one above. It currently uses the Ctrl+Shift+C to copy with transparency. The code takes a while to run ... 7 Here is a function that copies a Unicode string to the clipboard using JLink: Needs["JLink"]; InstallJava[]; LoadJavaClass["java.awt.Toolkit", AllowShortContext -> False]; uniclip[s_String] := JavaBlock[ javaawtToolkitgetDefaultToolkit[]@getSystemClipboard[]@setContents[#, #]& @ JavaNew["java.awt.datatransfer.StringSelection", s] ... 5 Converting a comment to an answer, in the 10.1.0 Front End this works: SetOptions[$FrontEndSession, {"PageWidth" -> 1000, "ExportTypesetOptions" -> {"PageWidth" -> 1000}}] I do not use CDF so I do not know how this relates. I found that I needed to set both options shown or the copy would still wrap. The value 1000 was purely arbitrary; ...

5

For example: Binarize /@ ToExpression@ Cases[NotebookGet[ClipboardNotebook[]], BoxData[_], Infinity]

4

This is a possible solution that I came up with after looking at another answer by @Ragfield: Encoding format used by GraphicsData? I had to modify the function decodePICT in that post to cut out the leading zero bytes: DecodePDF[data_String] := Module[{slash, backslash, zero, LF, CR, decode, codes, len, i}, {slash, backslash, zero, LF, CR} = ...

3

The following works borrowed mostly from here. Needs["NETLink"]; InstallNET[]; LoadNETType["System.Windows.Forms.Clipboard"]; LoadNETType["System.Windows.Forms.TextDataFormat"]; SystemWindowsFormsClipboardGetText[SystemWindowsForms\ TextDataFormatUnicodeText]

3

This isn't exactly what you want, but if you File > Print > Save as PDF then the content will appear correctly. It's only Export where it doesn't appear.

3

If you look at the internal expression of the cell containing the image, you'll find that it also uses the compressed form. However, the usual trick of Cell@BoxData@ToBoxes... doesn't seem to work here, as that only gives us the RawArray representation. This gives us a hint at a possible way of retrieving the compressed representation without having to build ...

1

This works for me: boxes = ToBoxes@Graphics@Raster[RandomReal[{0, 1}, {5, 5}]] (* ==> GraphicsBox[ RasterBox[{{0.0429951, 0.153342, 0.815801, 0.825589, 0.178414}, {0.732659, 0.659418, 0.871481, 0.644735, 0.54453}, {0.499096, 0.328874, 0.40405, 0.436912, 0.0551782}, {0.824125, 0.889256, 0.249706, 0.562126, 0.408294}, {0.612762, ...

1

As a generalization to the excellent answer by ens, Silvia's solution also can be added as a palette to the menu as follows. First, create and save the UniCodeCopy.m package, as described by ens. Then create as a separate notebook, perhaps named Unicode Copy Source.nb, CreatePalette[Button["UniCode Copy", Module[{codestr}, ...

Only top voted, non community-wiki answers of a minimum length are eligible