Getting the most from OpenOffice.org Writer fields

32

Author: Jean Hollis Weber

Fields are extremely useful features of Writer. This article describes how to use fields to solve common business and technical writing problems.

This article is excerpted from the recently published book OpenOffice.org Writer.

Using Document Properties to Hold Information That Changes

The Properties dialog for any document contains spaces on the Description tab and the User Defined tab for information that you might want to include in your document, especially if it’s information that might change during the course of the project. To display this dialog, click File > Properties.

Later in this article I’ll show how to use this information in fields. You can return to this dialog at any time and change the information you entered. When you do so, all of the references to that information will change wherever they appear in the document. For example, you might need to change the contents of the Title field from the draft title to the production title.

The User Defined tab provides four fields for you to use as required. You can change the default names for these fields to more meaningful names. To change these field names, click the Info fields button near the bottom of
the dialog. In the small pop-up dialog, type the field names you want, then click OK.

Using Other Fields to Hold Information That Changes

One way that writers use (or should use) fields is to hold information that is likely to change during the course of a project. For example, the name of a manager, a product, or even your entire company may change just before the document is due to be printed. If you have inserted the changeable information as fields, you can change the information in one place and it will automatically change in all the places where that field occurs.

Writer provides several places where you can store the information referred to by a field. We’ll look at some of them now. Three document properties (Title, Subject, Author) are on the Insert > Fields menu. To insert one of these fields, click on it in the menu. Other document properties are on the DocInformation and Document tabs of the Fields dialog are reached by clicking Insert > Fields > Other.

To insert one of these fields, select it in the Type list, then select from the Select and Format lists if choices appear. Finally, click Insert. Some of these items are picked up from the User Data page of the Options dialog, so make sure the information on that page is correct.

Tip Although these fields are often used to hold information
that changes, you can make the content unchangeable by selecting the Fixed content
checkbox when inserting the field. If necessary, you
can come back to this dialog later and deselect this checkbox to make the field
variable again.

Using AutoText to Insert Often-Used Fields Quickly

If you use the same fields often, you’ll want a quick and easy way to insert them. Use AutoText for this purpose. To define an AutoText entry for a field:

  1. Insert a field into your document, as described previously.
  2. Select the field, and then click Edit > AutoText (or press Ctrl-F3).
  3. On the AutoText dialog, choose the group where this new entry will be stored (in this example, it’s going into My AutoText), type a name for the entry, and change the suggested shortcut if you wish.
  4. Click the AutoText button, and click New to have the entry inserted as a field. Do not choose New (text only) or the AutoText entry will be plain text, not a field.
  5. Now whenever you want to insert this field at the cursor position, press the shortcut keys, then press F3.

Defining Your Own Numbering Sequences

You may want to define your own numbering sequences to use in situations where you don’t always want the number at the start of the paragraph, or where you want more control than the built-in numbering choices give you.

This topic describes how to create and use a numbering sequence, using a “number range variable” field.

Create a Number Range Variable

  1. Place the insertion point in a blank paragraph in your document.
  2. Click Insert > Fields > Other and select the Variables tab. In the Type list, select Number Range. In the Format list, select Arabic (1 2 3). Type whatever you want in the Name field (I’ve used Step in this example).
  3. Click Insert. The name of the variable (Step) now appears in the Selection list, and a number field (showing 1) appears at the insertion point in your document.The Fields dialog remains open, so you may need to move it out of the way to see the field in the document.

    Hover the mouse pointer over this number field and you’ll see the field code of Step = Step+1. If you click several more times on the Insert button in the Fields dialog, the numbers 2, 3, 4, and so on will appear in the document.

  4. Now you want to create another field, to restart the Step sequence at 1, so you can use the same sequence name more than once in your document (for example, to begin each set of instructions).

    To create this new field, open the Fields dialog to the Variables tab. Make sure the variable name Step appears in the Name box. In the Value box, type Step=1. Click Insert. Now hover the mouse pointer over the new field in your document and you’ll see the field code of Step = Step=1.

Use AutoText to Insert a Number Range Field Into a Document

You certainly don’t want to go through all of that every time you want to put in a step number. Instead, create two AutoText entries, one for the Step = Step=1 field (call it Step1, for example) and one for the Step = Step+1 field (StepNext). You can create similar fields for substeps or other sequences that you want to be numbered with letters (a, b, c), Roman numerals (i, ii, iii), or some other sequence supported by Writer. In the Fields dialog, choose the required format in the Format list when creating the field codes.

Next: Using Automatic Cross-References

If you type in references to other parts of the document, those references can easily get out-of-date if you reword a heading, add or remove figures, or reorganize topics. Replace any typed cross-references with automatic ones and, when you update fields, all the references will update automatically to show the current wording or page numbers. The References page of the Fields dialog lists some items, such as user-defined number range variables. Other items that you might expect to be listed, such as headings, are not shown.

Prepare Items as Targets for Cross-Referencing

Before you can insert a cross-reference to text such as a heading, you must prepare or “set” that heading as an item to be referenced. To do this, you can either use bookmarks or “set” references.

Inserting bookmarks for use in cross-referencing

Bookmarks are listed in the Navigator and can be accessed directly from there with a single mouse click. In HTML documents, bookmarks are converted to anchors that you can jump to via hyperlink.

  1. Select the text you want to bookmark. Click Insert > Bookmark.
  2. On the Insert Bookmark dialog, the larger box lists any previously defined bookmarks. Type a name for this bookmark in the top box. Click OK.

Marking headings or other text to be used in cross-referencing

To mark or “set” some text as an item to be referenced:

  1. Click Insert > Cross Reference.
  2. On the References page of the Fields dialog, click Set Reference in the Type list. The Selection list shows any references that have been defined. You can leave this page open while you set many headings as references.
  3. 3. Click in the document and highlight the text of the first heading to be used as a target for a cross-reference. Click on the Fields dialog. The text of the heading will appear in the Value box in the lower right of the dialog. In the Name box, type some text by which you can identify this heading.
  4. Click Insert. The text you typed in the Name box now appears in the Selection list.
  5. Repeat steps 3 and 4 as often as required.

Insert Cross-References

To insert a cross-reference to a heading or other text:

  1. In your document, place the cursor where you want the cross-reference to appear.
  2. If the Fields dialog is not open, click Insert > Cross Reference. On the References tab of the Fields dialog, in the Type list, click Insert Reference or Bookmark (depending on how you set your references). You can leave this page open while you insert many cross-references.
  3. Click on the required item in the Selection list, which shows the bookmarks or references that have been defined. In the Format list, choose the type of reference required. Usually this will be Reference (to insert the full text of the reference or bookmark) or Page (to insert the number of the page the referenced or bookmarked text is on).
  4. Click Insert.

To insert a cross-reference to an item (such as a figure caption) that you have previously inserted into the document as a numbering-sequence field:

  1. In your document, place the cursor where you want the cross-reference to appear. If the Fields dialog is not already open, click Insert > Cross-reference.
  2. On the References tab of the Fields dialog, select Figure in the Type list.
  3. Click on the required item in the Selection list, which shows the list of figures that have previously been inserted into the document. The Format list shows different choices from those given for headings. Choose the type of reference required. Usually this will be Category and Number (to insert the word “Figure” and its number), Reference (to insert the word “Figure” with its number and the full text of the caption), or Page (to insert the number of the page the figure is on).
  4. Click Insert.

Next: Using Fields in Headers and Footers

You can insert fields into headers or footers, using techniques described earlier in this article:

  • To insert a page number, document title, author, creation date and time, current date and time, or total page count field, use document properties.
  • You can insert a cross-reference to a bookmark or a set reference.
  • If you have used Heading 1 for your chapter titles, you can use a document field to insert the current chapter title, so it changes from one chapter to the next.
  • You can insert cross-references to other heading levels by specifying a value in the Layer box in the lower right of the Document tab of the Fields dialog. That is, Layer 1 = Heading 1, Layer 2 = Heading 2, and so on.

    A cross-reference field in the header of a page picks up the first heading of that level on the page, and a field in the footer picks up the last heading of that level.

    This feature did not work correctly in OOo 1.0, but it does work in Version 1.1.

  • To include the chapter number with the page number, position the cursor just before the Page field you inserted. Click Insert > Fields > Other. On the Document tab of the Fields dialog, select Chapter in the Type column and Chapter number without separator in the Format column. Click Insert.

    Go to the header or footer where you inserted this field, type the character you want to appear between the chapter number and the page number-for example, a period or a dash.

    The table of contents won’t automatically pick up these chapter numbers, so you’ll need to make a change on the Tables and Indexes page.

  • You can add a page count to the footer-for example “Page 9 of 12.” Type the word “Page” and a space in front of the Page field. Type a space, the word “of,” and a space after the Page field. Then click Insert > Fields > Page Count.

Using Fields Instead of Outline Numbering for Chapter Numbers

To have chapter numbers that update automatically and can be used in cross-referencing, use a numbered range field.

  1. Define your number range variable. I’ve called this variable Chapter.
  2. To insert the field into your Heading 1, type Chapter . Click Insert > Fields > Other. On the Variables tab, pick Number range, Chapter, Arabic. Click Insert. You’ll need to do this manually for each Heading 1.
  3. Select the entire text of the first Heading 1, including the word “Chapter” and the chapter number, and set a reference to it.
  4. You can now insert a cross-reference to this heading anywhere in your document.

Tip You can also use this technique for easier management of appendix numbering. Keep your appendix headings in the Heading 1 style, define a separate number range sequence for appendix numbers (choosing “A,B,C” for the number format), and type Appendix in the Heading 1 paragraph. You can then use the same page styles for chapters and appendixes, and the same field in the header or footer of chapters and appendixes.

Tricks for Working with Fields

Keyboard Shortcuts for Fields

Here are some handy keyboard shortcuts to use when working with fields:

Ctrl-F2 Open the Fields dialog. Ctrl-F9 Show/hide fields. Ctrl-F8 Field shadings on/off. F9 Update fields.

Fixing the Contents of Fields

You can specify “fixed content” for many items on the Document and DocInformation tabs so the field contents don’t update. For example, you might use a field to insert the creation date of a document, and you would not want that date to change. In another place you might use a date field to show the current date, which you do want to change; in that case, deselect “fixed content” when you insert the field.

Converting Fields into Text

Writer does not provide any easy way to convert field contents into text. To do this, you need to copy the field contents and paste them back as unformatted text. This is not a very good solution if you have hundreds of fields that you want to change, but you could use a macro to automate the process. This book does not cover macros.

Next: Developing Conditional Content

Conditional content is text and graphics that are included or excluded depending on a condition you specify.

A simple example is a reminder letter for an overdue account. The first and second reminders might have a subject line of “Reminder Notice,” but the third reminder letter might have the subject “Final Notice” and a different final paragraph.

A more complex example is a software manual for a product that comes in two versions, Pro and Lite. Both product versions have much in common, but the Pro version includes some features that are not in the Lite version. If you use conditional content, you can maintain one file containing information for both versions and print (or create online help) customized for each version. You don’t have to maintain two sets of the information that is the same for both versions, so you won’t forget to update both versions when something changes.

Choose the Types of Conditional Content to Use

This section describes several Writer features that can help you design and maintain conditional content. You can use one or any combination of these features in the same document.

Conditional text
With conditional text, you can have two alternative texts (a word, phrase, or sentence). One text will be displayed and printed if the condition you specify is met, and the other will be displayed and printed if the condition is not met. You cannot include graphics or edit the text except in the field dialog (not in the body of the document). You also cannot format part of the text (for example, bolding one word but not the others), but you can format the field to affect all of the field contents (for example, bolding all of the words). You cannot include a cross-reference or other field in the text.
Hidden text
With hidden text (a word, phrase, or sentence), you have only two choices: show or hide. If the condition you specify is met, the text is hidden; if the condition is not met, the text is displayed. The disadvantages are the same as for conditional text: you cannot include graphics, edit the text in the body of the document, format part of the text, or include a field.
Hidden paragraphs
Hidden paragraphs are like hidden text, but include entire paragraphs. A blank paragraph can also be hidden-for example, if a database field has no content for the current record. This is very useful when merging an address into a letter: if you allow two lines for the street address and the database record uses only one line, you can prevent the blank line from appearing in your document. The disadvantages are the same as for conditional text and hidden text.
Hidden sections
Hidden sections are often the most useful choice, because you can include graphics, edit the text in the body of the document, format any part of the text, and include fields. A section cannot contain less than a paragraph, so you can’t use this method for single words or phrases. The contents of a hidden section behave just like the contents of any other part of the document, but you can specify a condition under which the section is not displayed or printed. You can also choose to display the section but not print it. Finally, you can password-protect a section.

Plan Your Conditional Content

Conditions are what programmers call logical expressions. You must formulate a logical expression for each condition, since a condition is always either true (met) or false (not met). You can use the same condition in many places in your document, for different types of conditional content.

To make conditional content work, you need to:

  1. Choose or define a variable
  2. Define a logical expression (condition) involving the selected variable

Choosing or defining a variable

You can use the following variables in your condition:

  • User-defined variables
  • Predefined OpenOffice.org variables, which use statistical values from the document properties
  • User data
  • Database field contents-for example from your address book

You cannot use internal variables (for example, page number or chapter name) to formulate conditions.

Defining a logical expression (condition) involving the selected variable

The condition compares a specified fixed value with the contents of a variable or database field.

To formulate a condition, use the same elements as you would to create a formula: operators, mathematical and statistical functions, number formats, variables, and constants. The possible operators are shown in the list of operators in the online help. You can define quite complex expressions, but in most cases a simple condition will do the job.

Create the Variable

To create your variable, click Insert > Fields > Other. You can use choices found on the DocInformation, Variables, and Database tabs.

DocInformation field

You can use the document property as the variable in your condition statement, or you can create another document property field specifically for conditions.

User-defined variable field

To set up a variable or user field:

  1. Place the cursor where you want the field to be inserted.
  2. On the Fields dialog, select the Variables tab.
  3. Select Set variable in the Type list and Text in the Format list.

    Type a name for the variable in the Name box, and a value in the Value box. I’ve chosen “ProLite” for the name (to remind me that this variable is related to the two product versions), and I set the value as “Lite” because I can remember “If it’s the Lite version, then this text should be hidden.”

  4. Select Invisble so the field does not show in the document. Click Insert, then click Close.

  5. A small gray mark should be visible where you inserted the field. Hover the mouse pointer over this mark and you’ll see the field formula ProLite = Lite. We’ll come back to this field later.

Tip Because the gray mark is so small, you may have trouble finding it again, especially if you have other fields in the document. You may prefer to leave the variable field visible while you work, and change it to invisible just before you create final copy.

At any time you can place the insertion point just before the field and click Edit > Fields (or right-click on the field, and then click Fields on the popup menu). On the Edit Fields dialog, select or deselect the Invisible checkbox.

Apply the Condition to the Content

Now that you have defined the variable, you can use it in a condition statement. We’ll go through some of the possibilities.

Conditional text

First, let’s set up some conditional text that will insert the word “Great Product Lite” into the Lite version and “Great Product Pro” into the Pro version of the manual. You would use this field whenever you want to mention the name of the product.

  1. Place the cursor where you want one of these phrases to appear. (You can move or delete it later, if you wish.)
  2. Open the Fields dialog, select the Functions tab, and select Conditional text in the Type list.
  3. Type ProLite EQ “Lite” in the Condition box, Great Product Lite in the Then box, and Great Product Pro in the Else box. These fields are case-sensitive, and quotation marks are required around a text value such as Lite.
  4. Click Insert to insert the field, then click Close. You should see Great Product Lite in your text.

Hidden text

You might use hidden text for words or short phrases that describe features of Great Product Pro that aren’t found in the Lite version. You can reuse the same field in several places in your document-for example, by copying and pasting it.

To create a hidden text field:

  1. Click Insert > Fields > Other and select the Functions tab.
  2. Select Hidden text in the Type list.
  3. Type ProLite EQ “Lite” in the Condition box, and enter the required text in the Insert text box. Remember, this is the text that is hidden if the condition is true.
  4. Click Insert to create and insert the field.

Hidden sections

A conditional section is hidden if the condition is true. To create a conditional section:

  1. Select the text that you want to be included in the conditional section. (You can edit this text later, just as you can edit any other text.)
  2. Click Insert > Section. On the Insert Section dialog, select Hide and enter the condition in the With condition box. You can also give the section a name, if you wish. Click Insert to insert the section into your document.

To show the hidden section so you can edit or remove it:

  1. Click Format > Sections.
  2. On the Edit Sections dialog (not shown), select the section from the list.
  3. Do one of the following:
    • Deselect the Hide checkbox, and then click OK. You can now edit the contents of the section. Afterwards, you can click Format > Sections again and select the Hide checkbox to hide the section again.
    • Click Undo to remove the section markers (but not the contents of the section). Click OK. The contents of the section are now a normal part of the document.

Change the Value of the Variable

  1. Find the variable field you created.
  2. Click once just in front of this field, then right-click and click Fields on the pop-up menu.
  3. On the Edit Fields dialog, change the value of the variable to Pro. If you have set fields to update automatically, all of the conditional and hidden text that uses this variable as a condition will change.

Tip To turn on automatic updating of fields, click Tools > Options > Text Document; on the General tab, select Fields under Update Automatically.