\<bookmark_value\>logical expressions\</bookmark_value\>\<bookmark_value\>formulating conditions\</bookmark_value\>\<bookmark_value\>conditions; in fields and sections\</bookmark_value\>\<bookmark_value\>fields;defining conditions\</bookmark_value\>\<bookmark_value\>sections;defining conditions\</bookmark_value\>\<bookmark_value\>variables; in conditions\</bookmark_value\>\<bookmark_value\>user data;in conditions\</bookmark_value\>\<bookmark_value\>databases;in conditions\</bookmark_value\>\<bookmark_value\>hiding; database fields\</bookmark_value\>

Defining Conditions

Conditions are logical expressions that you can use to control the display of fields and sections in your document. Although the following examples apply to fields, they also apply to sections.

You can define conditions for the following field types:

  1. Conditional text: displays text A if the condition is true, or text B if the condition is false.

  2. Hidden text: hides the contents of the field if the condition is true.

  3. Hidden paragraph: hides the paragraph if the condition is true.

  4. Any record and next record: controls the access to database records.

The simplest way to define a condition is to type the logical expression directly in a \<emph\>Condition \</emph\>box using the following values:


The condition is always met. You can also enter any value not equal to 0 as the conditional text.


The condition is not met. You can also enter the value 0.

Note Icon

If you leave the \<emph\>Condition \</emph\>box empty, the condition is interpreted as not being met.

When you define a condition, use the same elements for defining a formula, namely comparative operators, mathematical and statistical functions, number formats, variables and constants.

You can use the following types of variables when you define a condition:

  1. Predefined LibreOffice variables that use statistics on document properties

  2. Custom variables, that are a created with the "Set variable" field

  3. Variables based on user data

  4. Variables based on the contents of database fields

You cannot use internal variables, such as page and chapter numbers, in condition expression.

Conditions and Variables

The following examples use a variable called "x":

x == 1 or x EQ 1

The condition is true if "x" is equal to 1.

x != 1 or x NEQ 1

The condition is true if "x" does not equal 1.

sinx == 0

The condition is true if "x" is a multiple of pi.

To use comparative operators with strings, the operands must be bounded by double quotation marks:

x == "ABC" or x EQ "ABC"

Checks if variable "x" contains (true) the "ABC" string, or not (false).

x == "" or x EQ ""


!x or NOT x

Checks if the variable "x" contains an empty string.

Note Icon

The "equal" comparative operator must be represented by two equal signs (==) in a condition. For example, if you define a variable "x" with the value of 1, you can enter the condition as x==1.

User Data

You can include user data when you define conditions. To change your user data, choose - LibreOffice - User data. User data must be entered in the form of strings. You can query the user data with "==" (EQ), "!=" (NEQ), or "!"(NOT).

The following table lists user data variables and their meanings:




First name


Last name










Zip code








Business telephone number


Home telephone number


Fax number


E-mail address


State (not in all LibreOffice versions)

For example, to hide a paragraph, text, or a section from a user with a specific initial, such as "LM", enter the condition: user_initials=="LM".

Conditions and Database Fields

You can define conditions for accessing databases, or database fields. For example, you can check the contents of a database field from a condition, or use database fields in logical expressions. The following table lists a few more examples of using databases in conditions:




Database.Table.Company NEQ ""

Database.Table.Company != ""

The condition is true if the COMPANY field is not empty. (In the first example, no operator is required.)


NOT Database.Table.Company

Database.Table.Company EQ ""

Database.Table.Company ==""

Returns TRUE if the COMPANY field is empty. (Exclamation sign represents a logical NOT.)

Database.Table.Company !="Sun Microsystems"

Database.Table.Company NEQ "Sun Microsystems"

Returns TRUE if the current entry in the COMPANY field is "Sun Microsystems".

Database.Table.Firstname AND Database.Table.Name

Returns TRUE if the record contains the first and the last name.

Note Icon

Note the difference between the boolean NOT "!" and the comparative operator not equal "!=" (NEQ).

When you refer to a database field in a condition, use the form Databasename.Tablename.Fieldname. If one of the names contains a character that is an operator, such as a minus sign (-), enclose the name in square brackets, for example, Databasename.[Table-name].Fieldname. Never use spaces inside field names.

Example: Hiding an Empty Database Field

You may want to create a condition that hides an empty field, for example, if the COMPANY field is empty for some of the data records.

Select the \<emph\>Hidden Paragraph\</emph\> box, and type the following condition: Addressbook.Addresses.Company EQ ""

or type the following

NOT Addressbook.Addresses.Company

If the COMPANY database field is empty, the condition is true and the paragraph is hidden.

Note Icon

To display hidden paragraphs on the screen, choose - LibreOffice Writer - View, and clear the Hidden paragraphs check box.

Examples of Conditions in Fields

The following examples use the Conditional text field, although they can be applied to any fields that can be linked to a condition. The syntax used for conditions is also used for the Hidden text, Hidden paragraph, Any record or Next record fields.

To display conditional text based on the number of pages:

  1. Choose \<emph\>Insert - Fields - Other\</emph\>, and then click the \<emph\>Functions\</emph\> tab.

  2. In the \<emph\>Type\</emph\> list, click "Conditional text".

  3. In the \<emph\>Condition \</emph\>box, type "page == 1".

  4. In the \<emph\>Then\</emph\> box, type "There is only one page".

  5. In the \<emph\>Or \</emph\>box, type "There are several pages".

  6. Click \<emph\>Insert\</emph\>, and then click \<emph\>Close\</emph\>.

To display conditional text based on a user-defined Variable

  1. Choose \<emph\>Insert - Fields - Other\</emph\>, and then click the \<emph\>Variables\</emph\> tab.

  2. In the \<emph\>Type \</emph\>list, click "Set Variable".

  3. In the\<emph\> Name\</emph\> box, type "Profit".

  4. In the\<emph\> Value\</emph\> box, type "5000".

  5. Click \<emph\>Insert\</emph\>.

  6. Click the \<emph\>Functions\</emph\> tab, and click "Conditional text" in the \<emph\>Type\</emph\> list.

  7. In the \<emph\>Condition\</emph\> box, type "Profit < 5000".

  8. In the \<emph\>Then\</emph\> box, type "Target is not met".

  9. In the \<emph\>Or \</emph\>box, type "Target is met".

  10. Click \<emph\>Insert\</emph\>.

To edit the contents of the "Profit" variable, double-click the variable field.

To display conditional text based on the contents of a database field:

The first part of this example inserts a space between the "First Name" and "Last Name" fields in a document, and the second part inserts text based on the contents of a field. This example requires that an address data source is registered with LibreOffice.

  1. Choose \<emph\>Insert - Fields - Other\</emph\>, and then click the \<emph\>Database\</emph\> tab.

  2. In the \<emph\>Type \</emph\>list, click "Mail merge fields".

  3. In the\<emph\> Database selection\</emph\> box, double-click an address book, click "First Name", and then click\<emph\> Insert\</emph\>. Repeat for "Last Name".

  4. In the document, place the cursor between the two fields, press Space, and then return to the \<emph\>Fields \</emph\>dialog:

  5. Click the \<emph\>Functions\</emph\> tab, and then click "Conditional text" in the \<emph\>Type\</emph\> list.

  6. In the \<emph\>Condition \</emph\>box, type: "Addressbook.addresses.firstname".

  7. In the \<emph\>Then \</emph\>box, type a space and leave the \<emph\>Or \</emph\>box blank.

You can now use a condition to insert text based on the contents of the First Name field.

  1. In the \<emph\>Fields \</emph\>dialog, click the \<emph\>Functions \</emph\>tab.

  2. In the \<emph\>Type \</emph\>box, click "Conditional text".

  3. In the \<emph\>Condition \</emph\>box, type: Addressbook.addresses.firstname == "Michael"

  4. In the \<emph\>Then \</emph\>box, type "Dear".

  5. In the \<emph\>Or \</emph\>box, type "Hello".

  6. Click \<emph\>Insert\</emph\>.

Please support us!