How to write a subscript and superscript in Matlab that will be displayed in Graphical User Interface(GUI)? - user-interface

I want to have a subscript and superscript in my GUI in Matlab. So far I have tried to use x_2 and x^2 and neither of them work. Is there anyone who knows how to do this?
Thanks in advance!

From http://www.mathworks.com/matlabcentral/newsreader/view_thread/158410#398940
You can use an undocumented feature of all Matlab uicontrols, which is
the fact that they use underlying Java Swing controls, and these in
turn accept any valid HTML strings. So you can do the following for
example:
uicontrol('string','<html><b>1<sub>2</sub>3<sup>4</sup>5</b></html>')
This is equivalent to the tex string '\bf1_23^45\rm'. You can set font
faces, colors, sizes, bold/italic and any other valid HTML 3.0
property. It's limited, but should do the trick in most conceivable
cases.
The same is true for tooltips, by the way: try setting multi-line
(<br>) multi-colored (<font color="red"> ... </font>) tooltip once and
you'll never use the standard boring single-line black tooltip
again...
And just in case you were wondering - yes, it also works for menus,
listboxes etc.

Related

Change font style when typing in powerpont

I am using PowerPoint2013 for create a presentation about math. And I do not want to use "equation object". I chose Italic time new roman font and I write for example A=(a1,a2,...) but it show me A=(a1,a2,...) instead of A=(a1,a2,...). Except letters, other characters not to be italic style.
So if a character (that I write) be a letter then automatically must be show italic style, and if not, must be show normal style.
How can I do.
I'll present a few options here:
VBA
You could use VBA to italicise only the letters on a slide. If this is something that could be useful then let me know and I'll give you a few pointers. A few downsides though:
It wouldn't work in real time. Also, not all letters should be italicised when typesetting math; for example, cos(x).
It still won't look great. Times is not a mathematical font.
Beamer
Most university lecturers will use LaTeX with Beamer to create mathematical presentations. It will export each slide as a static .pdf (i.e. you won't be able to use animation other than things appearing one by one), but will look much more professional than powerpoint, and you will be able to take advantage of LaTeX's wonderful maths typesetting.
TeXPoint
I haven't used this myself, but it is a plugin for powerpoint which lets you use LaTeX to typeset equations: http://texpoint.necula.org/
Out of interest, why do you not want to use PowerPoint's built-in equation editor?

displaying fractions in gtk

Is it possible to display fractions in a gtk widget like GtkTextView, presumably via using pango markup? I'm looking for something which is possible to edit by a user, so e.g. a pixbuf with a rendered png file is not ok.
Also I need arbitrarily long enumerators and denominators so
<sup>a</sup>/<sub>b</sub>
is not acceptable.
No, that's not possible. I don't know what your use case is, but to make an editable horizontal fraction (as in $\frac{a}{b}$) I would suggest doing something like putting two GtkEntry widgets without borders into a grid, and draw a line between them (or use a GtkSeparator.) You could even embed this grid inside a GtkTextView if you needed it to be inline.

Is there a way to query CTRun if it includes emoji characters?

I'm doing color transformations on glyphs rendered with CTFontDrawGlyphs, but I do not want to do those transformations to the emoji glyphs, since they have already a meaningful color information.
So, when I have a CTRun of glyphs, can I detect if it is actually emoji/color font?
I can do a string compare to the postscript name with "AppleColorEmoji", but seems awfully wasteful to do all the time, and somewhat hacky if there ever happens to be another font with the same features.
Ah, I can get the symbolic traits with CTFontGetSymbolicTraits, and check for kCTFontTraitColorGlyphs (or kCTFontColorGlyphsTrait), which, while undocumented, is available in the public headers.

Display of Asian characters (with Unicode): Difference in character spacing when presented in a RichEdit control compared with using ExtTextOut

This picture illustrates my predicament:
All of the characters appear to be the same size, but the space between them is different when presented in a RichEdit control compared with when I use ExtTextOut.
I would like to present the characters the same as in the RichEdit control (ideally), in order to preserve wrap positions.
Can anyone tell me:
a) Which is the more correct representation?
b) Why the RichEdit control displays the text with no gaps between the Asian Characters?
c) Is there any way to make ExtTextOut reproduce the behaviour of the RichEdit control when drawing these characters?
d) Would this be any different if I was working on an Asian version of Windows?
Perhaps I'm being optimistic, but if anyone has any hints to offer, I'd be very interested to hear.
In case it helps:
Here's my text:
快的棕色狐狸跳在懶惰狗1 2 3 4 5 6 7 8 9 0
apologies to Asian readers, this is merely for testing our Unicode implemetation and I don't even know what language the characters are taken from, let alone whether they mean anything
In order to view the effect by pasting these characters into a RichEdit control (eg. Wordpad), you may find you have to swipe them and set the font to 'Arial'.
The rich text that I obtain is:
{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 Arial;}}{\colortbl ;\red0\green0\blue0;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\fs22\u24555?\u30340?\u26837?\u33394?\u29392?\u29432?\u36339?\u22312?\u25078?\u24816?\u29399?1 2 3 4 5 6 7 8 9 0\par\pard\'a3 $$ \'80\'80\cf1\lang2057\fs16\par}
It doesn't appear to contain a value for character 'pitch' which was my first thought.
I don't know the answer, but there are several things to suspect:
There are several versions of the rich edit control. Perhaps you're using an older one that doesn't have all the latest typographic improvements.
There are many styles and flags that affect the behavior of a rich editcontrol, so you might want to explore which ones are set and what they do. For example, look at EM_GETEDITSTYLE.
Many Asian fonts come in two versions on Windows. One is optimized for horizontal layout, and the other for vertical layout. That latter usually has the same name, but has # prepended to it. Perhaps you are using the wrong one in the rich edit control.
UPDATE: By messing around with Wordpad, I was able to reproduce the problem with the crowded text in the rich edit control.
Open a new document in Wordpad on Windows 7. Note that the selected font is Calibri.
Paste the sample text into the document.
Text appears correct, but Wordpad changed the font to SimSun.
Select the text and change the font back to Calibri or Arial.
The text will now be overcrowded, very similar to your example. Thus it appears the fundamental problem is with font linking and fallback. ExtTextOut is probably selecting an appropriate font for the script automatically. Your challenge is to figure out how to identify the right font for the script and set that font in the rich edit control.
This will only help with part of your problem, but there is a way to draw text to a DC that will look exactly the same as it does with RichEdit: what's called the windowless RichEdit control. It not exactly easy to use: I wrote a CodeProject article on it a few years back. I used this to solve the problem of a scrollable display of blocks of text, each one of which can be edited by clicking on it: the normal drawing is done with the windowless RichEdit, and the editing by showing a "real" RichEdit control on the top of it.
That would at least get you the text looking the same in both cases, though unfortunately both cases would show too little character spacing.
One further thought: if you could rely on Microsoft Office being installed, you could also try later versions of RichEdit that come with office. There's more about these on Murray Sargent's blog, as well as some interesting articles on font binding that might also help.
ExtTextOut allows you to specify the logical spacing between records. It has the parameter lpDx which is a const pointer to an array of values that indicate the distance between origins of adjacent character cells. The Microsoft API documentation notes that if you don't set it, then it sets it's own default spacing. I would have to say that's why ExtTextOut is working fine.
In particular, when you construct a EMR_EXTTEXTOUTW record in EMF, it populates an EMR_TEXT structure with this DX array - which looking at one of your comments, allowed the RichEdit to insert the EMF with the information contained in the record, whereby if you didn't set a font binding then the RTF record does some matching to work out what font to use.
In terms of the RichEdit control, the following article might be useful:
Use Font Binding in a Rich Edit Control
After character sets are assigned, Rich Edit scans the text around the
insertion point forward and backward to find the nearest fonts that
have been used for the character sets. If no font is found for a
character set, Rich Edit uses the font chosen by the client for that
character set. If the client hasn't specified a font for the character
set, Rich Edit uses the default font for that character set. If the
client wants some other font, the client can always change it, but
this approach will work most of the time. The current default font
choices are based on the following table. Note that the default fonts
are set per-process, and there are separate lists for UI usage and for
non-UI usage.
If you haven't set the characterset, then it further explains that it falls back to ANSI_CHARSET. However, it's most definitely a lot more complicated than that, as that blog article by Murray Sargent (a programmer at Microsoft) shows.

Changing font tracking in Cocoa

I'm doing some text rendering in Cocoa using NSAttributedString, and setting the font and underline properties, etc. However, I can't figure out how I can change the text's tracking. Any suggestions?
I don't think font tracking is an exposed property for text layout with attributed strings.
You could perhaps use the available expansion attribute on whitespace, and manually insert whitespace characters with scaling factors to influence their width, but I expect that would be a fiddly hack for anything other than trivial cases.
The only other route I can think of is to use your own custom attributes along with an NSLayoutManager subclass. The cocoa text system is extremely flexible, but with that flexibility comes a greater degree of complexity.
My solution so far has simply been to use the kerning attribute, as tracking and kerning are similar. Is there any better solution?

Resources