Error in the creation of a Greek letter in a GUI

1 visualización (últimos 30 días)
Jacopo
Jacopo el 23 de Mayo de 2014
Comentada: Igor Jasmim el 12 de Oct. de 2016
Hello. I expose my question. I have tried to insert Greek letters in a static text following the procedure at the link:
I put in the Property Inspector in the entry "Tag" latex_text5 and under "String" \ alpha. However, in the command window I get the following warning:
Warning: Unable to interpret LaTeX string "\ alpha" > In openfig at 135    In gui_mainfcn> local_openfig at 286    In gui_mainfcn at 234    In GUI_prova2 at 42
What should I do to see the Greek letter alpha in the static text?
  6 comentarios
Jacopo
Jacopo el 23 de Mayo de 2014
I have everything set up through the property inspector . : (
I wrote this in OpeningFcn :
GUI_prova2_OpeningFcn function ( hObject , eventdata , handles, varargin ) % This function has no output args , see OutputFcn . % HObject handle to figure % Eventdata reserved - to be defined in a future version of MATLAB % Handles structure with handles and user data ( see TOUR ) % Varargin command line arguments to GUI_prova2 ( see varargin )
% Choose default command line output for GUI_prova2 handles.output = hObject ;
handles.laxis = axes ( ' Parent ' , hObject , 'units ' , ' normalized ' , 'position ' , [0 0 1 1] , ' visible', ' off ' ) ;
lbls = findobj ( hObject , ' -regexp ' , ' tag ' , ' latex_ * ' ) ;
for i = 1 : length ( lbls )       l = lbls ( i) ;       % Get current text , position and tag       set ( l, 'units ' , ' normalized ' ) ;       s = get ( l, ' string') ;       p = get (l, 'position' ) ;       t = get (l, ' tag ' ) ;       % Remove the Uicontrol       delete ( l) ;       % Replace it with a TEXT object       handles. (t) = text ( p (1 ) , p ( 2 ) , s, ' interpreter ' , ' latex' ) ; end
% Update handles structure Wizard ( hObject , handles) ;
and this in the Property inspector :
String - > \ alpha Tag - > latex_text5
Can you help me please ? Tell me please what should I write exactly . thank you very much
Jacopo
Jacopo el 23 de Mayo de 2014
This is what I wrote in the code, neither more nor less. I have also attached images of what appears before and after the run and what I wrote in the Property inspector.
% --- Executes just before GUI_prova2 is made visible.
function GUI_prova2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI_prova2 (see VARARGIN)
% Choose default command line output for GUI_prova2
handles.output = hObject;
handles.laxis = axes('parent',hObject,'units','normalized','position',[0 0 1 1],'visible','off');
lbls = findobj(hObject,'-regexp','tag','latex_*');
for i=1:length(lbls)
l = lbls(i);
% Get current text, position and tag
set(l,'units','normalized');
s = get(l,'string');
p = get(l,'position');
t = get(l,'tag');
% Remove the UICONTROL
delete(l);
% Replace it with a TEXT object
handles.(t) = text(p(1),p(2),s,'interpreter','latex');
end
% Update handles structure
guidata(hObject, handles);

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 24 de Mayo de 2014
Warning: Unable to interpret LaTeX string "\ alpha"
> In openfig at 135
In gui_mainfcn> local_openfig at 286
In gui_mainfcn at 234
In GUI_prova2 at 42
...What should I do to see the Greek letter alpha in the static text?
Well, I built a new GUI w/ just a single uicontrol and voila! was able to reproduce your error.
The problem is that for LaTeX the string '\alpha' must be in the math environment it turns out (enclosed in '$' signs. Otherwise, it's attempted to be interpreted in text mode and that fails spectacularly. Set the text in the Property Inspector to
This is a Greek alpha: $\alpha$
and joy will ensue...
Whew....learned something about LaTeX...
  3 comentarios
dpb
dpb el 25 de Mayo de 2014
Editada: dpb el 25 de Mayo de 2014
You're welcome...was an experience. I went back and cleaned up the sidebar conversation most of which was owing to my using a complicated sample GUI figure rather than building a single uicontrol. NB: that the script supplied by TMW only works for positioning on a UI that doesn't contain grouping boxes because it doesn't convert the positions for items within from those relative coordinates to absolute so the positioning of elements within them is incorrect. That was what I saw in first testing and presumed it was related to your problem which it wasn't.
Also, note that the problem you had really has no bearing on the GUI but was simply an issue w/ LaTeX syntax--I use LaTeX so infrequently over the default TeX it was new to me, too, so that took a while to discover, as well. The issue can (and actually, is how I finally did resolve it) be seen directly from text w/o the GUI around at all.
To work around any issues going forward, try
text(0.5,0.5,'\alpha','interpreter','latex')
text(0.5,0.5,'\alpha','interpreter','tex')
simply from the command line. Note also that the error from the failure in the 'LaTeX' interpreter doesn't necessarily show up on the command line until later--the actual failure may (and often is initially) just that nothing shows up in the figure.
Igor Jasmim
Igor Jasmim el 12 de Oct. de 2016
amazing!!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by