14
$\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$
18
  • 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, 2017 at 18:47
  • 2
    $\begingroup$ Depending on how much editing you want to do, there's also "Save as...RTF". $\endgroup$
    – JimB
    Jan 29, 2017 at 19:07
  • $\begingroup$ @Jim Baldwin I tried that, but ist not working for me... $\endgroup$
    – henry
    Jan 30, 2017 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, 2017 at 7:41
  • 5
    $\begingroup$ You could always use $\LaTeX$ and forget about word altogether :) $\endgroup$
    – Nasser
    Jan 30, 2017 at 7:44

3 Answers 3

12
$\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$
2
  • $\begingroup$ @Szabolcs Thank you very much ! $\endgroup$
    – henry
    Jan 30, 2017 at 19:09
  • 2
    $\begingroup$ I cannot find the option 'Metafile' on any of my menus. $\endgroup$
    – OKCarl
    Mar 29, 2022 at 4:34
6
$\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$
7
  • 5
    $\begingroup$ I don't think that's really viable. Formatting is not retained in any but the simplest of cases. $\endgroup$
    – MarcoB
    Jan 30, 2017 at 8:29
  • $\begingroup$ @ MarcoB Please have a look to the edit to my answer. $\endgroup$ Jan 30, 2017 at 12:11
  • $\begingroup$ Can you also copy functions like NDSolve[...] with the right coloring, spacing, etc ? $\endgroup$
    – henry
    Jan 30, 2017 at 12:41
  • $\begingroup$ @DoHe No, coloring does not hold. The question has been, however, different. It was only about mathematical formulas. $\endgroup$ Jan 30, 2017 at 13:02
  • 1
    $\begingroup$ okay, thanks a lot.:) My question however concerns the entire Code. $\endgroup$
    – henry
    Jan 30, 2017 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$
4
  • 1
    $\begingroup$ Does it address syntax highlighting, indentation and fonts? $\endgroup$
    – Kuba
    Mar 26, 2018 at 20:01
  • $\begingroup$ Yes, MathType Editor correspond to MS Office. You can easily try it. $\endgroup$ Mar 26, 2018 at 21:32
  • 1
    $\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, 2018 at 21:58
  • 1
    $\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, 2018 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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