OpenOffice

Character Translation Macro

What it is

The code for a macro that allows you to insert your own accented and special characters is attached below. It works in OpenOffice Writer so is usable for all text documents. It's indispensable if you write in more than one language, and invaluable even if you work only in English (as long as you would like to be able to write resumé or Götterdämmerung or Łódź or use «» or ± in your work without struggling to insert the non-English characters).

What it does

Say you want to write the word café . Normally, to insert the character é (e acute) you can either enter Alt+0223 on the numeric pad (remembering to keep NumLock on) or open the Insert menu, select Special character on the sub-menu, then search through the table and click on the letter é. All very time-consuming and error prone.

With this macro installed, you would type e', position the cursor after the apostrophe, then press a shortcut key combination such as Ctrl+shift+z (or some other shortcut of your choosing - I've reassigned F7 and it works beautifully) and the two characters would be removed and replaced by the single letter é.

This is nice and easy to remember and almost impossible to get wrong, but best of all, there are many more letter pairs available – about 130 at the moment. These are just a few of them:

In fact, most European languages using a latin alphabet are covered, including such oddities as the Turkish dotless ı and the Spanish upside down question mark ¿ and the German double-s ß and the Icelandic thorn Þ and so on and so on. Look in this paragraph for more information: character combinations. The definitive list is in the macro itself, found here.

Even better is that you can edit the table in the macro yourself to remove characters you'll never use and add new ones that are particularly useful to you. At the moment for instance there are no mathematical symbols, but if you wanted to add some, or maybe some Greek letters, that would be easy – just decide which memorable pair of characters you want to use then add them and the output character to the table. For example the Greek character µ is already in there, using the letters mu, but to add say pi would be just a matter of inserting pi and its symbol ∏ in the table, and voilà it's there whenever you need it.

Note that this functionality cannot be provided by the OpenOffice autocorrect function. This only operates on whole words, and does a conversion every time it finds the matched characters, even when you don't want it to. The macro operates only when you tell it to, and can operate anywhere in a text document even in the middle of words.

The combinations available

At the moment, the following conventions are observed:

If you make changes I would recommend trying to stick with this scheme or invent a good consistent one of your own - there's no point in having something that's so difficult to remember you have to use the normal lookup table anyway.

How to install it

I am not an expert in macros or OpenOffice so can't say if this is the best way of installing it, but it worked for me. These instructions are for my version of OpenOffice, which is 2.0.2 – I can't answer for other versions, but hopefully it shouldn't be too different.

The first step is to download the macro from here: macro text. Right click on the link, select Save Link as...(Firefox) or Save Target as...(Explorer) and save it on your hard disk somewhere. Then open the file you've just saved, select all the text in it and copy it to the clipboard (under Windows for example, move the cursor to just before the first character of the text, press Ctrl+Shift+End to select to the end of the text, and press Ctrl+c to copy the selected text to the clipboard).

Now, open a new OpenOffice text document using the default template. Go to Tools-Macros-Organise macros-OpenOffice.org Basic... In the resulting dialogue box, in the window called Macro From expand the entry My Macros then select Standard then Module1. Type insertAccentedChar in the box for the name of the macro, and press the New button.

A Basic editor screen will open, with two lines of text. Delete them both and paste in the contents of the clipboard. (In Windows, press Ctrl+a to select all then Ctrl+v to replace it with the new text). Select File-Save on the menus or by pressing the anachronistic floppy disc icon on the toolbar, or, in Windows, pressing Ctrl+s. Close the edit box – the macro is installed.

Making a shortcut key

The macro needs to be bound to a particular keypress combination so you can invoke it when you need it. I use Ctrl+Shift+z but you may prefer something else – there's plenty of choice available. Open Tools+Customise and select the Keyboard tab.

In the Category window find OpenOffice.org macros at the bottom of the list, then click on its little + then the + against User and Standard and select Module1. Your new macro insertAccentedChar should be highlighted in the Function window.

Now go back to the top window Shortcut Keys and scroll down to find the shortcut key combination you want to use to invoke the macro. OpenOffice is unhelpful here and will allow you to reassign keys such as Ctrl+p (which is a Windows standard to print a document) without warning. I would strongly advise not using a simple Ctrl + single character unless you're certain about what it does and are happy to change it. I use Ctrl+Shift+z because it's convenient and is only used in one or two other programs for the 'redo' function. Press Modify and your key combination should appear in the bottom right Keys box. Press OK and you're done.

You could also add a button to one of the toolbars if you preferred. This is done in much the same way – using Tools-Customise then via the Toolbar tab. Choose your toolbar eg Tools, then press add and, as above, point to the macro via the Category window. I leave the rest as an exercise for the reader.

Testing and changing the macro

Testing is easy – just type in a known pair, press the shortcut key, and if it changes, it works. If you've made significant changes to the table it's probably wise to do a fuller test eg make sure that the first and last pairs both still work and that all your changes work, but it's a very simple piece of code and it shouldn't take more than a few minutes to confirm everything's OK.

Making changes is done through the Tools+Macros+Organise Macros+OpenOffice.Org Basic menu series then selecting this macro and pressing Edit. Most changes will just be to add another character pair, remove some redundant ones, or change the mapping to something you find more convenient.

Don't put comments in the table – oo Basic doesn't like it.

Don't forget to save the file when you've finished making changes!

If you want to change the code that's fine, but you're on your own and don't need help from me. If you do anything interesting, let me know.

Updates

The provided set is intended to cover all the languages of the European Union that use a latin alphabet, and Turkish. I believe there may be gaps in Estonian, Latvian, and Lithuanian, which I'm unable to check. The various digraphs such as the Czech 'ch' are not included either as I'm not sure how they are used – in all text, or only in typeset text (like the English ae). Some of the input pairs may not be optimal for native speakers, for example I simply had to guess a combination for the Icelandic letters eth and thorn.

I'd be pleased to receive corrections, but please make sure they're correct – I don't want to waste time trying to sort out abstruse linguistic issues myself. Evidence supporting a suggested change would be a good idea.

Gaps in the table are less urgent, but rational suggestions would also be appreciated.

Last update of this site 20050507