You can't get TeX to find text in a png the way it does for psfrag
as essentially the information just isn't there (even if TeX could read the binary file). However if the png image has no text at all you can overlay latex text over it. there are packages to help that but you don't really need a package.
\includegraphics{file.png}%
\begin{picture}(0,0)
\put(-100,2){label 1}
\put(-100,-22){label 2}
\end{picture}
overlays the two labels over the image. Of course you have to judge the coordinates by eye or some external measurement.
Background
There is no easy way to do this, but there are a 3 ways to hack it. To understand how to control the MATLAB LaTeX interpreter, you need to understand how it works. When MATLAB processes a LaTeX string it calls tex.m
. The MATLAB tex
function appends
\nofiles \documentclass{mwarticle} \begin{document}\setbox0=\hbox{
and prepends
}\copy0\special{bounds: \the\wd0 \the\ht0 \the\dp0}\end{document}
to the string. MATLAB then calls a closed source compiled function texmex
which appears to call a tex
binary. MATLAB comes with a very limited TeX installation, so even if you could load a package file, you would need to tell MATLAB where to look.
MATLAB has a built in feature that lets you control where to look. You can control this with
setappdata(0, 'TeXPath', PackagePath);
where the variable PackagePath
contains the full path to the package. You can do this from the MATLAB command line or in a script or function.
3 ways
There are 3 ways that you can get MATLAB to load a package. Two require you to modify/overload MATLAB functions and are complete solutions. The final one doesn't require any modifications of MATLAB functions, but won't work in all cases.
The first way is to load a package via \input
instead of \usepackage
. This is because you cannot use \usepackage
after \begin{document}
. This may not work and I don't know if you can use \input
inside an \hbox
.
The second way is to modify mwarticle.cls
to load the packages you want. This will load the package for all MATLAB LaTeX strings.
The third way is to modify tex.m
to conditionally load packages through a mechanism like
getappdata(0, 'TeXPackages', Packagelist);
this requires knowing MATLAB to make the changes and could theoretically break something. If you go this way, you may also want to modify tex.m
to call your local latex
binary and not the potentially out of date MATLAB one.
Best Answer
After quite a lot of hours, in a random check of the resulting pdf file, i realized that the eps images appear as expected and very nice indeed. So, i don't want to jump into conclusions but the whole thing might have to do with TexMaker's pdf preview (of course related to a interpretation issue as mentioned above). If anyone faced the same problem, I would like to hear his solution too.