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
Cell[BoxData[
RowBox[{"copyUnicode", "[",
RowBox[{
RowBox[{
RowBox[{
SuperscriptBox["x", "2"], "\[SmallCircle]",
RowBox[{"{",
RowBox[{
RowBox[{"\[LeftFloor]", "\[Alpha]", "\[RightFloor]"}], ",",
"\"\<\[LeftFloor]\[Alpha]\[RightFloor]\>\""}], "}"}]}],
"\[PlusMinus]",
RowBox[{
SqrtBox["5"], "\[CirclePlus]", "\[HappySmiley]"}]}],
"<=",
"\"\<\[Integral]\[PartialD]\[RightArrow]\[Union]\[Sum]\[Infinity]\
\[Element]\>\""}], "]"}]], "Input"]
gives x^2 ∘ {Floor[α], "⌊α⌋"} ± Sqrt[5] ⊕ ☺ <= "∫∂→⋃∑∞∈".
Windows
Not tested, but it should work if you use "!clip"instead of"!xclip -in -selection clipboard"`. You might have to change the encoding to UTF-16.
Caveats
- Note that certain characters get ASCIIfied anyway in
InputForm when not inside a string.
- Mathematica uses non-standard private-use code points for some characters like U+211D
ℝ, even when a standard code point exists, so the output will be wrong if the input contains such characters.