Preformatted text in Writer: How do I break long words?

Hello,

I want to display script output in LibreOffice Writer. I created a new style which uses a monospace font.

Now the text contains many long words. I want Writer to split words at the end of the line. For example, take this line:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

Hopefully, you can see that all b’s are put on a new line. I want Writer to look like this website’s preformatted text:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

There is no real satisfactory solution.

My workaround is to replace the spaces U+0020 SPACE by non-breaking spaces U+00A0 NO-BREAK SPACE. Since you are in monospace font, both characters have the same width and this does not change the general appearance of the output.

Your lines (paragraph) are the a single huge word and Writer will split at end of line.

Note: with my Linux keyboard handler, the no-break space is Ctrl+Shift+Space. This is handy to type it in Edit>Find & Replace.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

In case you need clarification, edit your question (not an answer) or comment the relevant answer.

Thanks for the answer. I wish there was a better way to get preformatted text. However, replacing all spaces with non-breaking spaces improves the style quite a bit.

To have all automatic line breaks always occur at the edge, you need to defeat the word wrap. The only way I see is to replace all word delimiting characters by non-breaking variants.

For space and hyphen, hold ctrl+shift to type the non-breaking character. If you need to fix large text sections, you can use find/replace. You can’t type the non-breaking character into the replace field on all systems, but you can copy from your document and paste into the field. (Make one manual replacement, and copy from that.)

I am not aware that replacements exist for characters other than space and hyphen. E.g. pipe, exclamation mark and percent (|!%) are characters which - to Writer - constitute a word break, and which occur frequently in various coding contexts. Someone else may know a way.