How to get code block with syntax highlighting into LibreOffice Writer
15,366
Libreoffice extensions
There are several extensions that allow to highlight a code snippet.
You can search for them in extensions.libreoffice.org.
Among the others
The steps to follow are usually as easy as
- Insert a new Text Box (Insert -> Text Box)
- Copy and paste/write your code snippet into the text box (You can choose any fonts based on your preference)
- Select the text box
- Go to Tools -> Highlight Code -> Language of the code
(From Code Highlighter)
You may need to install
sudo apt install libreoffice-script-provider-python python3-pip
sudo pip3 install pygments
Related videos on Youtube
Author by
user2891462
Updated on September 18, 2022Comments
-
user2891462 almost 2 years
I am using Linux. I want to write small pieces of code and paste them into LibreOffice Writer. I do not care too much about which code editor to use, although preferably it would be ViM or Sublime Text 3.
I have tried several avenues, but all of them are unsuccessful:
- Write the code in ViM and save them as HTML with
TOhtml
. Then, open the HTML file with Firefox, copy the code and paste it in LibreOffice with Paste Special/HTML. The colors are gone, though. - Write the code in Sublime Text 3 and export it using the SublimeHighlight module. I can copy the text as RTF/HTML, but when pasting it in LibreOffice it pastes the literal HTML code. Paste Special didn't solve it either.
How can one paste HTML/RTF code into LibreOffice Writer?
Running Xubuntu 16.04 and
LibreOffice 5.1.6.2 10m0(Build:2)
- Write the code in ViM and save them as HTML with
-
Hastur over 4 yearsNote that if instead you decide to use LaTex for a better result, there are macro that will work fine for you in that case too.
-
einpoklum about 3 yearscode highlighter gives me an error message when trying to highlight
-
Bodo about 3 years@einpoklum If you want to get help regarding this error it would be better to write a separate question with a reference to this answer and describe your environment and show the input and the exact error message.
-
Hastur about 3 years@einpoklum And maybe add the libreoffice, python, pygments versions too
:-)
-
einpoklum about 3 years
-
Hastur about 3 years@einpoklum Good an open bug. Let's hope someone will take it in charge and solve it... I did not write this app I just used (to be honest few, because I prefer to use LaTex ;-) ). BTW It seems there is a fix: And renaming before installing, the downloaded extension's file name to codehighlighter.oxt, is the solution.. Give it a look if it works for you.