# Copy and paste behaviour with Subscript

I tend to use a lot of subscripts in my code, and I am aware that copy and paste of subscripts from Mathematica to MathematicaSE (or any text editor, for that matter) is screwy in the sense that $a_b$ copies to MathematicaSE as

Subscript[a, b]


which when pasted back into Mathematica yields Subscript[a, b]. This is quite different behavior than Greek or other special symbols; for example, $\Lambda$ copies into MathematicaSE as

\[CapitalLambda]


which when pasted back into Mathematica correctly yields $\Lambda$. The same applies even for more obscure symbols, like \[WhiteBishop].

Is there any way at all to have subscripts correctly copy and paste from notebook to text to notebook like all the other special symbols in Mathematica? Or is there no choice but to use infix symbols, like a[b]?

-
After you paste back into a notebook, you can select the cell and press Ctrl-Shift-N to format it as StandardForm. This will change the Subscript to look like a subscript. It will also do some other formatting, some of which may not be desirable (e.g. remove all newlines). – Szabolcs Feb 28 '14 at 15:07
@Szabolcs: Thanks, that seems to be a usable workaround, if you post as an answer I'll mark it as resolved. – DumpsterDoofus Feb 28 '14 at 15:13
Well, I didn't post as an answer because there's enough undesirable formatting done by it that I didn't find it very usable myself ... – Szabolcs Feb 28 '14 at 15:17
@Szabolcs: When you say "undesirable", do you mean that it can potentially execute incorrectly after pasting and Ctrl-Shift-N, or that it aesthetically looks bad? – DumpsterDoofus Feb 28 '14 at 15:18
It just looks bad, as in less readable. My biggest problem is the removal of line breaks. It should never execute incorrectly. – Szabolcs Feb 28 '14 at 15:19

I use a lot of superscripts and subscripts in my work as well, so this question intrigued me although the problems I have are a little bit different (chemistry formulas and suchlike).

I found a good lead from the answer by Mr. Wizard on this question (Paste data into Mathematica with formatting).

I have merely modified the end of Mr. Wizard's raw paste function and renamed it. This could then be used to make a paste button to sit in DockedCells or in a Palette.

    Button["Paste in Display Form", pasteAsExpression[]]

pasteAsExpression[] :=
NotebookGet[ClipboardNotebook[]] /.
Notebook[{Cell[BoxData[data_] | data_, ___]}, ___] :> (Paste[
ToExpression[data]])


I first had simply tried utilizing the Paste[] function which pulls from the system clipboard, and use StandardForm or DisplayForm to modify it (e.g. StandardForm@Paste[]), but this didn't work. What does work is to use Paste[StandardForm[Subscript[a,b]]], but that necessitates getting the data from the clipboard. Mr. Wizard's solution solved that for me. There may be a way to use a pure function to get Paste[] to do what is needed, but I couldn't figure it out.

-
This is my first answer. I hope that I provided sufficient credit to @Mr. Wizard as this is clearly a simple modification of his solution to a similar problem. I am not quite sure what the etiquette is for citation, so I just did the best that I could. – Andy Mobley Feb 28 '14 at 16:29
Thanks, this and Mr. Wizard's solution should make things easier for people who care about formatting and line breaks. – DumpsterDoofus Feb 28 '14 at 17:00

After you paste back into a notebook, you can select the cell and press Ctrl-Shift-N (Cmd-Shift-N on OS X) to format it as StandardForm. This will change the Subscript to look like a subscript.

Be aware that will also do some other formatting, some of which may not be desirable from a readability viewpoint (e.g. it removes all newlines from within a single expression such as a Module).

-