Mathematica and LaTeX Integration

This document is about Mathex, a software package that allows to embed Mathematica © macro expressions into a LaTeX document, combining together the power of the two systems. It works in this way: when You click F2 on your preferred editor, before of the TeX to PDF conversion, a pre-processor (written in the PERL language) call Mathematica, do the computation globally (i.e. treating the file as a single program) and replaces the macros in the final TeX. The macros should be inserted between the two conventional simbols , and can contain every valid Mathematica’s expression, or more espressions, separated by semicolon. As every expression and every graphics object get created everytime on-the-fly, the process can be slow.


Special Formattings
A macro <% ... %> can have a (limited) number of options (opt->value) after the '|' symbol. An option modify some secondary aspects of output: Examples: 1. Characters dimension: <% x^3/(1-x) | tiny %>: This allow to use the Mathematica engine in order to compose complex formulas, that otherwise would be reduced and/or simplified.

Graphics
The system creates a graphic file if the last expression of the macro produces a Mathematica Graphics[] object. You can obtain the simplest graphs directly from the standard plotting functions (Figures 2 and 3       Each graphs file is saved in the directory ./eps, under the current path.
For the Mathematica graphical primitives, please consults a Mathematica book.

Caching
With the efficiency in mind, the system call Mathematica only if needed. For example, if You change only the text and no equations at all, the program will try to reuse the previous results. This caching activity is a sperimental feature, so it is possible to disable it, adding the following directive:

Requirements
This sofware is available (and tested) only on the Linux Operating System, and its derivatives. The install.sh command copy the files in the installation directory (usually $HOME/.math) and integrate that software with the supported editors (Lyx, Emacs and Vim).

Customization
Mathex calls Mathematica via a script wrapper. You can find the script (called math.run) in the installation directory. A little tuning allows to use local (or sudo) installation, or also remote Mathematica host (via ssh).

Usage
If You are using a supported editor, the <F2> shortcut should be available. As alternative, you can pre-process by yourself with the command: #/path/to/replace.pl file.in > file.out As the Lyx editor is concerned, we suggest to insert the macros <% ...%> using the Lyx TeX blocks (with Control-L) (Figure 7).

Disclaimer
The Mathex package (the PERL code and BASH scripts contained) is copyrighted (©)2004-2016 Michele Andreoli. It is distributed under the GNU Free Documentation License.
Of course, I disavow any potential liability for the contents of this document.
Use of the concepts, examples, and/or other content of this document and related software is entirely at your own risk.