Formatting code snippets in OpenOffice Writer documents
If you ever have the need to provide code samples within the constraints of a typical, word-processed, A4 document template, the following tip might help.
As anyone who uses OpenOffice’s formatting styles will know, Writer has a basic “Teletype” style which can be used as-is, or customized to suit for formatting code snippets. However, one problem that often occurs is that when inserting code snippets into such documents, even with the Teletype style’s monospace font set to a relatively small point size, you still often run out of horizontal space within the confines of the A4 template — and statements end up containing arbitrary breaks and wrap onto the subsequent line, often leaving the code sample hard to read.
One method for alleviating the effects of this is to use a book publisher-style “line continuatation” character, such as or, if you’ve forgotten your reading glasses:
Using this character you can avoid awkward to read snippets such as this:
function listusers()
{
$this->set('userlist', $this->User->findAll(null, array('id',
'username', 'first_name', 'last_name'), 'id DESC'));
}
or monstrosities like this:
function listusers()
{
$this->set(
'userlist',
$this->User->findAll(
null,
array(
'id',
'username',
'first_name',
'last_name'
),
'id DESC'
)
);
}
using instead the rather more elegant (from a word processing point of view, at least):
function listusers()
{
$this->set('userlist', $this->User->findAll(null,
array('id', 'username', 'first_name',
'last_name'), 'id DESC'));
}
Obviously, a solution is only useful if it’s easy to apply and so creating a macro to simplify the insertion of the character is helpful. If you have never created a macro using OpenOffice, worry not, it really couldn’t be simpler. Just go Tools > Macros > Record Macros, then select the line continuation character (Insert > Special Character, select the OpenSymbol character set, locate the line continuation arrow (Unicode code point: U+E48C) and insert, then simply click the “Stop Recording” macro button which will be floating around somewhere over your document window. You will then be asked to give the macro a name and save it.
So far so good, this has helped, but needing to manually select the macro each time you need it will still be an embuggerance. The solution is obvious enough, just assign a keyboard shortcut to the macro. To do this, go Tools > Customise > Keyboard, select the macro’s container within the Category pane, select the macro itself within the Function pane, select the keyboard shortcut you wish to use from the Shortcut keys pane, and that shortcut should automatically appear within the Keys pane. Click OK and Bob’s yer uncle. One DTP-style line continuation character ready to go. Simple, innit?
Footnotes:
- “Line continuation character” is just the name I use. I’ve no idea what the official name for is!
- The notes above are relevant forOpenOffice v.2.4 at least.
Tags: OpenOffice