LibreOffice Writer - How to format text as code?

Is is possible to put code snippets into an OpenDocument Text file (.odt) file? I want it to be inside a bordered box, etc...

And I would like to know whether there is any way to add plugins to LibreOffice Writer?

7

2 Answers

See the following images to know how to create a text-box.

Click the icon with an A with a vertical bar next to it:enter image description here

Type whatever code you want to put in the box and then right-click on the border on the box. Select Line from the menu.enter image description here

Select the style you want for the box's border and click ok.

enter image description here

2

IMO it's better to use "Insert > Frame > Frame..." -- do not use a text box.

Several reasons:

  • Text in frames can use paragraph styles. Text that you enter into a text box may be formatted only by hand. If it's a large document, you will want to create a paragraph style for code, and use the paragraph style instead of direct formatting. Suppose you need to change the code font later. If you used styles, you can change the style and all code examples update. If you used text boxes and direct formatting, you will have to edit every text box by hand. Not recommended.

  • AFAICS normal paragraph text automatically avoids frames, whereas, when I tried text boxes, I had to set text wrapping manually.

The point about styles is important. Styles are underused, but IMO if you're working on anything longer than, oh, 4 or 5 pages, the time you spend setting up styles will pay off many times over. Avoid LO features (like text boxes) that don't support styles.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like