Getting Started Guide

Chapter 9
Getting Started with Math

LibreOffice’s Formula (Equation) Editor

This document is Copyright © 2012–2016 by the LibreOffice Documentation Team. Contributors are listed below. You may distribute it and/or modify it under the terms of either the GNU General Public License (http://www.gnu.org/licenses/gpl.html), version 3 or later, or the Creative Commons Attribution License (http://creativecommons.org/licenses/by/4.0/), version 4.0 or later.

All trademarks within this guide belong to their legitimate owners.

## Contributors

 Jean Hollis Weber Hazel Russman Laurent Balland-Poirier John A Smith Martin Saffron Peter Schofield Olivier Hallot

## Feedback

Note: Everything you send to a mailing list, including your email address and any other personal information that is written in the message, is publicly archived and cannot be deleted.

## Acknowledgments

This chapter is based on the OpenOffice.org 3.3 Math Guide. The contributors to that book are:

 Daniel Carrera Agnes Belzunce TJ Frazier Peter Kupfer Ian Laurenson Janet M. Swisher Jean Hollis Weber Michele Zarri

Additional material has been added from the German Math Handbuch for LibreOffice 3.4 (translated to English by Hazel Russman). Contributors to that book are:

 Regina Henschel Christian Kühl Florian Reisinger Gisbert Friege (Dmaths) Jochen Schiffers

Additional material has been added from the French How-To Math for LibreOffice (translated to English by Laurent Balland-Poirier). Contributors to that book are Bernard Siaud and Frédéric Parrenin.

## Publication date and software version

Published 22 June 2016. Based on LibreOffice 5.1.

## Note for Mac users

Some keystrokes and menu items are different on a Mac from those used in Windows and Linux. The table below gives some common substitutions for the instructions in this chapter. For a more detailed list, see the application Help.

 Windows or Linux Mac equivalent Effect Tools > Options menu selection LibreOffice > Preferences Access setup options Right-click Control+click and/or right-click depending on computer setup Open a context menu Ctrl (Control) ⌘ (Command) Used with other keys F5 Shift+⌘+F5 Open the Navigator F11 ⌘+T Open the Styles and Formatting window

Contents

# Introduction

LibreOfficeMath is a formula editor you can use to create or edit formulas (equations) in a symbolic form within LibreOffice documents or as standalone objects. Example formulas are shown below. However, if you want to evaluate numeric values using formulas, then refer to the Calc Guide for more information; Math does not carry out any actual calculation.

The Formula Editor in Math uses a markup language to represent formulas. This markup language is designed to be easily read wherever possible, for example, a over b produces the fraction $\frac{a}{b}$ when used in a formula.

# Getting started

Using the Formula Editor, you can create a formula as a separate document or file for a formula library, or insert formulas directly into a document using LibreOffice Writer, Calc, Impress, or Draw.

## Formulas as separate documents or files

• On the menu bar, go to File > New > Formula.

• From the Start Center, click Math Formula.

• On the Standard toolbar, click the triangle to the right of the New icon and select Formula from the context menu.
• In Math, use the keyboard shortcut Ctrl+N.

• Use command Import MathML from the clipboard.

As you enter the markup language in the Formula Editor, the formula will appear in the Preview window during and after input of the markup. The Elements window to the left of the Preview window may also appear, if it has been selected in View on the menu bar. For more information on creating formulas, see “Creating formulas” on page 8.

## File formats for formulas

LibreOffice’s native file format for formulas is ODF Formula, with extension *.odf. You can also embed formula objects in other documents like presentations, spreadsheets, or text documents. LibreOffice can also read and save formulas in MathML 1.01 format, with extension .mml.

       E   =       mc    2      [/itex] $E={\mathrm{mc}}^{2}$

## Formulas in LibreOffice documents

To insert a formula into a LibreOffice document, open the document in Writer, Calc, Draw, or Impress. The LibreOffice module in use affects how you position the cursor to insert the formula.

Figure 2 shows an example Writer document with the formula box selected ready for a formula to be entered.

When you have completed entering the markup for the formula, close the Formula Editor by pressing the Esc key or by clicking an area outside the formula in the document. Double-clicking on the formula object in the document will open the Formula Editor again so that you can edit the formula.

Formulas are inserted as OLE objects into documents. As with any OLE object, you can change how the object is placed within the document. For more information on OLE objects, see the user guides for Math, Writer, Calc, Draw, and Impress.

If you frequently insert formulas into documents, you might like to add the Formula button to the Standard toolbar or create a keyboard shortcut. See Chapter 14, Customizing LibreOffice, for more information.

# Creating formulas

You can insert elements into a formula using one of the following methods:

Using the Elements window or the context menus to insert a formula provides a convenient way to learn the markup language used by LibreOffice Math.

## Elements window

The Elements window can easily be used when entering formula data. In addition to the list of categories at the top of the window, it also provides an Example category with example formulas to use as a starting point for a formula or equation.

The Elements window is positioned by default to the left of the Preview and Formula Editor windows, as shown in Figure 1 and Figure 2. It can be floated in the same way as other docked windows.

The Elements window and the context menu contain only the most common commands that are used in formulas. For some seldom-used commands, you must always enter the command using the markup language. For a complete list of commands, see the Math Guide.

## Markup language

Markup language is entered directly into the Formula Editor. For example, typing the markup 5 times 4 into the Formula Editor creates the simple formula $5×4$ . If you are experienced in using markup language, it can be the quickest way to enter a formula. Table 2 shows some examples of using markup language to enter commands. For a full list of commands that can be used in the Formula Editor, see the Math Guide.
 Display Command Display Command $a=b$ a = b $\sqrt{a}$ sqrt {a} ${a}^{2}$ a^2 ${a}_{n}$ a_n $\int f\left(x\right)\mathit{dx}$ int f(x) dx $\sum {a}_{n}$ sum a_n $a\le b$ a <= b $\mathrm{\infty }$ infinity $a×b$ a times b $x\cdot y$ x cdot y

## Greek characters

### Using markup language

Greek characters are commonly used in formulas, but Greek characters cannot be entered into a formula using the Elements window or the context menu. Use the English names of Greek characters in markup language when entering Greek characters into a formula. See Appendix A, Commands Reference, in the Math Guide for a list of Greek characters that can be entered using markup language.

### Symbols dialog

Greek characters can also be entered into a formula using the Symbols dialog.

1. 1)Make sure the cursor is in the correct position in the Formula Editor.

2. 3)Select Greek from the Symbol set drop-down list. For italic characters, select iGreek from the drop-down list.

3. 4)Select the Greek character from the symbol list, then click Insert. When selected, the name of a Greek character is shown below the symbol list.

4. 5)Click Close when you have finished entering Greek characters into the formula.

Figure 4: Symbols dialog

## Formula examples

### Example 1

The simple formula $5×4$
can be created using LibreOffice Math as follows:

1. 1)Make sure the cursor is flashing in the Formula Editor, then select the category Unary/Binary Operators and symbol Multiplication using one of the following methods:

This method initially places the formula text <?> times <?> in the Formula Editor and the symbol appears in the document. These placeholders must then be replaced with real numbers. Using markup language in the Formula Editor places the formula $5×4$ directly into the document. To use markup language, enter 5 times 4 in the Formula Editor. $5×4$
appears in the document.

To move forward from one placeholder to the next placeholder in a formula, press the F4 key. To move backward from one placeholder to the previous placeholder in a formula, use the key combination Shift+F4.

If necessary, you can prevent a formula in a document from updating automatically. Go to View on the menu bar and deselect AutoUpdate display. To then manually update a formula, press F9 key or select View > Update on the menu bar.

### Example 2

You want to enter the formula $\mathrm{\pi }\phantom{\rule{2em}{0ex}}\simeq \phantom{\rule{2em}{0ex}}3.14159$
where the value of pi is rounded to 5 decimal places. You know the name of the Greek character (pi), but do not know the markup associated with the Is Similar Or Equal symbol $\simeq$ .

# Editing formulas

How you edit a formula and switch into formula editing mode depends on whether the formula is in Math or another LibreOffice component.

If you cannot select a formula element using the cursor, click on the Formula Cursor icon in the Tools toolbar to activate the formula cursor.
1. 3)Select the formula element you want to change, using one of the following methods:

# Formula layout

This section provides some advice on how to layout complex formulas in Math or in a LibreOffice document.

## Using braces

LibreOffice Math knows nothing about order of operation within a formula. You must use braces (also known as curly brackets) to state the order of operations that occur within a formula. The following examples show how brackets can be used in a formula.

Example 1

2 over x + 1 gives the result $\frac{2}{x}+1$

Math has recognized that the 2 before and the x after the over as belonging to the fraction, and has represented them accordingly. If you want x+1 rather than x to be the denominator, you must bracket them together using braces so that both will be placed there.

Inserting braces into 2 over {x + 1} gives the result $\frac{2}{x+1}$ where x+1 is now the denominator.

Example 2

– 1 over 2 gives the result $\frac{-1}{2}$

Math has recognized the minus sign as a prefix for the 1 and has therefore placed it in the numerator of the fraction. If you wish to show that the whole fraction is negative, with the minus sign in front of the fraction, you must put the fraction in braces to signify to Math that the characters belong together.

Adding braces to into the markup language {1 over 2} gives the result $–\frac{1}{2}$ and the whole fraction is now negative.

Example 3

When braces are used in markup language, they are used to define the layout of the formula and are not displayed or printed. If you want to use braces within your formula, you use the commands lbrace and rbrace within the markup language.

x over {–x + 1} gives the result $\frac{x}{–x+1}$
Replace the braces using the commands lbrace and rbrace in the markup language. Writing x over lbrace –x + 1 rbrace and the result is $\frac{x}{\left\{–x+1\right\}}$

## Brackets and matrices

If you want to use a matrix in a formula, you have to use a matrix command. For example, matrix { a # b ## c # d } gives the resulting matrix $\begin{array}{cc}a& b\\ c& d\end{array}$ in the formula, where rows are separated by two hashes (#) and entries within each row are separated by one hash (#).
Normally, when you use brackets within a matrix, the brackets do not scale as the matrix increases in size. For example, ( matrix { a # b ## c # d } ) gives the result $\left(\begin{array}{cc}a& b\\ c& d\end{array}\right)$
To overcome this problem, LibreOffice Math provides scalable brackets that grow in size to match the size of a matrix. The commands left( and right) have to be used to create scalable brackets within a matrix. For example, left( matrix { a # b ## c # d } right) gives the result $\left(\begin{array}{cc}a& b\\ c& d\end{array}\right)$ where the matrix is now bracketed by scalable brackets.

Scalable brackets can be used with any element of a formula, such as a fraction or square root.

Use the commands left[ and right] to obtain scalable square brackets. A list of all brackets available within Math can be found in Appendix A, Commands Reference, in the Math Guide.

If you want all brackets to be scalable, go to Format > Spacing to open the Spacing dialog. Click on Category, select Brackets from the drop-down list and then select the option Scale all brackets.

## Unpaired brackets

When using brackets in a formula, Math expects that for every opening bracket there will be a closing one. If you forget to add a closing bracket, Math places an inverted question mark next to where the closing bracket should have been placed. This inverted question mark disappears when all the brackets are paired. However, an unpaired bracket is sometimes necessary and you have the following options.

### Non-scalable brackets

A backslash \ is placed before a non-scalable bracket to indicate that the following character should not be regarded as a bracket, but as a literal character.

For example, the unpaired brackets in the formula [ a; b [ are deliberate, but gives the result $\begin{array}{c}\\ a;b\\ \end{array}$ . To remove the inverted question marks and create unpaired brackets, backslashes are added. The formula now becomes \ [ a; b \ [ and the result $\left[a;b\left[$ shows unpaired brackets without the inverted question marks.

### Scalable brackets

To create unpaired scalable brackets or braces in a formula, the markup commands left, right, and none are used.

Example

You want to create the formula $|x|=\left\{\begin{array}{c}x\text{for}x\ge 0\\ -x\text{for}x<0\end{array}$ and in the Formula Editor you enter
abs x = lbrace stack {x "for" x >= 0 # -x "for" x < 0.
However, this gives the incorrect result $\begin{array}{c}\\ \begin{array}{c}x\text{for}x\ge 0\\ -x\text{for}x<0\end{array}\\ ||x\end{array}$ .

To remove the inverted question marks and create the correct formula, you have to use the markup commands left, right, and none. To create the correct formula, change the entry in the Formula Editor to

abs x = left lbrace stack {x "for" x >= 0 # -x "for" x < 0} right none.

## Recognizing functions

In the basic installation of Math, Math outputs functions in normal characters and variables in italic characters. However, if Math fails to recognize a function, you can tell Math that you have just entered a function. Enter the markup command func before a function forces Math to recognize the following text as a function and uses normal characters.

For a full list of functions within Math, see the Math Guide.

Some Math functions have to be followed by a number or a variable. If these are missing, Math places an inverted question mark where the missing number or variable should be. To remove the inverted question mark and correct the formula, you have to enter a number, a variable, or a pair of empty brackets as a placeholder.

You can navigate through errors in a formula using the key F3 or the key combination Shift+F3.

## Formulas over multiple lines

Suppose you want to create a formula that requires more than one line, for example $\begin{array}{c}x=3\\ y=1\end{array}$ .
Your first reaction would normally be to press the Enter key. However, if you press the Enter key, the markup language in the Formula Editor goes to a new line, but the resulting formula is written on one line. You must type the macro command newline each time you want to create and display a new line in a formula.

Example

x = 3
y = 1

gives the incorrect result $x=3y=1$
x = 3 newline y = 1 gives the correct result $\begin{array}{c}x=3\\ y=1\end{array}$

It is not possible in Math to create multiple-line formulas when a line ends with an equals sign and you want to continue the calculation on a new line without completing the term on the right side of the equals sign. If you require a multiple line formula to have an equals sign at the end of a line without a term after the equals sign, then use either empty quotes "" or empty braces {} or the space characters grave ` or tilde ˜.

By default, a multiple line formula is centrally aligned. For more information on alignment using the equals sign, see the Math Guide.

Spacing between the elements in a formula is not set by using space characters in the markup language. If you want to add spaces into the formula, use one of the following options:

Any spaces at the end of a line in the markup language are ignored by default. For more information, see the Math Guide.

## Adding limits to sum/integral commands

The sum and integral commands can take the parameters from and to if you want to set the lower and upper limits respectively. The parameters from and to can be used singly or together as shown by the following examples. For more information on the sum and integral commands, see the Math Guide.

Examples

sum from k = 1 to n a_k gives the result $\sum _{k=1}^{n}{a}_{k}$
int from 0 to x f(t) dt gives the result $\underset{0}{\overset{x}{\int }}f\left(t\right)\mathit{dt}$
int_0^x f(t) dt gives the result ${\int }_{0}^{x}f\left(t\right)\mathit{dt}$
int from Re f gives the result $\underset{\mathrm{\Re }}{\int }f$
sum to infinity 2^{-n} gives the result $\sum ^{\mathrm{\infty }}{2}^{-n}$

## Writing derivatives

When writing derivatives, you have to tell Math that it is a fraction by using the over command. The over command is combined with the character d for a total derivative or the partial command for a partial derivative to achieve the effect of a derivative. Braces {} are used each side of the element to surround the element and make the derivative as shown by the following examples.

Examples

{df} over {dx} gives the result $\frac{\mathit{df}}{\mathit{dx}}$
{partial f} over {partial y} gives the result $\frac{\partial f}{\partial y}$
{partial^2 f} over {partial t^2} gives the result $\frac{{\partial }^{2}f}{\partial {t}^{2}}$

To write function names with primes, as is normal in school notation, you must first add the symbols to the catalog. See the Math Guide for more information.

## Markup language characters as normal characters

Characters that are used as controls in markup language cannot be entered directly as normal characters. These characters are: %, {, }, &, |, _, ^ and ". For example, you cannot write 2% = 0.02 in markup language and expect the same characters to appear in the formula. To overcome this limitation, use one of the following methods:

• Add the character to the Math Catalog, for example the double quote character.

• Use commands, for example lbrace and rbrace give literal braces $\left\{\right\}$ .
• Note

The Special Characters dialog used by other LibreOffice modules is not available in Math. If you regularly require special characters in Math, the characters should be added to the catalog of Math symbols. See the Math Guide for more information.

## Text in formulas

The font used for text in a formula will be the default font that has been set in the Fonts dialog. For more information on how to change fonts used for in formulas, see “Changing formula appearance” on page 18.

By default, text alignment is left-justified in formulas. To change text alignment, see “Adjusting formula alignment” on page 21.

Formatting commands are not interpreted within text used in formulas. If you want to use formatting commands within formula text, then you must break up the text using double quotes in the Formula Editor.

Example

Enter the following in the Formula Editor:

"In " color blue bold "isosceles" "triangles, the base angles are equal"

creates the following text in a formula $\text{In}{\text{isosceles}}\text{triangles, the base angles are equal}$

## Aligning formulas using equals sign

LibreOffice Math does not have a command for aligning formulas on a particular character. However, you can use a matrix to align formulas on a character and this character is normally the equals sign (=).

Example

Creating the matrix:

matrix{ alignr x+y # {}={} # alignl 2 ## alignr x   # {}={} # alignl 2-y }

gives the following result, where formulas are aligned on the equals sign $\begin{array}{ccc}\hfill x+y& =& 2\hfill \\ \hfill x& =& 2-y\hfill \end{array}$

The empty braces each side of the equals sign are necessary because the equals sign is a binary operator and requires an expression on each side. You can use spaces, or ` or ~ characters each side of the equals sign, but braces are recommended as they are easier to see within the markup language.

You can reduce the spacing on each side of the equals sign if you change the inter-column spacing of the matrix. See “Adjusting formula spacing” on page 20 for information on how to adjust adjust formula spacing.

# Changing formula appearance

## Formula font size

### Current formula font size

To change the font size used for a formula already inserted in Math or another LibreOffice module:

1. 1)Click in the markup language in the Formula Editor.

2. 3)Select a different font size using the Base size spinner or type a new font size in the Base Size box.

3. 4)Click OK to save your changes and close the dialog. An example result when you change font size is shown below.

Example

Default font size 12pt: $\mathrm{\pi }\phantom{\rule{2em}{0ex}}\simeq \phantom{\rule{2em}{0ex}}3.14159$
After font size change to 18pt: $\mathrm{\pi }\phantom{\rule{2em}{0ex}}\simeq \phantom{\rule{2em}{0ex}}3.14159$

Figure 6: Font Sizes dialog

### Default formula font size

To change the default font size used for all formulas in Math or another LibreOffice module:

1. 2)Select a different font size using the Base size spinner or type a new font size in the Base Size box.

2. 3)Click Default and confirm your changes to the base size font. Any formulas created from this point on will use the new base size font for formulas.

3. 4)Click OK to save your changes and close the Font Sizes dialog.

• Note

If you have already inserted formulas into a document and you change the default font size, only formulas inserted after the change in default font size will use the new default settings. You have to individually change the font size of formulas already inserted if you want these formulas to use the same font size as the default settings. For more information on changing the font size, see the Math Guide.

## Formula fonts

### Current formula fonts

To change the fonts used for the current formula in Math or another LibreOffice module:

1. 1)Click in the markup language in the Formula Editor.

2. 3)Select a new font for each the various options from the drop-down lists.

3. 4)If the font you want to use does not appear in the drop-down list, click Modify and select the option from the context menu to open a fonts dialog. Select the font you want to use and click OK to add it to the drop-down list for that option.

4. 5)Click OK to save your changes and close the Fonts dialog.

Figure 7: Fonts dialog

### Default formula fonts

To change the default fonts used for all formulas in Math or another LibreOffice module:

1. 2)Select a new font where required for each of the various options from the drop-down lists.

2. 3)If the font you want to use does not appear in the drop-down list, click Modify and select the option from the context menu to open a fonts dialog. Select the font you want to use and click OK to add it to the drop-down list for that option.

3. 4)Click Default and confirm your changes to the fonts. Any formulas created from this point on will use the new fonts for formulas.

4. 5)Click OK to save your changes and close the Fonts dialog.

• Note

If you have already inserted formulas into a document and you change the default fonts, only formulas inserted after the change in default fonts will use the new default settings. You have to individually change the font of formulas already inserted if you want these formulas to use the same font as the default settings. For more information on changing the font, see the Math Guide.

Use the Spacing dialog (Figure 8) to determine the spacing between formula elements. The spacing is specified as a percentage in relation to the defined base size for fonts.

### Current formula spacing

To change the spacing used for the current formula in Math or another LibreOffice module:

1. 1)Click in the markup language in the Formula Editor.

2. 3)Click Category and select one of the options from the drop-down list. The options in the Spacing dialog change according to the category selected.

3. 4)Enter new values for the spacing category and click OK.

4. 5)Check the result in your formula. If it is not to your satisfaction, repeat the above steps.

Figure 8: Spacing dialog

### Default formula spacing

To change the default spacing used for all formulas in Math or another LibreOffice module:

1. 2)Click Category and select one of the options from the drop-down list. The options in the Spacing dialog change according to the category selected.

2. 3)Click Default and confirm your changes to the formula spacing. Any formulas created from this point on will use the new spacing for formulas.

3. 4)Click OK to save your changes and close the Spacing dialog.

• Note

If you have already inserted formulas into a document and you change the spacing, only formulas inserted after the change in spacing will use the new default settings. You have to individually change the spacing of formulas already inserted if you want these formulas to use the same spacing as the default settings. For more information on changing the formula spacing, see the Math Guide.

The alignment settings determine how formula elements located above one another are aligned horizontally relative to each other.

It is not possible to align formulas on a particular character and formula alignment (using the method described below) does not apply to text elements, which are always aligned left.

Independent of using formula alignment given below, it is possible to align formulas using the commands alignl, alignc and alignr. These commands also work for text elements.

### Current formula alignment

To change the alignment used for the current formula in Math or another LibreOffice module:

1. 1)Click in the markup language in the Formula Editor.

2. 3)Select either Left, Centered, or Right for horizontal alignment.

3. 4)Click OK and check the result in your formula. If it is not to your satisfaction, repeat the above steps.

Figure 9: Alignment dialog

### Default formula alignment

To change the default alignment used for all formulas in Math or another LibreOffice module:

1. 2)Select either Left, Centered, or Right for horizontal alignment.

2. 3)Click Default and confirm your changes to the formula alignment. Any formulas created from this point on will use the new alignment for formulas.

3. 4)Click OK and check the result in your formula. If it is not to your satisfaction, repeat the above steps.

• Note

If you have already inserted formulas into your document and you change the formula alignment, only formulas inserted after the change in alignment will use the new default settings. You have to individually change the alignment of formulas already inserted if you want these formulas to use the same alignment as the default settings.

## Changing formula color

### Character color

To change the color of the characters used in a formula, use the command color in the markup language. This command only works on the formula element immediately after the color name. For example, entering the markup language color red ABC 5 times 4 gives the result   ${\mathit{ABC}}5×4$ .
To change the color of the whole formula, you have to enclose the whole formula within brackets. For example, entering the markup language color red {ABC 5 times 4} gives the result ${\mathit{ABC}5×4}$ .

For information on the colors available in Math, see the Math Guide.

For ease of use, the Elements window includes the category Attributes, which lists standard colors. Click on the required color to insert the command into your formula.

### Background color

It is not possible to select a background color for formulas in LibreOffice Math. The background color for a formula is by default the same color as the document or frame that the formula has been inserted into. However, in LibreOffice documents, you can use object properties to change the background color for a formula. For more information on using a background color (area fill for objects) with a formula, please refer to the user guides for Writer, Calc, Draw, and Impress.

## Formula library

If you regularly insert the same formulas into your documents, you can create a formula library using formulas that you have created using the Formula Editor. Individual formulas can be saved as separate files using the ODF format for formulas with the file suffix of .odf, or in MathML format with the file suffix of .mml.

You can use LibreOffice Math, Writer, Calc, Draw, or Impress to create formulas and build up your formula library.

### Using Math

1. 1)Create a folder on your computer to contain your formulas. Give the folder a memorable name, for example Formula Library.

2. 3)Go to File > Save As on the menu bar or use the keyboard shortcut Ctrl+Shift+S to open a Save As dialog.

3. 4)Navigate to the folder you have created for your formula library.

4. 5)Type a memorable name for your formula in the File name text box.

5. 6)Select from the drop-down list for File type either ODF Formula (.odf) or MathML 1.01 (.mml) as the file type for your formula.

6. 7)Click Save to save the formula and close the Save As dialog.

### Using Writer, Calc, Draw, or Impress

1. 1)Create a folder on your computer to contain your formulas. Give the folder a memorable name, for example Formula Library.

2. 2)Open a document using Writer, Calc, Draw, or Impress.

3. 4)Right-click on the formula object and select Save Copy as from the context menu to open a Save As dialog.

4. 5)Navigate to the folder you have created for your formula library.

5. 6)Type a memorable name for your formula in the File name text box.

6. 7)Select from the drop-down list for File type either ODF Formula (.odf) or MathML 1.01 (.mml) as the file type for your formula.

7. 8)Click Save to save the formula and close the Save As dialog.

You cannot insert a formula from your library into a document by dragging and dropping using the mouse, nor by using Insert > File on the menu bar. You must insert a formula from your library into your document as an OLE object.

# Formulas in Writer

When a formula is inserted into a document, LibreOffice Writer inserts the formula into a frame and treats the formula as an OLE object. Double-clicking on an inserted formula will open the Formula Editor in LibreOffice Math, where you can edit the formula.

This section explains what options you can change for each individual formula within a Writer document. Please refer to the chapters on styles in the Writer Guide for information on how to change the default settings for frame styles for OLE objects.

## Automatic formula numbering

Automatic numbering of formulas for cross-reference purposes can only be carried out in LibreOffice Writer.

### Numbering

 ${\mathit{ABC}5×4}$ (1)
1. 3)Delete the sample formula and insert your formula as an object in the left column. See “Creating formulas” on page 8 for more information on inserting formulas.

Alternatively, you can first insert your formula into the document, then carry out Steps 1 and 2 above, replacing the sample formula with your formula.

• Note

If you want to use square parentheses instead of round ones around the formula number, or if you want the formula number to be separated from the formula by tabs instead of using a table, then you need to modify the AutoText entry for fn. Refer to the section on AutoText in Chapter 4, Getting Started with Writer.

### Cross-referencing

1. 1)Click in the document where you want the cross-reference to appear.

2. 3)Click on the Cross-references tab, then select Text in the Type section.

3. 4)In the Selection section, select the formula number you want to refer to.

4. 5)In the Insert reference to section, select Reference and click Insert.

5. 6)When you have finished creating cross-references, click Close to close the Fields dialog.

• Tip

To insert the cross-reference number without parentheses, select Numbering instead of Reference in the Insert reference to section.

## Anchoring formulas

A formula is treated as an object within Writer and its default anchoring is As character within a paragraph when it is inserted into a document. To change the anchoring of a formula object:

Alternatively,

1. 2)Make sure the Type page is selected and select a new anchoring position from the Anchor section.

2. 3)Click OK to save your changes and close the Object dialog.

The anchoring options are not available in the Object dialog when you are making changes to the various options available for frame styles. For more information on how to modify frame styles, please refer to the chapters on styles in the Writer Guide.

## Vertical alignment

The normal default setting for vertical alignment for formula objects is to use the text base line as a reference. This default setting can be changed by modifying the formula frame style. See the chapters on styles in the Writer Guide for more information.

To change the vertical alignment position of an individual formula object:

1. 2)Make sure the Type page is selected and select a new alignment position from the drop-down list in the Position section. The vertical alignment options available are Top, Bottom, Center or From bottom.

2. 3)If necessary, type in the text box a plus or minus value for vertical alignment. This option is only available if From bottom vertical alignment has been selected.

3. 4)Select the type of text alignment from the drop-down list in the Position section. The text alignment options available are Base line, Character and Row.

4. 5)Click OK to save your changes and close the Object dialog.

If the Position section in the Object dialog is grayed out and not available, then go to Tools > Options > LibreOffice Writer > Formatting Aids and uncheck the option Math baseline alignment. This setting is stored with the document and applies to all formulas within it. Any new documents created will also use this setting for Math baseline alignment.

## Object spacing

A formula object, when inserted into a Writer document, has spacing on each side. The default value used for spacing is set within the frame style for formula objects and can be changed by modifying the formula frame style, see the chapters on styles in the Writer Guide for more information.

You can individually adjust the spacing for each formula object within a document as follows:

1. 1)Create the formula in your Writer document.

2. 2)Right-click on the selected formula object and select Object from the context menu, or go to Format > Frame/Object on the menu bar to open the Object dialog.

3. 4)In the Spacing section, enter the spacing value for Left, Right, Top and Bottom spacing.

4. 5)Click OK to save your changes and close the Object dialog.

## Text mode

In large formulas placed within a line of text, the formula elements can often be higher than the text height. Therefore, to make large formulas easier to read, it is recommended to always insert them into a separate paragraph of their own.

However, if it is necessary to place a large formula within a line of text, double-click on the formula to open the Formula Editor and then go to Format > Text Mode on the menu bar. The Formula Editor will try to shrink the formula to fit the text height. The numerators and denominators of fractions are shrunk, and the limits of integrals and sums are placed beside the integral/sum sign, as shown in the following example.

Example

A formula in a separate paragraph:

$\sum _{i=2}^{5}{i}^{2}$

and the same formula embedded into a line of text using text mode format: $\sum _{i=2}^{5}{i}^{2}$

## Background and borders

The default setting for background (area fill) and borders for formula objects is set by the formula frame style. To change this default setting for formula frame style, refer to the chapters on styles in the Writer Guide. However, for individual formulas in a document, you can change the background and borders.

The size of the frame that a formula is placed in when inserted into a document cannot be changed. The frame size for a formula object depends on the setting of the formula font size; see the Math Guide for more information.

### Backgrounds

1. 1)In the document, select the formula where you wish to change the background.

2. 2)Right-click on the formula and select Object from the context menu, or go to Format > Frame/Object on the menu bar to open the object dialog.

3. 4)Select the options you want to use for the formula background. The options change depending on the type of fill selected.

4. 5)Click OK to save your changes and close the Object dialog.