Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When using LaTeX as the interpreter to typeset labels in MATLAB it would be great to be able to include packages to customize appearance. Is this possible?

As of now I know no method to create non italic greek letters in the legends.

share|improve this question
    
Depending on what you need, you might be interested in matlab2tikz. –  G. Poore Feb 18 '13 at 21:14

1 Answer 1

up vote 2 down vote accepted

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.

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.