Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Related :

How to "Copy as Unicode" from a Notebook?

Plot[\[Alpha], {\[Alpha], 0, 8}]

cellExpression

(*
Cell[BoxData[RowBox[{Plot,[,RowBox[{\[Alpha],,,RowBox[{{,RowBox[{\[Alpha],,,0,,,8}],}}]}],
]}]],Input,CellChangeTimes->{3.58068*10^9,{3.58068*10^9,3.58068*10^9}}]
*)

CellExpression2InputText[cellExpression_] := First[FrontEndExecute[
FrontEnd`ExportPacket[cellExpression, "InputText"]]]

CellExpression2InputText[cellExpression]

(*
Plot[\[Alpha], {\[Alpha], 0, 8}]
*)

CellExpression2InputText[cellExpression] // CopyToClipboard

Paste[]

Plot[\[Alpha], {\[Alpha], 0, 8}]

when copy the result above to SE, the [Alpha] was not shown in Unicode Form. And I failed in my usage involved with CellExpression2InputText

Mr.Wizard's method, this is good to copy directly from input cell.

SetAttributes[copyUnicode, HoldFirst]
copyUnicode[expr_, form_: InputForm] :=
Run["clip <", Export["$Clipboard.temp", ToString[Unevaluated @ expr, form],
"Text", CharacterEncoding -> "Unicode"]];

case 1

CellExpression2InputText[cellExpression] // copyUnicode

Paste[]

PasteResult(not good)

CellExpression2InputText[cellExpression]

case 2

ToExpression[CellExpression2InputText[cellExpression], InputForm, HoldForm] // copyUnicode

Paste[]

still not good

question


So question is clear:

How to convert CellExpression to string/clipboard with greek letters in Unicode Form when copy to SE without laborious work by hand.

\[Alpha] ==> to α
share|improve this question
    
I thought you understood after the discussion in meta that you shouldn't use combine quote form and comment form to format an output cell in markdown. Evidently, I was wrong, so I tell you now: don't do it. –  m_goldberg Jun 20 '13 at 3:52
    
@m_goldberg aha, fine, ok, I will modify my package to generate that differ from the old styles. –  HyperGroups Jun 20 '13 at 4:03
    
@m_goldberg help, When I'm reading the MarkDown help page, I have trouble comprehending this sentence.Like code blocks, code spans will be displayed in a monospaced font. Markdown and HTML will not work within them. Note that, [unlike] code blocks, code spans require you to manually escape any HTML within! I donot know what is the unlike mean. Because I found that they both keep the html tags. –  HyperGroups Jun 20 '13 at 7:52
    
I don't think this comment thread is the place to discuss this. Post it as a question in meta, or take it up in chat. –  m_goldberg Jun 20 '13 at 9:45
    
@m_goldberg ok, seems a little tiny as a question in meta. I haven't used chat by far, maybe I should try that. –  HyperGroups Jun 20 '13 at 10:02

2 Answers 2

up vote 7 down vote accepted

For this specific case there is a solution which does not rely on Mathematica. Since the greek characters copied from Mathematica were a general problem here on our site which made code-blocks tedious to read, I have adapted a stolen user script. This can be installed as extension into browsers and provides additional buttons which let you (beside other things) make this conversion easily.

Please read this meta post for more information and a installation guide.

share|improve this answer

Although I'm not on Windows and you apparently are, I would guess that you can fix this problem by wrapping your cellExpression as follows:

ToExpression[cellExpression, InputForm, HoldForm]

The output of your function CellExpression2InputText escapes the backslashes defining Mathematica's special characters, so they aren't translated to Unicode. But this added escape level is removed in ToExpression.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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