Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mathematica code in email and keeping formatting the same as notebook

As we all know, when one is to send email with some Mathematica code in it, the practice is to do the following

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

Then paste the code into the email, or any other exchange media it is.

The only problem with the above, is that when, on the other end, one copies the text from email and paste it back into a Mathematica notebook, the code will then no longer appear as it was in the original form (before the converting to INPUT FORM).

Because when one inserts the text copied from the email to Mathematica notebook, it becomes a standard form cell. All well, except the original code formatting is all lost.

Try it if you have not, convert a cell to INPUT FORM and the code will change shape, and I could not find a way to get back the original form before this operation.

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

Thanks --Nasser

like image 818
Nasser Avatar asked May 28 '11 06:05

Nasser


People also ask

How do you write a notebook in Mathematica?

When Mathematica is first started, it displays an empty notebook with a blinking cursor. You can start typing right away. Mathematica by default will interpret your text as input. You enter Mathematica input into the notebook, then type Shift +Return to make Mathematica process your input.

How do you make a header in Mathematica?

Add a Title cell to your notebook by choosing Format ▶ Style ▶ Title: Note that the cursor that appears in the Title cell is very large. Type in a title for your notebook: Next, click below the Title cell and add a section header by using the Format ▶ Style ▶ Section menu item.

Can you write LaTeX in Mathematica?

Create LaTeX code from arbitrary Mathematica expressions: The Mathematica function TeXForm produces a LaTeX representation of a syntactically correct expression, often trying to apply conventional typesetting rules. The result looks similar but not identical to TraditionalForm output.

What is a Mathematica notebook?

File Extensions and MIME Types Wolfram Notebooks are structured interactive documents that may contain text, graphics, sound, calculations, typeset expressions, and user interface elements. Notebooks have the file extension . nb and can be accessed and edited on the desktop, mobile, and cloud devices.


2 Answers

Cells formatted with the Code style (ALT/CMD-8) retain all formatting when using copy-and-paste. I use them all the time to format postings for SO. Well, truth be told, I use Code cells pretty much all the time, except for one-shot or throw-away input.

There are other advantages to using the Code style. It makes it easy to evaluate all of the definitions in a notebook, without also evaluating all of the incidental and test expressions: ALT/CMD-click on the cell bracket of any of the Code cells and then press SHIFT-ENTER. Also, Code cells automatically become initialization cells, which is frequently exactly what you want for the definitions in a notebook. Finally, when Mathematica spots Code cells in a notebook it offers to create an auto-save package that contains only those cells.

The downside to Code cells is that you lose the automatic formatting that Mathematica performs on cells with the Input style -- but then again that automatic formatting is precisely what we are trying to avoid in the context of this question.

like image 175
WReach Avatar answered Nov 28 '22 21:11

WReach


Copying the cell as a cell expression doest the trick. Just right-click the cell bracket and the Copy as > Cell expression.

The resulting code is unusable for posting in newsgroups, as it is highly unreadable, but copying to and from email and back into Mathematica seems to preserve layout in the few tests that I did.

like image 40
Sjoerd C. de Vries Avatar answered Nov 28 '22 21:11

Sjoerd C. de Vries