Wolfram Library Archive

All Collections Articles Books Conference Proceedings
Courseware Demos MathSource Technical Notes


Will Thomson
Organization: University of Birmingham
Revision date


This is a package based on matlab2tikz (http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz) for converting Mathematica figures to tikz code for inclusion in LaTex documents. At present the package can only deal with 2-D plots.

The output is a .tikz file which can be included in a 'figure' environment in Latex using the command \input{filename.tikz}. The .tikz file can be fine-tuned in any text editor (e.g. if you don't like the x or y limits, you can change them easily in the tikz file).

Example implementation:

- You first need to put the package somewhere Mathematica can find it. An easy way is to evaluate SystemOpen[FileNameJoin[{$BaseDirectory, "Applications"}]] in Mathematica and paste Mathematica2Tikz.m into the directory that opens.

In Mathematica:

This produces a file called figure_1.tikz in the indicated directory. The file contains the code for a tikz figure of the function f(x) = Exp[-(.2*x+Sin[x]) with x-label 'x' and y-label 'f(x)'.

In LaTeX (this is just an example, see matlab2tikz documentation/tutorials for options and usage):

\begin{figure} \newlength\figureheight \newlength\figurewidth \setlength\figureheight{6cm} \setlength\figurewidth{6cm} \centering \input{figure_1.tikz} \end{figure}

The .tikz file can be customised as you wish. For example, changing the values of xmin, xmax, ymin, ymax has the obvious effect on the tikz image produced.

*Information Science and Technology > Mathematical Typesetting > TeX

LaTeX, tikz