File Exchange

image thumbnail


version (7.67 KB) by

Displays a LaTeX string as an image.

29 Ratings



View License

If you have LaTeX already installed, this function will convert LaTeX strings into images and display them in figures.

Comments and Ratings (33)


Ben (view profile)

Very nice function!

John de Leon

Hi Ben, does this also work with the latest releases of MATLAB?


Pawel (view profile)

Does not work under Ubuntu 10.04 with XeLaTex. Requires corrections in the code.


so good !

Luis Rozas

Clark W

Can we reduce the size of the exported result when using
print -deps ...

jack nice

Can we add the package \usepackage[latin5]{inputenc}

Eddie Fiorelli

Yup, I had to make the same change on line 340.

Martin Mooslechner

In addition to the 'tex' -> 'latex' change I also had to change the format of the fullfile-String. it contained '\', latex thought of it as an escape character...

I added:
add to line 640: cmd=regexprep(cmd, '\', '/');

to change all the '\' to '/'.
works fine after that...


Joaquin Orias

Jurgen Theiss

This is exactly what I was looking for. It works beautifully. However, I also had to make the change from 'tex' to 'latex' on line 340 as pointed out by Peter Lawrence below.

Jeramy Ashlock

I made the change to line 340 (tex->latex) butI get the message

Error running Ghostscript: /bin/bash: /usr/local/matlab/sys/ghostscript/bin/glnx86/gs: /lib/ bad ELF interpreter: No such file or directory

I make symlinks to the newer libraries, e.g.
ln -s /lib/ /lib/, etc... but this doesn't work. I aso tried to symlink the 'gs' binary in the matlab directory to /usr/bin/gs, with more error messages.

I'm using R12 on fedora core 2.

Theodore Sande

Just what I require !

Peter Lawrence

Very pleased, makes matlab plots look very professional.
As with Jøger's point, texpoint did not work for me in my newly installed WinXP+MiKTeX until I changed the string 'tex' to 'latex' in line 340.

Jøger Hansegård

Nice! For Windows+Miktex, change 'tex' to 'latex' in line 340: fullfile(texbin,['tex' exe_ext]).
At least, this works for me.

ZL Guo


Federico Forte

Great, great, great!!!

John Long

I have MikTeX installed, but the m-file doesn't work. What executable should I define in the setup?

Wang Gang

Very good!
Maybe you can add the following codes to enable AMSMATH package. A shortcoming is that the saved .fig file has a too big size.


Stefan Schlamp

There is a problem with the resizing function if the figure also contains a legend. You want to change the function "figuremoved" in the file to include the line


The whole function would then read:
function figuremoved(fig);
fpos = convertUnits(get(fig,'units'),get(fig,'position'),'inches');
H = findall(fig,'type','image','tag','teximage');
for h=H
ax = get(h,'parent');
hunits = getappdata(h,'units');
if hunits(1) == 'n'
apos = get(ax,'pos');
pos = getappdata(h,'position');
center = convertUnits(hunits,[pos 10 10],'inches',fpos,'inches');
apos(1:2) = center(1:2) - .5*apos(3:4);

In my case, this did not cause problems when no legend was present.

Madhusudhan Chellappa

Very usefull. And very easy to use.
Thanks Ben

roby Zopope

It's great

Steeve Ambroise

Steeve Ambroise

Daniel Zajfman

This is very good!

Praveen Malhotra

This is great! I was looking for this for a long time.

Byunghun Kim

Very good!

Yordan Kyosev

Thanks !

Rahul Shah

Great and nifty utility... I will now be using this regularly to plot figures and include Latex equations. Very easy to use. Absolutely recommended for Matlab/Latex users. Thanks, Ben!

Philipp Baecker


Dingyu Xue

Perfectly done work. It is recommended that all the MATLAB/LaTeX users install this work to make their work graphics easier and beautiful.

It is suggested that one can interactively moves the image in the axis with a mouse.

Sebastien PARIS

A Must Have !!!!. Works great !!!.

A Wish ?. Yes could matlab ha a better Latex support ?
because teximage is very usefull but size files increase
too much (due to the bitmap convertion of the Latex string)


Updated license


remove email address


BSD update

added quotes when calling the OS so that paths can have spaces in them.

MATLAB Release
MATLAB 5.3 (R11)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video