Tips & Tricks
Follow


Oleg Komarov

Greek alphabet and latex commands [not a question]

Oleg Komarov on 30 Aug 2011
Latest activity Reply by Neil Henry on 9 Dec 2021

Capital letters are obtained by capitalizing the LaTeX command for the lowercase version. Capital letters in grey are exceptions which have no LaTeX commands. For example, to produce a capital chi simply type X (this also applies for the lowercase omicron).
When two versions of the lowercase letter are available, a var prefix can be added to obtain the second version. For example, the two versions of epsilon are \epsilon and \varepsilon.
--------------------------------------------------------------------------------------------------------------------------------------------------------
The code used to generate the table:
greeks = ...
{'ALPHA' 'A' '\alpha'
'BETA' 'B' '\beta'
'GAMMA' '\Gamma' '\gamma'
'DELTA' '\Delta' '\delta'
'EPSILON' 'E' {'\epsilon','\varepsilon'}
'ZETA' 'Z' '\zeta'
'ETA' 'H' '\eta'
'THETA' '\Theta' {'\theta','\vartheta'}
'IOTA' 'I' '\iota'
'KAPPA' 'K' '\kappa'
'LAMBDA' '\Lambda' '\lambda'
'MU' 'M' '\mu'
'NU' 'N' '\nu'
'XI' '\Xi' '\xi'
'OMICRON' 'O' 'o'
'PI' '\Pi' {'\pi','\varpi'}
'RHO' 'P' {'\rho','\varrho'}
'SIGMA' '\Sigma' {'\sigma','\varsigma'}
'TAU' 'T' '\tau'
'UPSILON' '\Upsilon' '\upsilon'
'PHI' '\Phi' {'\phi','\varphi'}
'CHI' 'X' '\chi'
'PSI' '\Psi' '\psi'
'OMEGA' '\Omega' '\omega'};
h = figure('units','pixels','pos',[300,100,620,620],'Color','w');
axes('units','pixels','pos',[10,10,600,600],'Xcol','w','Ycol','w',...
'Xtick',[],'Ytick',[],'Xlim',[0 6],'Ylim',[0,4]);
% Loop by column and row
for r = 1:4
for c = 1:6
el = (r-1)*6 + c;
% Title
text(c-0.5,5-r,greeks{el,1},'Fonts',14,'FontN','FixedWidth',...
'Hor','center','Ver','cap')
% Color cap latter in grey or black
if strcmp(greeks{el,2}(1),'\')
clr = [0, 0, 0];
else
clr = [0.65, 0.65, 0.65];
end
% Cap letter
text(c-0.5,4.87-r,['$\rm{' greeks{el,2} '}$'],'Fonts',40,...
'Hor','center','Ver','cap','Interp','Latex','Color',clr)
% Lowercase letter/s (if two variants)
if iscell(greeks{el,3})
text(c-0.75,4.48-r,['$' greeks{el,3}{1} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
text(c-0.25,4.48-r,['$' greeks{el,3}{2} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
% Latex command
text(c-0.5,4.3-r,['\' greeks{el,3}{1}],'Fonts',12,'FontN','FixedWidth',...
'Hor','center','Ver','base')
else
text(c-0.5,4.48-r,['$' greeks{el,3} '$'],'Fonts',20,...
'Hor','center','Interp','Latex')
text(c-0.5,4.3-r,['\' greeks{el,3}],'Fonts',12,'FontN','FixedWidth',...
'Hor','center','Ver','base')
end
end
end
% Print to pdf
export_fig greeks.pdf
The link to export_fig.
And here is the link to the pdf on scribd: http://www.scribd.com/doc/159011120/Greek-alphabet-in-latex
Neil Henry
Neil Henry on 9 Dec 2021
It was quite helpful for me.
Kirsten
Kirsten on 15 Jun 2016
This is useful. I'm trying to add a text box with \rho in it, but for some reason it looks like \varrho (pi looks normal, sigma also looks like varsigma), which I don't like. If I actually use \varrho, it doesn't see that as a character. Any ideas?
Walter Roberson
Walter Roberson on 16 Jun 2016
Testing, I find HTML rho and varrho can display the same in some of the fonts. Font names Arial and Symbol and Times New Roman (and probably others) distinguish them. I suggest you experiment with a font change.
Walter Roberson
Walter Roberson on 27 Sep 2013
There is a hack you can use for some uicontrol styles, and for uitable entries. This hack relies upon the fact that MATLAB uses HTML underneath some items.
The below works for styles pushbutton, togglebutton, radiobutton, checkbox, listbox, and popupmenu, but does not work for style 'edit' or 'text' or 'slider' or 'frame'.
1) To create a string with Greek characters in a uicontrol, create the uicontrol with one of the noted styles, and set the String properly specially.
  • At the very beginning of the String property, put '<HTML>' (or '<html>'). There must not be anything before that in the String property, not even a space.
  • Then have the normal string until you need the Greek character.
  • At that point, put in the HTML Character Entity equivalent of the character you want, starting with ampersand and ending with semi-colon. Each Greek character must have its own leading ampersand and trailing semi-colon; you cannot combine multiple entities.
  • If you code the entity name in all lower-case or all upper-case, the result will be the lower-case version of the character. If, however, you code with a leading capital letter and the rest lowercase, then the capital letter version will be used.
  • Then continue with the other elements of the string.
  • At the end of the string you want presented, you can just stop, but if you like to be complete, you could add '</HTML>' at the end.
Example:
uicontrol('Style', 'push', 'String', '<HTML>&omega;&Alpha;&tau;&Epsilon;&rho;&epsilon;&Rho;' )
You might have noticed that all of the uicontrol styles that support this character encoding normally have callbacks. (uicontrols of style 'text' and 'edit' are allowed to have callbacks, but in practice 'text' style uicontrols would not have a callback specified.)
Unfortunately, setting 'hittest' to 'off' on uicontrol elements has no effect, so one cannot take the simple route.
You can get rid of the action of the callback by setting the 'enable' property of the uicontrol to 'off'. If you do that, then any color will be removed from the text, and the text will be dimmed, making it harder to read. Setting the uicontrol 'fontweight' to 'bold' helps a bit.
If you are looking to emulate a uicontrol static text but with greek characters, then possibly the most effective way is to use style 'pushbutton' instead, leave 'enable' 'on', but ensure there is no (useful) callback. Unfortunately this will "frame" the text with a rounded rectangle.
If you want to be more perfectionist, then you should probably be reading Undocumented MATLAB.
2) To create an entry in a uitable with Greek characters:
  • ensure that the column format is String. As every entry in a column in a uitable must be the same format, then if you want to present numbers anywhere in the same column, you will need to convert the numbers to strings -- and conversely, if you want the user to be able to edit such an entry, you will later need to convert the cell array entry from string to number to get the new value the user entered.
  • encode the string for the cell array in the same manner as shown above, with '<HTML>' leading and ampersand encoding of the Greek characters.
Lisheng Su
Lisheng Su on 8 Aug 2013
Nice!
Walter Roberson
Walter Roberson on 3 Jan 2013
Walter Roberson
Walter Roberson on 15 Jun 2012
Perhaps the char() codes could be added in as well? e.g., char(945) is lower-case alpha.
Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer on 15 Jun 2012
Marking this as answered.
Walter Roberson
Walter Roberson on 30 Aug 2011
Nice table. I thought from previous discussions that some of those were not available!