Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently wrote a repport for school with a lot of code in it. The only way I found to wrok was to highlight it with STRONG and that is really quite ugly. So is there a code highlightning extension for libre office writer?

Like this one below:

<insert code here>

A syntax highlight with different colors is also ok.
I never enter a whole program so I need to be able to highligt what I think is code.

Like this one: echo "Hello World!";


I presonally didn't like this highlight since it formats the text and all the text that comes after. I want to mark some text then click on a highlight and that's it.
This one is too complicated and hard to use, I have to select programming language each time I highlight which will be about 100 times in one report, that's way too much.
I would like something similar to what they use on the site. simple code highlight if you will.

Code Colorizer Formatter

It installs for me, but I can't get it to work and it doesn't have PHP or HTML support, which I need.

share|improve this question
added as an answer, glad it helped – Drake Clarris May 29 '13 at 14:10
I recommend using LaTeX (see example). Before I've used latex, I saved the source as HTML with KDE Kate and copied the rendered code from a browser to open office – Martin Thoma Jun 3 '13 at 12:51
@Moose why do you add this as a comment instead of an answer? explain all the steps too thanks. – Alvar Jun 3 '13 at 19:31
up vote 9 down vote accepted

It's not a plug-in, but I put the code into a website that colors syntax for you. The site I use is tohtml. I don't use the html generated code however, I just copy the colored and highlighted code from the browser and paste it into my document and WYSIWYG.

share|improve this answer
Copying didn't work for me from Firefox to Libroffice, though saving as HTML and opening the file in Libreoffice then copying did work – Wilf May 11 '15 at 19:43
copy+paste worked on ubuntu from chrome to libreoffice! thanks! – rrosa Sep 10 '15 at 4:10


COOder seems to be abandoned, and it can't be installed in LibreOffice

Code Colorizer Formatter

Code Colorizer Formatter installs and works correctly in LibreOffice. Code Colorizer Formatter has also added PHP support, but HTML support is missing completely and JavaScript didn't work when I tested it. The instructions for how to get it to work on the Code Colorizer Formatter website didn't work for me, however I've gotten Code Colorizer Formatter to work in LibreOffice the hard way, and here are my instructions:

  1. Download Code Colorizer Formatter and install it in LibreOffice Writer like any other LibreOffice extension.

  2. Open your code file in LibreOffice Writer. Code Colorizer Formatter supports Bash, Basic, C++, Java, Perl, PHP, Python, R, SQL, XML, C#, 8085 Assembler, and x86 Assembler.

  3. Select the code to be colorized.

  4. Select Tools -> Macros -> Organize Macros -> LibreOffice Basic.

  5. A new LibreOffice Basic Macros window will open. Under the Macro from heading, select My Macros -> MacroFormatterADP -> a supported programming language. In the screenshot below, Java is selected.

  6. Under the Existing macros in... heading, select HighlightSelLanguage where Language in HighlightSelLanguage is the same as the programming language that was selected in step five. In the screenshot below, HighlightSelJava is selected.

  7. Click the Run button to colorize the selected code.

enter image description here

share|improve this answer
Seems abandoned, going to the extensions section in LibreOffice says it hasn't had an update in over a year – Purefan May 4 '15 at 7:51

I had the same requirement and none of these solutions worked for me in LibreOffice 5 except 'Code Colorizer Formatter'. But Code Colorizer Formatter also worked in Writer only (I also needed for Impress). Later I found another solution using Python macro which is tested in LibreOffice 5.


Step 1: Install libreoffice-script-provider-python:

sudo apt-get install libreoffice-script-provider-python

Step 2: Install pygments for Python 3:

sudo pip3 install python3-pygments

Step 3: Download

Step 4: Copy the to /usr/lib/libreoffice/share/Scripts/python/

sudo cp /usr/lib/libreoffice/share/Scripts/python/

Step 5: Set the Read-Only permission to the script.

sudo chmod 0444 /usr/lib/libreoffice/share/Scripts/python/

Step 6: Open the LibreOffice Writer and goto Tools -> Customize -> Keyboard

  • Select the LibreOffice option button (Available on top left corner)
  • Select any desired shortcut
  • Select share/Highlight/Highlight_source_code under the Functions Category
  • Click on the Modify button to set the shortcut


LibreOffice Impress

  • Open LibreOffice Impress.
  • Insert a Text Box (Insert -> Text Box).
  • Copy and paste any code snippet into that Text Box.
  • Create a new Style (Right click on an existing style -> New...)
  • Name the Style as code-<language>
  • Apply the style to your code snippet Text Box.
  • Select the Text Box.
  • Use your shortcut keys to execute the macro.

LibreOffice Writer/Calc

  • Open LibreOffice Writer/Calc.
  • Insert a Text Box (Insert -> Text Box).
  • Copy and paste any code snippet into that Text Box.
  • Right click on the Text Box and select 'Description'.
  • Add a description in the following format: code-<language>
  • Select the Text Box
  • Use your shortcut keys to execute the macro.


I have added custom style support to this extension. Use code-<language> for default style and code-<language>-<style> for custom style. Available styles are listed in my Git Hub page.

For example Code-Java-Emacs will colorize the Java code using Emacs style.

For more details, visit to the Git Hub link: libreoffice-code-highlighter

share|improve this answer
This works quite nicely, thanks! How can I change the pygments theme? – greschd Nov 30 '15 at 8:36
Please check the updated post. I have updated my script to support custom styles. You need to upgrade the script, in-order to use this new feature. – Gobinath Nov 30 '15 at 12:35
Nice, thanks. One thing still bothers me -- when I just saved the file and then try to execute the macro, it resets the text to some earlier version. Do you know why this is and if it could be fixed easily? – greschd Dec 1 '15 at 12:48
I haven't faced such a problem. Could you please let me to know the exact steps to reproduce this issue? – Gobinath Dec 1 '15 at 14:43
(in Impress): I edit some code in a text box I had already formatted previously, save the document (Ctrl + S), select the text box, try highlighting (Ctrl + Shift + H), and it resets some of the text I wrote – greschd Dec 1 '15 at 20:16

I have to select programming language each time I highlight which will be about 100 times in one report, that's way too much

Actually there's a way to bind coloring in a given language to a hot key. Make the following sub and bind it to a hot key:

Go to Tools → Macros → Organaize macros → LibreOffice Basic. Select Module1 and press Edit:

enter image description here

Then copy-paste this code:

Sub COOoderInPython
End Sub

Sub ExecuteCOOoder(sLanguage As String)
  oLanguage = org.openoffice.coooder.theLanguagesManager.get(GetDefaultContext()).getLanguage(sLanguage)
  If NOT isNull(oLanguage) Then
    oHighlighter = CreateUnoService("org.openoffice.coooder.Highlighter")
    oHighlighter.Language = oLanguage
  End If
End Sub

Finally bind that to a hot key:

enter image description here

share|improve this answer

One that I know of, but seems to be abandoned, is Code Colorizer Formatter.

I don't know if it still works in LO 4, but it might be worth for you to give it a try (or to rescue and bring up to date!).

share|improve this answer
Code Colorizer Formatter was updated on March 1, 2015 with support up to LibreOffice 4.4 for many programming languages including PHP. I tested Code Colorizer Formatter on LibreOffice 4.2. The instructions on the official Code Colorizer Formatter website didn't work for me, so I put my own instructions for using Code Colorizer Formatter in my answer. – karel May 4 '15 at 10:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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