
Now your code is ready to be pasted into Microsoft word.
Select the syntax-highlighted code and click copy. If you want to keep the line numbers, go to next step. Then, under styles, deselect the "margin" property in ".dp-highlighter ol", as shown in the image below. To Turn off the line numbers, inspect the page in chrome. It will open a new tab, with syntax-highlighted code snippet, in this case the XML sample we chose. Select the language from drop down menu. I will be using a sample XML to demonstrate this (XML sample from here - ). Open the website provided above in chrome and Copy the code snippet in the text area.
Steps to achieve syntax highlighting are listed below: This gives me the option to use line number, as well as very nice syntax highlighting (Please use Google Chrome for this step, because syntax highlight is not copied when using Mozilla Firefox, as also pointed out by couple of user comments). One could use notepad plus plus as described above.
Use external tool to achieve syntax highlighting requirement 1 above. Code snippet shall have spell-check disabled. Code snippet shall break across pages smoothly without any extra effort. Code snippet shall be inline with other text.
Add code snippets to a word document, with syntax highlighting for easier visibility and differentiation of code and other text. Hopefully, the answer would be useful to someone. The post is longer than I would have liked, but I believe screenshots are always helpful. I am sharing the approach and my reasoning of why I chose this approach. However, I ended up using an entirely different approach which suited my needs. I recently came across this post and found some useful hints. Is there some better (and ideally portable) way to do this? Is there at least some sort of verbatim style similar to the LaTeX environment? Is there at least some pretty printer that I could copy-and-paste as RTF?
My examples are primarily in Java.Īs someone who is used to LaTeX, doing this in Word is extremely painful.
Some of the examples will be written from the IDE, and others would be written in place. I have to write some documents that will include source code examples.