An alternative search tool for LibreOffice Writer

AltSearch

Article from Issue 253/2021
Author(s):

AltSearch offers extended functionality to LibreOffice Write's default find and replace tools, making it ideal for editing and formatting longer documents.

Few features in a word processor are less glamorous than a search tool. That is, until you do some intensive editing, especially if your revisions include reformatting. Then you will be thankful for a full-featured tool. In the case of LibreOffice Writer, the available tools are barely adequate, which is why I recommend the Alternative Find & Replace for Writer extension, also known as AltSearch [1].

Like all LibreOffice extensions, AltSearch is easily installed. Just download it from the LibreOffice extension site, and open Tools | Extension Manager. The next time you start Writer, AltSearch appears as a menu item, as well as an icon with green binoculars in the upper left corner of the toolbar.

You can understand the need for AltSearch by examining the default search tools in Writer. Edit | Find is a simple field similar to the ones found in many web browsers. It is suitable for finding words and phrases, but its options are strictly limited. You can search backward or forward from your present location in a document, find all, or match case – and that's all (Figure 1).

Figure 1: Find is Writer's basic search tool. For many purposes, it is too simple.

Edit | Find & Replace is more versatile, but it, too, is relatively limited. It can match case or search for whole words only. It has several additional features, such as support for regular expressions, similarity, and searches on a half-dozen paragraph styles, which make it more useful than Find – although you must be careful not to replace the Find field's contents with nothing if you use the tool just to search (Figure 2).

Figure 2: Find & Replace is an improvement over Find but is still fairly basic.

Another default tool, Navigator, which you open from the sidebar, allows searching by any object in the document, most usefully by six paragraph style headings, and even lets you reposition text below the headings without cutting and pasting (Figure 3) – but that is all. All three default tools are focused on finding and have limited power to edit.

Figure 3: Navigator is useful for finding objects in a document but is separate from the other find tools.

By contrast, AltSearch offers more options (Figure 4). Admittedly, it suffers from some misspellings in the menus and is awkward to use. In particular, the menus are so long that it is best to position the window as close to the upper left corner of the screen as possible. However, most of the menu items include online help, and AltSearch's capabilities make the inconvenience worth enduring.

Figure 4: AltSearch is as much an editing tool as another search tool.

To start with, AltSearch's main window is better organized than Writer's default tools, with much of the complexity hidden. You can easily replace the default tools with AltSearch without delving into its complexities. But if you do take a closer look at AltSearch, you will find several important improvements.

For example, although Find supports standard regular expressions, it leaves the user to decide which ones to use. In comparison, AltSearch offers a selection window that includes custom expressions for formatting, such as custom hyphens and non-breaking dashes (Figure 5).

Figure 5: AltSearch's list of useful regular expressions.

In addition, AltSearch offers a list of extended regular expressions (Figure 6) that, among other things, allows searches for most of the objects displayed in Navigator, including images, tables, frames, and cross references – a combination of features so basic I'm surprised that Writer did not do the same years ago. Other extended regular expressions include hyperlinks, text inside parentheses, and HTML tags.

Figure 6: AltSearch's list of extended expressions.

Similarly, while the default tools only support basic paragraph styles, AltSearch's properties not only support character and list styles, but they can search on any of these styles used in the document rather than a basic few (Figure 7). Moreover, should these choices be overwhelming, you can run AltSearch on the basis of the text you select with the cursor. All these options greatly increase the chance of pinpointing a search item quickly, which is especially welcome in longer documents.

Figure 7: AltSearch lets you search on character and list styles.

These options are not just useful in searches. They can also be useful in turning AltSearch into the desktop equivalent of the sed command. For example, if you save a Writer document that uses styles into text format, the conversion eliminates the indentation of a new paragraph, as well as any space between paragraphs. Adding spaces between paragraphs manually is tedious, but with AltSearch you can search for paragraph breaks with /p and replace them with a paragraph break and an empty new line (/p/n), preparing the text version of the document within seconds. If you want the extra space only in a list style, you can specify the style as well. In much the same way, you can easily remove non-breaking spaces or hyphens by replacing them with nothing and find a character string at the start (/<) or end of a word (/>).

In addition, AltSearch can perform a search or a replace that contains more than one paragraph, or it can define a start and end point for a search. Both search and replace can be added from the clipboard, which is particularly useful with a clipboard that supports multiple entries. Styles can be replaced with another of the same kind, and objects can be renamed for easier navigation.

Perhaps AltSearch's most important single feature is the ability to do multiple searches via a batch file. The Batch manager opens with a list of some basic editing tasks, ranging from converting to a cleaner version of HTML than is available in Writer, converting date formats, or writing all of one kind of object to a new file (Figure 8). However, these are only samples of tasks that you can add to a batch file. From the Batch manager window, you can open the text editor of your choice and construct files that perform as many functions as you choose. When completed, a batch file can be executed and saved for later use. This function is especially useful in a longer project such as a book or thesis, where you might have many files that need to be edited in the same way because they will eventually be combined into a single work.

Figure 8: Users can write their own batch files to perform multiple functions all at once.

Conclusion

All this functionality takes a while to learn. Online help [2] exists, but it is more than a decade old and only marginally more detailed than the help built into the interface. For that matter, AltSearch itself seems not to have had a release for at least as long. So far, AltSearch continues to work, but a time may come when the latest LibreOffice release no longer supports it. If that ever happens, it would be a crippling blow to Writer's functionality, not just for search and replace but for serious editing as well. AltSearch is an extension that, like others before it, deserves to be a default part of the LibreOffice code. In fact, maybe someday, a version will be released for LibreOffice Calc as well.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News