The following creates a file with the desired unicode:
Export["/tmp/foo.txt", "\[Alpha]\[LessEqual]b"] (* save in Unix temp directory *)
Copying it to the clipboard is another issue. Copy/paste is a not a simple process. The data is interpreted/converted along the way, particularly by the receiving application. In Mathematica, String
expressions always seem to appear in their expanded ASCII form (that is, "\[Alpha]" not "α"). I think CopyToClipboard
and the menu command Edit > Copy will always copy this sort of Mathematica string. In notebooks, these strings are "typeset" by the Front End so that the corresponding Unicode glyph is shown on the screen. But if you ever edit a notebook with an ASCII editor, you will see that they are stored as [Alpha] etc.
Now if you're on a Mac, and probably if you're on Linux (but not WolframCloud), then the following will probably copy the Unicode to the system clipboard:
Run["export LANG=en_US.UTF-8; cat /tmp/foo.txt | pbcopy"]
I don't know what to do on Windows.
If Export[]
works, why not ExportString[]
? Well, the String
returned by ExportString[]
contains the six bytes of Unicode data in foo.txt
, but it becomes a Mathematica string. And in this case, something odd happens. Each of the six bytes is interpreted as a character, each of them different from characters in the input except the ASCII "b".