The mathematical code in the email and saving the format is the same as the notebook

As we all know, when you need to send an email with some Mathematica code, the practice is as follows:

Select a cell, Cell-> ConvertTo → INPUT FORM, then COPY AS TEXT

Then paste the code into email or any other exchange medium.

The only problem with the above is that when the text from the email is copied to the other end and pasted back into the Mathematica notebook, the code will no longer be displayed as it was in the original form (before conversion to INPUT FORM).

Because when one inserts the text copied from the letter into the Mathematica notebook, it becomes a standard form cell. Everything is good, except for the original formatting of the code, everything is lost.

Try, if you didn’t, convert the cell to INPUT FORM, and the code will change the form, and I could not find a way to return the original form to this operation.

Is there a way to write Mathematica code in the text, of course, so that it retains the same shape and looks the same as it was originally when it was in standard form before conversion?

Thanks --Nasser

+7
source share
3 answers

Cells formatted in code style (ALT / CMD-8) retain all formatting when using copy and paste. I use them all the time to format messages for SO. Well, the truth is, they told me that I use code cells almost all the time, with the exception of one-time or discarded input.

There are other benefits to using a code style. This makes it easy to evaluate all the definitions in the notebook, without also evaluating all the random and test expressions: ALT / CMD-click on the cell bracket of any of the code cells, and then press SHIFT-ENTER. In addition, code cells automatically become initialization cells, which is often what you want for definitions in a laptop. Finally, when Mathematica places code cells in a notebook, he suggests creating an automatic save package containing only those cells.

The downside of code cells is that you lose the automatic formatting that Mathematica does on cells with an input style - but again, that automatic formatting is exactly what we are trying to avoid in the context of this question.

+7
source

Copying a cell as a cell expression does the trick. Just right click on the cell and Copy as > Cell expression .

The resulting code is not suitable for publication in newsgroups, as it is very unreadable, but copying to e-mail and vice versa in Mathematica seems to save the layout in several tests that I did.

+2
source

Since the problem sends the code by email, why not just send (part) of the laptop as an attachment. No copy paste and guaranteed uniform formatting.

0
source

All Articles