# Export Mathematica code to Word, preserving all formatting

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.

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

The user Szabolcs gave the answer.

Here are the steps:

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)

:)

• @Szabolcs Thank you very much ! – henry Jan 30 '17 at 19:09

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:

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

It works for me.

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

Here are the steps:

• Install MathType Editor
• ctrl+c your formula and paste MathtypeEditor
• ctrl+c your formula in MathtypeEditor
• Open Word: ctrl+v (paste)
• 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? – Kuba Mar 26 '18 at 21:58