Displaying Special Characters
![Facebook](http://www.idlcoyote.com/images/facebook_32.png)
![Twitter](http://www.idlcoyote.com/images/twitter_32.png)
![RSS](http://www.idlcoyote.com/images/rss_32.png)
![Google+](http://www.idlcoyote.com/images/gplus_32.png)
QUESTION: I would like to use the less-than-or-equal sign in a legend on my graphics plot. And, later, I want to make a PostScript file of this figure, using PostScript fonts. Is this possible in IDL?
ANSWER: Well, yes, it is possible. But like many things having to do with PostScript, a bit more complicated than you were hoping it would be.
Editor's Note: This is no longer true. It is actually quite easy to make a less-than-or-equal sign in PostScript. In fact, you can use the Coyote Graphics System routine cgSymbol to create this symbol and others, including Greek symbols, both for output to the display and to PostScript files. You can now embed these symbols in text that you use for plot and axis titles with all Coyote Graphics routines You will find more extensive examples of this in the Coyote Plot Gallery.
IDL> cgPS_Open IDL> cgText, 0.5, 0.5, Alignment=0.5, /Normal, $ 'This is the LESS-THAN-OR-EQUAL ($\leq$) sign.', $ Font=1, Charsize=2.0 IDL> cgPS_Close
To see how much work Coyote Graphics routines save you, let's consider a simple case first: How do you put a less-than-or-equal sign on an IDL graphics plot with the normal, default vector graphics? We need to find the less-than-or-equal sign character. Using IDL on-line help, we look for the word fonts.
IDL> ? fonts
We see the sub-category examples of vector fonts and choose that. It leads to a page of Vector Font Samples. The less-than-or-equal sign is probably a mathematical symbol, so we scroll down to the Math and Special Symbol font category (Font 9). We see something similar to the figure below.
![]() |
Math symbol fonts. |
The table is a bit confusing because the table values are in octal. (Sigh...) We find the less-than-or-equal symbol in the 5th row and 13th column. The proper procedure is to take the octal number associated with the row (14, in this case), multiply it by 10, and add it to the octal number associated with the column (also 14 in this case). So the octal value we are looking for is 14 * 10 + 14 = 154.
It might be handier to know what this value is in decimal notation. We can use IDL to find out:
IDL> Print, "154 108
OK. So let's make a string variable of this.
IDL> le_sign = String(108B)
Now we can use the string in a string expression. Just be sure you switch to the Math font (!9) before you use the symbol and switch back to the default font (!X) afterwards.
IDL> cgDisplay, 300, 100 IDL> cgText, 0.5, 0.5, Alignment=0.5, /Normal, $ 'This is the LESS-THAN-OR-EQUAL (!9' + le_sign + '!X) sign.'
You can see the result in the figure below.
![]() |
The less-than-or-equal sign. |
PostScript Output
Now, what about doing the same thing in PostScript? Naturally, if you don't mind vector fonts in your PostScript output you can use the same expression as above. The result will be identical.
But most of the time when we are producing PostScript output we want higher quality fonts. This means using hardware or true-type fonts. But here are several possible problems to watch out for here. First, your chosen font must support unicode encoding of special symbols. In general, most Type1, True-Type, or OpenType fonts meet this requirement. Many of the older PostScript hardware fonts do not. Second, even those fonts that do support unicode encoding don't always support the special character you have in mind. It is important that you know the details of your particular font.If you are unsure about your font, you might want to check the Unicode web page for additional information.
The second piece of information we must have is the unicode value for the symbol you are interested in. There are several ways to discover this information (for example, you can use the Character Map application on Windows), but character charts are also available on the Unicode web page under the Code Charts item. Note that not all fonts implement the character with the unicode encoding recommended by the Unicode Orgainization. And it is typical that not all possible unicode encodings will be implemeted in your font. Check your font for details.
Using this information, and checking under the Mathematical Operators category, we find the unicode value for the less-than-or-equal sign is 2264. (Note that if you try to use a unicode encoding that is not supported by your font, that the output is typically a small box. That is to say, an incorrect or inappropriate unicode encoding doesn't cause your program to break, it just results in the wrong output.)
I happen to have a true-type font named Century Schoolbook on my computer. (I use a Windows computer and I looked in the Fonts control panel to see what true-type fonts I had. You will have to discover a way to learn this information on your computer.) Let me show you how I would create a less-than-or-equal sign with this font.
First, I want to make the Century Schoolbook font the default font. I type this:
IDL> Device, Set_Font='Century Schoolbook', /TT_Font
Then I am ready to create my PostScript plot.
IDL> thisDevice = !D.Name IDL> Set_Plot, 'PS' IDL> Device, XSize=5, YSize=1, /Inches, Filename='testoutput.ps'
It is extremely important at this point that I put the PostScript device is ISOLATIN mode. Otherwise, the unicode coding will not be recognized.
IDL> Device, /ISOLATIN1
Next, I am ready to draw the output. Notice that I use the !Z format code to select unicode encoding. I also select true-type fonts by setting the Font keyword to 1. (You could alternatively set the !P.Font system variable to 1.)
IDL> cgText, 0.5, 0.5, Alignment=0.5, /Normal, $ 'This is the LESS-THAN-OR-EQUAL (!Z(2264)) sign.', $ Font=1, Charsize=2.0 IDL> Device, /Close_File IDL> Set_Plot, thisDevice
You see the output below.
![]() |
The less-than-or-equal sign in PostScript. |
Version of IDL used to prepare this article: IDL 7.1.2.
Last Updated 3 September 2011