# Copy as Input Text via Function

I've got some code which generates a series with coefficients that are a rather complicated expressions of Greek letters with subscripts. I want to store some of these coefficients for future use, rather than computing them each time I run my program.

What I would like, is to store each coefficient as if I had used the "Copy As" -> "Input Text" functionality which you get when right clicking on a specific cell. And I would like to do this via the Export[] function rather than doing it for each coefficient manually. Does anyone know how to do this so that, in particular, the Greek letters are exported as $\backslash[\text{Rho}]$ as opposed to $\rho$. "Copy As" -> "Input Text" does this, but Export[] gives the formatted $\rho$, which causes problems on import.

• Have a look at CopyToClipboard I think it does what you want. You should note that there are functions for saving expressions for furture usesuch as Put and Save. – Quantum_Oli Nov 23 '16 at 9:38
• Excellent, thank you! PutAppend and then ReadList gives me exactly what I want. – Billy Pilgrim Nov 23 '16 at 10:12
• @BillyPilgrim If you use Put and Read together, then you shouldn't write to a file. Just use ToString. Your question seems to ask about exporting to a file, maybe copying to the clipboard, but your comment made me suspect that you just want a string. ... – Szabolcs Nov 23 '16 at 10:22
• @Szabolcs What I meant by my comment is that I use Put/PutAppend to write to file, and then some time later, when I want the contents of the the file, I use ReadList. This provides (as far as I can tell) an acceptable solution for me. – Billy Pilgrim Nov 23 '16 at 11:15
• @BillyPilgrim So your real question is how to save Mathematica expressions for later, and not how to format them in a certain way? – Szabolcs Nov 23 '16 at 11:15

Use Export with "Package". Export["file.txt",expr,"Package", "Comments" -> None]
ToString[expr, InputForm]

then write the resulting string to a file. References: ToString, InputForm