MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: Matlab and Latex

Subject: Matlab and Latex

From: Omkar Palsule-Desai

### Omkar Palsule-Desai

Date: 16 Nov, 2008 10:16:02

Message: 1 of 7

Hi,

I am trying to have a legend of a graph in Matlab as '\overline{W}' (this is a latex style). However, I am getting the output as 'overline W'. I do get correct output of other Latex command on the same graph. May I get some suggestions on this?

Thank you,

Omkar

Subject: Matlab and Latex

From: Walter Roberson

### Walter Roberson

Date: 16 Nov, 2008 16:57:55

Message: 2 of 7

Omkar Palsule-Desai wrote:

> I am trying to have a legend of a graph in Matlab as '\overline{W}' (this is a latex style).
> However, I am getting the output as 'overline W'. I do get correct output of other Latex
> command on the same graph. May I get some suggestions on this?

Is the Interpreter property for the legend definitely set to 'latex' ?
The default is 'tex'.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Matlab and Latex

From: Omkar Palsule-Desai

### Omkar Palsule-Desai

Date: 16 Nov, 2008 17:34:01

Message: 3 of 7

Hi,

I am not sure if I got your message. I am giving the command as
legend{'\alpha', '\overline{W}'}

I am getting '\alpha' typed in correctly, but I get 'overlineW' as the output.

I am not sure what is wrong here.

Omkar

Walter Roberson <roberson@hushmail.com> wrote in message <ciYTk.20332$us4.2917@newsfe14.iad>... > Omkar Palsule-Desai wrote: > > > I am trying to have a legend of a graph in Matlab as '\overline{W}' (this is a latex style). > > However, I am getting the output as 'overline W'. I do get correct output of other Latex > > command on the same graph. May I get some suggestions on this? > > Is the Interpreter property for the legend definitely set to 'latex' ? > The default is 'tex'. > > -- > .signature note: I am now avoiding replying to unclear or ambiguous postings. > Please review questions before posting them. Be specific. Use examples of what you mean, > of what you don't mean. Specify boundary conditions, and data classes and value > relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?  Subject: Matlab and Latex From: Doug Schwarz Date: 17 Nov, 2008 01:39:11 Message: 4 of 7 In article , "Omkar Palsule-Desai" wrote: > Hi, > > I am trying to have a legend of a graph in Matlab as '\overline{W}' (this is > a latex style). However, I am getting the output as 'overline W'. I do get > correct output of other Latex command on the same graph. May I get some > suggestions on this? > > Thank you, > > Omkar There is no built-in option for using latex in legends, but you can trick it. Try this: plot(x1,y1,x2,y2) % or whatever your plot is % Use legend text that's about the width of the final result. h = legend('a','W'); % Find the first text object (alpha) and change it. h1 = findobj(get(h,'Children'),'String','a'); set(h1,'String','$\alpha$','Interpreter','latex') % Find the second text object (W) and change it. h2 = findobj(get(h,'Children'),'String','W'); set(h2,'String','$\overline{W}$','Interpreter','latex') -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address. Subject: Matlab and Latex From: Bob Gilmore ### Bob Gilmore Date: 3 Dec, 2008 16:53:33 Message: 5 of 7 Doug, It's not necessary to go "poking around" inside of the legend; the handle to a legend has an Interpreter property that you can set: >> plot(1:10) >> legend('$\overline{W}$') >> h = legend; >> set(h, 'interpreter', 'latex') Hope that helps, -- Bob Gilmore, The MathWorks, Inc. "Doug Schwarz" <see@sig.for.address.edu> wrote in message news:see-64E789.20391116112008@news.frontiernet.net... > In article <gfort2$lr4$1@fred.mathworks.com>, > "Omkar Palsule-Desai" <omkardpd@iimahd.ernet.in> wrote: > >> Hi, >> >> I am trying to have a legend of a graph in Matlab as '\overline{W}' (this >> is >> a latex style). However, I am getting the output as 'overline W'. I do >> get >> correct output of other Latex command on the same graph. May I get some >> suggestions on this? >> >> Thank you, >> >> Omkar > > > There is no built-in option for using latex in legends, but you can > trick it. Try this: > > plot(x1,y1,x2,y2) % or whatever your plot is > > % Use legend text that's about the width of the final result. > h = legend('a','W'); > > % Find the first text object (alpha) and change it. > h1 = findobj(get(h,'Children'),'String','a'); > set(h1,'String','$\alpha$','Interpreter','latex') > > % Find the second text object (W) and change it. > h2 = findobj(get(h,'Children'),'String','W'); > set(h2,'String','$\overline{W}$','Interpreter','latex') > > -- > Doug Schwarz > dmschwarz&ieee,org > Make obvious changes to get real email address.  Subject: Matlab and Latex From: Doug Schwarz Date: 3 Dec, 2008 21:15:46 Message: 6 of 7 In article , "Bob Gilmore" wrote: > Doug, > It's not necessary to go "poking around" inside of the legend; the handle to > a legend has an Interpreter property that you can set: > > >> plot(1:10) > >> legend('$\overline{W}$') > >> h = legend; > >> set(h, 'interpreter', 'latex') > > Hope that helps, > -- > Bob Gilmore, The MathWorks, Inc. Hi Bob, Thanks for that info. Actually, I suspected that and tried legend('$\overline{W}$','Interpreter','latex') but it doesn't work. You have to get the handle and set the interpreter afterwards. Why is that? It's counter to normal handle graphics syntax. -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address. Subject: Matlab and Latex From: Stefan ### Stefan Date: 3 Dec, 2008 21:43:02 Message: 7 of 7 Hi there, for including pictures in latex i would advise you to search the file exchange for 'laprint'. Really a great tool. Regards, Stefan Doug Schwarz <see@sig.for.address.edu> wrote in message <see-6A6590.16154603122008@news.frontiernet.net>... > In article <gh6diq$f71$1@fred.mathworks.com>, > "Bob Gilmore" <bgilmore@mathworks.com> wrote: > > > Doug, > > It's not necessary to go "poking around" inside of the legend; the handle to > > a legend has an Interpreter property that you can set: > > > > >> plot(1:10) > > >> legend('$\overline{W}$') > > >> h = legend; > > >> set(h, 'interpreter', 'latex') > > > > Hope that helps, > > -- > > Bob Gilmore, The MathWorks, Inc. > > > Hi Bob, > > Thanks for that info. Actually, I suspected that and tried > > legend('$\overline{W}\$','Interpreter','latex')
>
> but it doesn't work. You have to get the handle and set the interpreter
> afterwards. Why is that? It's counter to normal handle graphics syntax.
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.