LibreOffice Writer power tools: Conditional text
Conditional text in LibreOffice Writer refers to text that changes according to circumstances you set. Conditional text can both simplify the use of paragraph styles and offer a solution to one of the biggest challenges in technical documentation: how to single-source, or maintain, multiple copies of a document within the same file.
Single-sourcing files is routine in technical documentation. For example, you might want separate manuals or how-tos for average users, developers, and system administrators. Each section may use some of the same text, but go into details that are only of interest for one particular audience. Or you might want separate trainer and student guides, with trainers getting answers to quizzes and extra sections for instructions.
In such circumstances, maintaining two separate files means twice the maintenance and revision effort, and the two versions could get out of sync. As an alternative you could work from a copy of a single file, then delete passages irrelevant to the audience for which you are printing, but that is equally hit or miss. Instead, by choosing the right conditional text features, you can automate the process of single-sourcing, making it quick and reliable.
Creating a multi-purpose style
In its simplest use, conditional text makes applying paragraph styles more flexible. Instead of changing the paragraph style manually when you reach a certain circumstance, you can set up a paragraph style whose formatting changes automatically.
To set up this kind of conditional text:
- Press the F11 key to open the Styles and Formatting Window, and either select the Text Body paragraph style or create a new one. Among the predefined styles in LibreOffice Writer only Text Body can be modified to support conditional text.
- On the Condition tab for the style you are using, choose a Context from the left pane, then click a paragraph style from the right pane so it appears as an Applied style in the left. In the Context mentioned, the paragraph style you are setting up will automatically format in the same way as the Applied style you have chosen. If you change the formatting of the applied style or choose another applied style, the style using conditional text will automatically change as well.
- Repeat this process for every other context you want to set up. When you have done so, you will no longer have to switch styles as you work. Instead, the formatting will change automatically as you move from one context to another.
The one inconvenience of creating such a paragraph style is that, if used with outline levels, it will complicate the use of features such as tables of content that rely on particular styles. However, you can work around this inconvenience by manually adding markers from which to create the table of contents, and the efficiency of the conditional style can more than compensate for the extra work, especially in short documents.
Adding variable text phrases
When single-sourcing, you may need to change phrases to make a passage suitable to your audience. For instance, you might want a header in a training manual to read "Advice for Trainers" in one manual and "Advice for Students" in another.
You can change phrases by setting up a conditional text field:
- Make sure that View -> Field Shadings is selected. Otherwise, you have no way of seeing where a field is applied.
- Select Insert -> Fields -> Other -> Functions -> Hidden Text.
- Set the Condition field to 1, and in the Then field, enter the text to display when the Condition field is set to 1.
- In the Other field, enter the text to display when the Condition field is set to 0, or any number other than 1.
- Press the Insert key to add the field to the text. The settings are saved automatically, and if neccessary you can move to another position and create a new field simply by overwriting the settings.
To change the condition, click on text with the shading that indicates a field to open the dialogue window. Use the arrow keys in the window to move to the next conditional text field.
If you need more than two conditions, use an input list instead. An input list can contain any number of items, but when you press the Insert button, LibreOffice uses only the top one. To choose an item to insert, use the controls in the dialogue window for the input list to move it to the top of the list.
Hiding text phrases and paragraphs
When you prepare a particular version of a single-sourced document, you can hide all the text that is relevant to other versions. Writer can hide text phrases and whole paragraphs, and though it uses different dialogue windows for each case, the technique for hiding text phrases and paragraphs is almost identical:
- Make sure that View -> Field Shadings and View -> Hidden Paragraphs are turned on so that you can find the hidden text or paragraph.
- Highlight a text snippet, or place the cursor in the paragraph to be hidden. In both cases, take care to include spaces as well as characters. You might want to turn on View -> Non-Printing Characters if you run into problems with paragraphs.
- Select Insert -> Fields -> Other -> Functions -> Hidden Text or Hidden Paragraphs. In the case of hidden text, the selected snippet displays in the Hidden text field.
- Enter 1 in the condition field and press the Insert button. The text or paragraph is now hidden. Only a small gray field shading shows where the hidden text belongs. By contrast, the hidden paragraph will be visible until you unselect View -> Hidden Paragraph.
To display hidden text, click on the gray shading, using Zoom if necessary. To display hidden paragraphs, click anywhere in the paragraph. In each case, the appropriate dialogue window opens, and you can change the condition field to 0. If you have used hidden text or paragraphs more than once, use the arrow keys in the dialogue window to move to other instances to change the conditions for them.
More conveniently, you can hide text by using a character or paragraph style:
- Open the Styles and Formatting window by pressing F11.
- Select either paragraph or character styles, and right-click in the window to select New from the context menu.
- On the Font Effects tab, select the Hidden box.
- When applying the paragraphs character style, be sure to include the spaces around the characters or the spaces above and below the paragraph to avoid displaying any obvious gaps.
Nothing in the editing window indicates that text or a paragraph is hidden using a character or paragraph style. To display all passages hidden by a particular style, unselect the Hidden box on the Font Effects tab for the style. You might want to leave a comment at the start of the document or a note in File -> Properties -> Description to remind you that the file includes hidden text snippets or paragraphs.
No matter what techniques you use, hidden text or paragraphs will not be printed unless you deliberately display it or select it for printing under File -> Print -> LibreOffice Writer or Tools -> Options -> LibreOffice Writer -> Print.
In addition to hiding phrases or paragraph, you can hide larger bodies of text by using sections. Created from Insert -> Section, sections generally consist of at least several paragraphs, but can be of any length. They can be set to be write-protected in normal documents, to be editable in read-only documents, or to be formatted differently from surrounding text when you create a multipurpose style.
More to the point, like paragraph and character styles, sections can be hidden, and you can set a condition for hiding a section from Format -> Section, which includes a list of sections, both hidden and visible, in the current document that you can check to ensure that you don't overlook any.
Working through complexity
The varied locations and implementations of conditional text features in LibreOffice practically guarantee that the majority of users will overlook their potential. Conditional formatting badly needs an overhaul to make it more accessible, and especially to make the process consistent no matter what kind of text it is intended for. Still, even the use of conditions to change or hide text or paragraphs should be no challenge even for beginners, once they realize that they only need to use 0 for off and 1 for on.
Even in its present state, conditional text in LibreOffice is well worth trying. As a tool for single-sourcing, it has no parallels in other free or proprietary office suites.
Do you want to receive a compilation of Wazi's top
blog posts in the past year delivered directly to your inbox?
This work is licensed under a Creative Commons Attribution 3.0 Unported License