How do you use the LaTeX blackboard font in MATLAB?

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';

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

  2. 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.

Leave a Comment