SMBs

DIY: Add formulas to LibreOffice documents with LibreOffice Math

Jack Wallen explains how to add user-friendly formulas in your LibreOffice documents by installing and using LibreOffice Math.
When you're creating a new document, whether it's a spreadsheet or a word processing document, it can be a challenge to create a formula to include in it. You can let your readers know the formula they need to use is (A+B)/(C*(D+E)), but why not include a formula in the way it's supposed to be (Figure A)? Figure A

The formula in its true form is much easier to understand.

If you're using LibreOffice, you can save yourself the hassle of creating a formula using tables and various formatting tools by using a tool created specifically for that task: LibreOffice Math. The built-in LibreOffice formula editor can create formulas with fractions, terms with exponents and indices, integrals, and mathematical functions, to inequalities, systems of equations, and matrices. These formulas can then be inserted into Writer, Calc, and Impress documents to make a document that depends upon mathematical formulas much more user friendly.

These formulas cannot interact with your documents; that is, you cannot insert the formula you see in Figure A and make the formula extract the variables from spreadsheet cells. These are static formulas used for illustration and simplification only. Let's look at how you can add these formulas into your documents.

Installing LibreOffice Math

First, you need to install LibreOffice Math. If you're using Windows, go to Start | LibreOffice X.X (X.X is the release number). Inside that folder you should see LibreOffice Math listed; LibreOffice Math typically installs by default. There are instances when people do custom installations to leave out specific elements; if you installed LibreOffice on Windows this way, you'll need to reinstall and do a standard installation.

If you're using Linux and LibreOffice Math is not installed, open your Add/Remove Software tool and search for "libreoffice-math" (no quotes). If it's not listed as Installed, install it from that tool.

Using LibreOffice Math

There are two ways to open LibreOffice Math: from the LibreOffice submenu or from within a LibreOffice application. If you plan on embedding a formula into an application, you should only open LibreOffice Math from within the application you want the formula imbedded into. If you just want to create a formula to be saved as a PDF, you can open LibreOffice Math by itself by going to your main desktop menu, clicking LibreOffice XX | LibreOffice Math (XX is the release number).

When you start up LibreOffice Math, you will be presented with two windows (Figure B). Figure B

You see a formula created using elements from the Elements window. (Click the image to enlarge.)

Formulas are created by selecting the elements necessary and then replacing the <?> tags with the numeric or variable values for the formula in question. Let's walk through the process of creating the formula used earlier.

You might think the formula in question could be represented by typing (A+B)/(C*(D+E)), but that is not the case. When you type a formula into the lower pane of the LibreOffice Math window, that formula will appear in the preview screen exactly as you typed it. Instead, you must use elements from the Elements window. Follow these steps to get the proper formula:

  1. Start with a blank window.
  2. Click the Divisional (fraction) element.
  3. Highlight the first <?> characters.
  4. Click the Addition element.
  5. Highlight the second <?> characters.
  6. Click the Multiplication* element.
  7. Highlight the last <?> characters (which appear after you click the Multiplication element).
  8. Click the Addition element.
Your current LibreOffice Math main window will look what's in Figure C. Figure C

Now it's just a matter of filling in the blanks. (Click the image to enlarge.)

To finish this equation, replace the <?> strings with the necessary variables. The string will look like:

{A + B} over {C * (D + E)}

The easiest way to get the hang of how the formulas work is to create them using the Elements window and compare the written formula to the end results. The LibreOffice site also has a page of examples that is helpful.

After creating your formula, you can save it as an Open Document Formula document or export the formula as a PDF. The best way to get the formula into a document is to create the formula from within the document in which you're working by following these steps:

  1. From within your document, go to Insert | Object | Formula.
  2. Create your formula as you did above in the lower pane (Figure D).
  3. Once your formula is created, click in the document pane (upper pane) to close the formula editor.
Figure D

As you change the formula in the lower pane, it will update automatically within the document.
When you close the formula editor, you will see the formula in the document. If you click on that formula, you will see a dotted green line around the formula box (Figure E). Figure E

If you right-click the element, you can export it as an image as well.

Now you can add user-friendly formulas to your LibreOffice documents. It can take a while to familiarize yourself ith how the formulas are written; in the meantime, you can use the Elements tool to help you create complex formulas to be embedded into your documents.

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

0 comments

Editor's Picks