Jex - a Java Equation Editor for LibreOffice

RERELEASE January 2013

by David K. Levine

Jex is an equation editor designed to insert, edit and convert equations in LibreOffice. It is similar to the Design Sciences Mathtype editor, a version of which also ships as the default equation editor with Microsoft Word. Installation and downloads are below. Jex is a wysywig editor that supports TeX. It reads and writes TexMath equations. It can read Mathtype equations on any LibreOffice/java supported platform (Linux, for example). (Warning: after importing an msword document into LibreOffice you must first save it in .odt format for this to work.)

Jex was written in 2002-2003 and never produced very good looking equations in Open/Libre office due to fact that at that time the only way I could figure out how to do it was to insert "hand coded" windows meta-files. Over the years many bugs crept in and new versions of Open/Libre office broke existing functionality. Recent versions of Libreoffice finally provide decent support for the svg vector graphics format and Roland Baudin built a version of TexMaths and Martin Gieseking added to dvisvgm the ability to produce scalable "font-free" TeX fonts from DVI files. The result are scalable - including in pdf - equations in Libreoffice that look good.  I patched TexMath so that Baudin's code can be used by Jex, and Jex now inserts nice looking TexMath equations into Libreoffice. I also fixed the bugs and rounded out the functionality so that Jex is now usable and useful for the first time in many years. In the process I simplified the installation a great deal.

jex screenshot

equation in openoffice

Download and Install

Step 0: Install Java, LibreOffice and TeX if you have not already done so.
Step 1: Install dvisvgm.
Step 2: Download the
jex-install.zip and unzip it into the directory of your choice.
In the installation directory you will find a patched version of TexMaths called
texmaths-0.36.dl.oxt and euclid.zip
Step 3: Install the patched version of TexMaths using the LibreOffice extension manager (under tools) - select texmaths-0.36.dl.oxt from the directory you put Jex in. This provides the identical functionality of TexMaths 0.36 and adds two new buttons: the convert button which converts a TexMath object back to TeX in the document and the jex button which run Jex. Jex is fully compatible with TexMaths - any equation created or edited with Jex can be edited with TexMaths and vice-versa (up to the limitation that Jex does not understand all TeX). You will need to close and reopen Libreoffice before the TexMaths toolbar is available.
Step 4: Unzip euclid.zip, read the licensing agreement for the Design Science Euclid fonts and install all the fonts you have unzipped - both the Euclid and Esstix fonts. This can generally be done by double-clicking on the fonts.
Step 5: Run Jex from the installation directory using "java -jar jex.jar" or if your platform supports it by double-clicking the jar file. In Jex, from the help | install "Show Command" get the command for running Jex on the clipboard. If you are in Linux save this someplace so that if you close Jex it won't get lost. Make sure to exit by using the "Immediate Shutdown" option from the File menu: Jex must be opened after Libreoffice to function correctly.
To use Jex you must run LibreOffice with the command line libreoffice --writer "--accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager". If you forget that command the Jex help | install menu "Show Office Command" will remind you and also copy it to the clipboard. Again: make sure to use "Immediate Shutdown" to exit Jex.
Step 6: In LibreOffice click the TexMaths button with the small "J" in the corner. This will bring up a dialog asking you where Jex is. Copy the command line from step 5. You may also wish to assign a keyboard shortcut to Jex. I recommend ctrl-m which is also the Jex shortcut for closing the window and updating the equation in the document.

Downloads: Stable Binary(old version 12) Latest Binary(version 199) . Installation zipfile. (Note that the jar files contain the source code along with the executables.) If you use the stable version, you should rename jex-stable.jar to jex.jar.

Upgrading Jex

Simply replace the jex.jar file in the installation directory with the jex.jar file of your choice (for example, to replace the current version with the stable version, or vice versa).

Known Limitations

If you use the clipboard while in Jex saving the equation to the document will lose the data in the clipboard. When converting mathtype equations to TexMaths sometimes the converted equation is not placed correctly with respect to the text. This is due to an apparent bug in LibreOffice - when a Mathtype equation is deleted the cursor sometimes jumps in an unpredictable way (this is true not just when it is deleted by the program, but also if you delete it yourself).

Changelog

Copyright: Stable version 9 and current version 85 and earlier are placed in the public domain. All subsequent versions are released under the GPL version 2.

Usage: To insert a new equation in LibreOffice, click the Jex button. To edit an existing equation, select it, and click the Jex button. In both cases a Jex window will open. The first time Jex runs it will take a while to load, so be patient. However, even when all Jex windows are closed, Jex will remain running until LibreOffice closes, so subsequent window openings will be reasonably fast. (If you wish to bypass this for some reason use the "Immediate Shutdown" option on the File menu.)

In addition to opening Jex equations, Jex can open and edit Mathtype equations. The document must be saved in .odt format. If you cut and paste any mathtype equations you must save the document before you can read it using Jex. WARNING: when you save the equation back to the document it will be saved in TexMaths format and not in Mathtype format. At this time there is no capability of writing Mathtype compatible equations. NOTE: Jex reads the Mathtype object information directly from the .odt file which is why you must save it in that format before you can edit it.

Equation editing uses keystroke bindings similar to Mathtype or Scientific Workplace; in particular control-j inserts a sub/superscript and control-g make the next character greek. You can find a complete list of keyboard accelerators under the help menu. To insert something into the "User" menu, copy it to the clipboard, then click on the target using any mouse button except the usual one. 

When you are done editing your equation, save it, or use the ctrl-m keystroke accelerator from within Jex to save the equation and close the window. If you are editing an equation, the "save" operation replaces the equation in Openoffice with your edited equation. Otherwise the new equation is inserted at the cursor in Openoffice.

Jex speaks a dialect of both MathML and of LaTex. LaTex is the default format. The paste operation will read the clipboard to determine if it contains TeX or MathML. You can also type TeX directly into equations by hitting \ in the editor. Be aware that hitting the space key will insert your TeX and exit TeX mode. You can also type _ to get a sub(and super)script. Exactly what LaTex is and is not supported by Jex is documented here. MathML support is "more experimental" than TeX support as well as incomplete, and is not documented. Jex can be used to convert from supported TeX to MathML and vice versa, and from Mathtype to both formats, but conversion into Mathtype format is not supported.

Compiling: The source files are contained in the jar file. To compile, change the .jar extension to .zip and unzip the file (in Linux you can just open the .jar file directly with the Archive Manager). The java files should be in a directory called jex, the images in a subdirectory of that directory called images. The supporting jar files in  jex-install.zip must be in your class path. From the superdirectory of the jex directory issue the command javac jex/Jex.java. You can then run the program by java jex/Jex and put it in a jar file using jar jar cvfm jex.jar jex/jmainclass.txt jex. If you want to make modifications, it would be useful if you changed the data in ver.txt to show that this is a different version.

What are the supporting files in jex-install.zip?

The jex-install.zip contains the necessary java support files from openoffice needed to control openoffice from Java. They are probably already installed on your system but are a pain to locate, so I have provided a set of copies and bound the Jex jar file to copies that are in the same directory as the jar file.