What is the best way to include source code / program listings in Writer?

I would like to include some source code into an appendix at the end of my document. Is there any way of doing this?

I thought perhaps screen-shot the code and crop and paste it in… Obviously that is a silly thing to do and it doesn’t look professional. Is there another way?

I also tried pasting in code and formatting it with the monospace font. That looks okay, but there is no syntax highlighting. Is syntax highlighting a possibility? Or am I asking too much?

PS: Code is in C / C++

Textbox way to insert code snippets in word document.

• Insert > Text Box

• Create a textbox size by mouse (this is resizeable later)

• Click at any size of the text box, from properties menu, select fill > colour > choose a colour

• Click the text box, select a font colour

• Start typing

• Finally it should look something like this:- Imgur: The magic of the Internet

The LibreOffice extension center lists a few resources that might help you with this task.

I haven’t used any of these, but with a quick search I was able to find the following extensions:

  1. Code Colorizer Formatter, which shows a warning because it has not had an update in over a year.

  2. COOoder.

Of course, you can always develop your own solution and contribute it[PDF] to the catalogue!

I got a strange error with COOoder, which failed to install, but Code Colorizer Formatter seems to be working well, even if it is a bit old - still works find as far as I can tell.

Thanks for the suggestion!