# Why do my UICONTROLs not display TeX commands correctly?

59 views (last 30 days)
I have created a pushbutton UICONTROL and I would like the 'String' property to contain a Greek letter, but the TeX command is displayed instead of the Greek character.
For example, the following command creates a pushbutton labelled "\beta":
uicontrol('String', '\beta')

MathWorks Support Team on 10 Jul 2009
UICONTROLs cannot handle TeX commands.
As a workaround, you can take advantage of the characters available in each fontset's character mapping. See the attached file, chart.m, that will help you access the available characters for any specified font on your system.
You can use the results by converting the hexadecimal value obtained from the chart into a decimal value, and then into a character. Here is an example:
chart('arial')
% Notice that the "squared" symbol is located at B2
figure
str = char(hex2dec('B2'));
h1 = uicontrol('String',['m/s',str], ...
'Style','text');
For pushbuttons and togglebuttons, another workaround involves setting the UICONTROL's 'CData' property to the image data of a TeX image obtained from a TeX application. This requires that you have a TeX application installed.
There are many ways that you can implement this workaround, and the following is one example. This example uses MiKTeX from http://www.miktex.org as the TeX application. It also uses a user-contributed function, teximage.m, which can be found on MATLAB Central at the following URL:
This function will convert a LaTeX string into an image and display it in a figure. It can also return the 3D color matrix required for the 'CData' property mentioned earlier. When using this function to generate the 'CData', you will have to pay attention to the optional input parameter, 'resolution', which defines the font resolution. This will help you to obtain the appropriately sized 3D color data matrix that will fit in the button. NOTE: Some font resolutions are not supported and will produce an error.
Provided that you have MiKTeX installed and have put teximage.m on your MATLAB path, You can use the following example as a guide for this workaround:
texstr = 'Process: $\bar{x} = \beta \times \sqrt{x+1}$';
I = teximage('-noHG',texstr, ...
'displaymode','none', ...
'background',get(0,'defaultuicontrolbackgroundcolor'), ...
'resolution',100,'antialias','off');
hpb = uicontrol('cdata',I,'units','pixels','position',[100 100 175 30])

### Products

MathWorks Support

### Community Treasure Hunt

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

Start Hunting!