6

I am running Matlab R2010A on OS X 10.7.5

I have a simple matlab plot and would like to use LaTeX commands in the axis and legend. However setting:

set(0, 'defaultTextInterpreter', 'latex');

Has zero effect, and results in a TeX warning that my tex commands can not be parsed. If I open plot tools of this plot, the default interpreter is set to 'TeX'. Manually setting this to 'LaTeX' obviously fixes this, but I can't do this for hundreds of plots.

Now, if I retrieve the default interpreter via the Matlab prompt, i.e get(0,'DefaultTextInterpreter')

It says 'LaTeX', but again, when I look in the properties of the figure via the plot tools menu, the interpreter remains set to 'TeX'.

Complete plotting code:

figure
f = 'somefile.eps'
set(0, 'defaultTextInterpreter', 'latex'); 
ms = 8;
fontSize = 18;
loglog(p_m_sip, p_fa_sip, 'ko-.', 'LineWidth', 2, 'MarkerSize', ms); hold on;
xlabel('$P_{fa}$', 'fontsize', fontSize);
ylabel('$P_{m}$', 'fontsize', fontSize);
legend('$\textbf{K}_{zz}$', 'Location', 'Best');
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on', 'YGrid', 'on', 'XGrid', 'on');
print('-depsc2', f);
Maurits
  • 2,082
  • 3
  • 28
  • 32
  • This might be silly, but have you tried `set(0,'defaultTextInterpreter','LaTeX')` instead of `set(0,'defaultTextInterpreter','latex')`? – Adam27X Nov 23 '12 at 20:49
  • @Adam27X. Sorry, it doesn't work.. – Maurits Nov 23 '12 at 21:02
  • @Maurits try changing the `DefaultTextInterpreter` property of the title/axes themselves... – Eitan T Nov 23 '12 at 21:55
  • Usually i just put in latex strings without $ and It works. I am not sure about textbf, though. – Acorbe Nov 23 '12 at 22:07
  • @EitanT Very sorry, but `set(gca, 'defaultTextInterpreter', 'latex')` or `gcf` or `legend` or to the figure handle doesn't help. – Maurits Nov 23 '12 at 22:19
  • @Acorbe But `$ ...$` denotes LaTeX math mode. Anyway, I did try your suggestion, and it didn't make a difference for me. – Maurits Nov 23 '12 at 22:20

1 Answers1

15

This works for me (R2011B)

figure
ms = 8;
fontSize = 18;

xx = 0:.1:1;
plot(xx,sin(xx))

xlabel('P_{fa}', 'fontsize', fontSize);  %No need for latex explicitly (Tex is enabled by default)
ylabel('P_{m}', 'fontsize', fontSize);

legend({'$$\textbf{K}_{zz}$$'}, 'interpreter', 'latex','fontsize',fontSize); %Explicit latex
      %REM: legend needs a cell

enter image description here

I can change 'defaultTextInterpreter'

set(0, 'defaultTextInterpreter', 'latex'); 

xlabel('$$P_{fa}$$', 'fontsize', fontSize);
ylabel('$$P_{m}$$', 'fontsize', fontSize);

legend({'$$\textbf{K}_{zz}$$'},'interpreter', 'latex','fontsize',fontSize)

obtaining the better version

enter image description here

If I remove 'interpreter', 'latex' from the legend call, I have bad results, though:

enter image description here

Acorbe
  • 8,367
  • 5
  • 37
  • 66
  • That is brilliant, thanks a lot. One thing if I may, where could I have found this in the documentation? – Maurits Nov 23 '12 at 23:05