12
$\begingroup$

How can I transfer code from a Mathematica notebook to a Microsoft Word document in a way that all formatting I see in the notebook is preserved?

I want to preserve the font, the indentation and the syntax colouring.

I am using Mathematica on Windows.

$\endgroup$
  • 2
    $\begingroup$ You might consider library.wolfram.com/infocenter/Demos/5698 written by Mike Honeychurch. I don't know if the described process still works (as it was written in 2005). $\endgroup$ – JimB Jan 29 '17 at 18:47
  • 2
    $\begingroup$ Depending on how much editing you want to do, there's also "Save as...RTF". $\endgroup$ – JimB Jan 29 '17 at 19:07
  • $\begingroup$ @Jim Baldwin I tried that, but ist not working for me... $\endgroup$ – henry Jan 30 '17 at 7:21
  • $\begingroup$ You can save the notebook as web-page and further open it by Word. However, modern versions of MS Word has a lot of security restrictions preventing the evaluation of an active content of web-pages and other files. So, you may be need to switch off some of the security settings to open this web-page for edition in Word. But it is fully possible. The rtf-version of the notebook appears too ugly.. $\endgroup$ – Rom38 Jan 30 '17 at 7:41
  • 4
    $\begingroup$ You could always use $\LaTeX$ and forget about word altogether :) $\endgroup$ – Nasser Jan 30 '17 at 7:44
8
$\begingroup$

The user Szabolcs gave the answer.

Here are the steps:

  1. Open your Mathematica Notebook
  2. Ctrl+A, if you want to selct all your cells or simply select your desired cells
  3. Go to: Edit -> Copy as -> Metafile
  4. Open Word: Ctrl+V (paste)

:)

$\endgroup$
  • $\begingroup$ @Szabolcs Thank you very much ! $\endgroup$ – henry Jan 30 '17 at 19:09
3
$\begingroup$

You can copy-as-MathML from Mathematica directly into Word. Have fun! Edit

To address your comment. This is a fragment of my Mathematica notebook:

enter image description here

These are the corresponding formulas inserted into the Formel Editor of Word 2013

enter image description here

It works for me.

$\endgroup$
  • 3
    $\begingroup$ I don't think that's really viable. Formatting is not retained in any but the simplest of cases. $\endgroup$ – MarcoB Jan 30 '17 at 8:29
  • $\begingroup$ @ MarcoB Please have a look to the edit to my answer. $\endgroup$ – Alexei Boulbitch Jan 30 '17 at 12:11
  • $\begingroup$ Can you also copy functions like NDSolve[...] with the right coloring, spacing, etc ? $\endgroup$ – henry Jan 30 '17 at 12:41
  • $\begingroup$ @DoHe No, coloring does not hold. The question has been, however, different. It was only about mathematical formulas. $\endgroup$ – Alexei Boulbitch Jan 30 '17 at 13:02
  • $\begingroup$ okay, thanks a lot.:) My question however concerns the entire Code. $\endgroup$ – henry Jan 30 '17 at 14:36
1
$\begingroup$

enter image description hereHere are the steps:

  • Install MathType Editor
  • Open your Mathematica Notebook
  • ctrl+c your formula and paste MathtypeEditor
  • ctrl+c your formula in MathtypeEditor
  • Open Word: ctrl+v (paste)
  • You can also arrange your formula in Word.
$\endgroup$
  • $\begingroup$ Does it address syntax highlighting, indentation and fonts? $\endgroup$ – Kuba Mar 26 '18 at 20:01
  • $\begingroup$ Yes, MathType Editor correspond to MS Office. You can easily try it. $\endgroup$ – Sinan Emre Çankaya Mar 26 '18 at 21:32
  • $\begingroup$ I know what it is about. But I don't see how syntax highlighting information is supposed to be preserved here. Can you show an example, with let's say Module[{x}, x] and x highlighted? $\endgroup$ – Kuba Mar 26 '18 at 21:58
  • $\begingroup$ As you can see relative font sizes are not preserved, neither indentation. There is not syntax highlighting so can't judge by the image. $\endgroup$ – Kuba Mar 27 '18 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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