MATLAB has the ability to "publish" code as an html document. It can include math by taking equations keyed in LaTeX notation, processing it with latex and embedding a bitmap image into the html. An example MATLAB file would be

% With this equation, $x(t) = y(t)$, MATLAB only processes the math with LaTeX

running the MATLAB publish function would essentially internally convert this to

$x(t) = y(t)$

although everything may be enclosed in an \hbox. I can't really follow all the details of the MATLAB code as some of it is closed source.

\begin{edit} One potentially important piece of information I just found is that the MATLAB version of the article class has \input{size1\@ptsize.clo} commented out with the following comment

%% The following line causes the HG text to offset vertically and horizontally.

Apparently the good people at the Mathworks don't understand how to deal with LaTeX margins. Needless to say, this is why commands like \large don't work even when stuck in an \hbox. \end{edit}

The problem appears to be that MATLAB only processes the math with LaTeX. In how to scale math font only, you appear to need to be outside the math environment to change the font size. Is it possible to change the math font size from within the math environment? I think the MATLAB parser decides when to start and stop processing with latex based on $'s. Maybe there is some other way to exit mathmode.

  • Did you try $\hbox{<font scaling command>$...$}$? Jan 28, 2013 at 12:48
  • Commands such as \tiny,\huge,etc should also work within the equation environment. However I don't think they work within the $$ environment. I'm not sure there is a way to do this in latex. But it seems there is a hack in matlab that will allow you to rescale: mathworks.de/matlabcentral/newsreader/view_thread/102987
    – myrtille
    Jan 28, 2013 at 12:55
  • @HendrikVogt That approach doesn't work. What happens is that MATLAB essentially creates two tex files. The first containing $\hbox{<font scaling command>$ and the second with $}$. I was trying to express that problem with the last two sentences of the question.
    – StrongBad
    Jan 28, 2013 at 13:01
  • 1
    @myrtille I don't think traditional font resizing (i.e., \huge) works in math mode. I am trying to avoid hacking the MATLAB script
    – StrongBad
    Jan 28, 2013 at 13:03
  • @DanielE.Shub It works inside the equation-environment, but not inside the $$ is what my test showed. Which is what I meant to say in my previous post. Sorry for the confsion
    – myrtille
    Jan 28, 2013 at 13:24

1 Answer 1


I can't quite see what matlab is doing less latex works than I would expect, however this sort of works to make the first expression larger:

So after a bit of trial and error and discussion in comments most of latex is enabled but you need to switch out of math mode, use a lower level font size change such as \fontsize{20}{25}\selectfont for 20pt font, and then switch back into math mode using \( not $ so as not to confuse matlab's scan for math fragments.

enter image description here

% With this equation, 
% MATLAB only processes the math with LaTeX

% $$e^{\pi i} + 1 = 0$$
% With this equation, $\hbox{\fontsize{20}{25}\selectfont\(z(t) = w(t)\)}$, MATLAB only processes the math with LaTeX
  • 3
    I think I found a reason MATLAB is doing less LaTeX then you expected. The MATLAB class is mwarticle.cls and it is essentially the same as article.cls, except they do not load \input{size1\@ptsize.clo} so no size commands work. The comment in the code suggests they did this because they didn't understand the margins and not to prevent the sizing.
    – StrongBad
    Jan 28, 2013 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .