Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use the LaTeX blackboard font in MATLAB?

So, based on my question and solutions here, I would like to actually start using LaTeX, in figures as seen. However, one problem I am running into, is that I cannot seem to display the Expectation operator.

From my research, I know that the expectation operator can be displayed as such normally as such:

/mathbb{E} 

However, when I try to use it in MATLAB, nothing prints out.

clear all
figure(1); clf(1);
set(gcf, 'color', 'white'), axis off     %# Remove axes and set white background
my_text = '$$ \mathbb{E} $$';
text('units', 'inch', 'position', [-0.5 3.5], 'fontsize', 14, 'color', 'k', ...
    'interpreter', 'latex', 'string', my_text);

Now, I know that the \mathbb is some sort of different 'library', but frankly it is quite useful for mathematical formulations. How do I 'include' it in MATLAB? I am lost on this.

like image 767
Spacey Avatar asked Sep 03 '12 15:09

Spacey


1 Answers

You might not have noticed it, but you get an warning message in the command prompt:

Warning: Unable to interpret TeX string

which tells you that MATLAB has trouble parsing your LaTeX expression. More specifically, the blackboard bold math font (indicated by the '\mathbb') is not supported by MATLAB's built-in LaTeX interpreter (it requires the amsmath package).

One way to install this package is described here and here. I'll summarize it for you:

  1. Download the AMS-LaTeX package from here.

  2. Modify the m-file tex.m, which is located in the MATLAB root\toolbox\matlab\graphics folder (backup the file before modifying it):

    2.1. In the localDecorateInputString function, modify standardhead to include the new packages (marked in bold):

    standardhead = [' \nofiles \documentclass{mwarticle} \usepackage{amsfonts, amsbsy, amssymb} \begin{document}']

    2.2. In the localGetTeXPath function, add the paths of where the AMS package files are located (marked in bold), for instance:

    texpath{1} = blah blah blah...
    texpath{end+1} = blah blah blah...
    texpath{end+1} = 'C:\amslatex\';

  3. Copy all .sty files of the AMS package to the MATLAB root\sys\tex folder.

  4. Restart MATLAB.

You should now have the necessary LaTeX font packages installed. I would've gladly checked it out myself if time allowed, it seems promising.

like image 78
Eitan T Avatar answered Sep 28 '22 00:09

Eitan T