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!";
Cooder
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.
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.
UPDATE 2: LibreOffice Extension
I have published my previous macro script as an extension: Code Highlighter which is available in LibreOffice Extensions store.
1. How to install?
Follow these steps to install the extension:
Step 1: Install libreoffice-script-provider-python:
Step 2: Install pygments for Python 3:
Step 3: Download and add the codehighlighter.oxt extension to Libre Office
2. How to use?
You can assign keyboard shortcuts for frequently used languages. To see how to assign keyboard shortcut, visit the Git Hub page: libreoffice-code-highlighter
I leave my original answer here since it is still valid for LO <= 5.
I had the same requirement and none of these solutions worked for me in LibreOffice 5 except 'Code Colorizer Formatter'. But Code Colorizer Formatter worked in Writer only (I also needed for Impress). Later I found another solution using Python macro which is tested in LibreOffice 5.
Installation
Step 1: Install libreoffice-script-provider-python:
Step 2: Install pygments for Python 3:
Step 3: Download Highlight.py
Step 4: Copy the Highlight.py to /usr/lib/libreoffice/share/Scripts/python/
Step 5: Set the Read-Only permission to the script.
Step 6: Open the LibreOffice Writer and goto Tools -> Customize -> Keyboard
Usage
LibreOffice Impress
code-<language>
LibreOffice Writer/Calc
code-<language>
UPDATE 1:
I have added custom style support to this extension. Use
code-<language>
for default style andcode-<language>-<style>
for custom style. Available styles are listed in my Git Hub page.For example,
Code-Java-Emacs
will color the Java code using Emacs style.COOder
COOder seems to be abandoned, and it can't be installed in LibreOffice 4.2.8.2.
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:
Download Code Colorizer Formatter from Code Colorizer Formatter project homepage and install it in LibreOffice Writer like any other LibreOffice extension.
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.
Select the code to be colorized.
Select Tools -> Macros -> Organize Macros -> LibreOffice Basic.
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.
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.
Click the Run button to colorize the selected code.
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:
Then copy-paste this code:
Finally bind that to a hot key:
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!).
I got tired of formatting my code on an online page and wanted to get my code styled inside LibreOffice or OpenOffice writer.
I found out that the extension "cooder" runs properly on my LibreOffice 5.* even if the install of it seemed to fail (My LibreOffice 5.* suspended while installation).
In the Extension-Manager you can activate the Cooder, restart LibreOffice/NeoOffice/OpenOffice an you should see a new Symbol that you can use to style your sourcecode inside LibreOffice.
You can download the extension at: http://extensions.libreoffice.org/extension-center/coooder
To format code in libreoffice-impress I followed Drake Clarris approach (tohtml) pasting first to a libreoffice writer document and then copy paste to the slide.