Fanning Software Consulting

Creating a Sun Symbol

Facebook Twitter RSS Google+

QUESTION: When I use the \sun symbol in cgPlot titles with output to a PDF file, it comes out with the dot not centered in the ring. Is there something I can do about that? I usually use it as a subscript but just the symbol by itself also has this problem.

Here is an example.

   IDL> cgPlot, [0, 1], [0, 1], XTitle='$\sun$', Output='test.pdf'

ANSWER: Creating an astronomically correct sun symbol has been a 20 year issue for IDL. But, with the addition of the DejaVuSans True-Type font in IDL 8, it has become possible to create a sun symbol with the dot in the center. Since this requires using a True-Type font, it really only applies to hardcopy and raster file output. The Hershey font solution is still problematic. (See the SunSymbol program in the NASA IDL Astronomy Library, for example.)

If you are using Coyote Graphics routines, all you have to do is select the DejaVuSans font as the default True-Type font.

   IDL> cgSet_TTFont, 'dejavusans'

Then the sun symbol will be rendered correctly, using the normal cgPlot command.

   IDL> cgPlot, [0, 1], [0, 1], XTitle='$\sun$', Output='sunsymbol.png'

You see the results in the figure below.

An astronomically correct Sun Symbol.
An astronomically correct Sun Symbol.
 

If you wish to use the sun symbol as a subscript, use a double slash (\\) to specify the symbol inside the subscript annotation, like this.

   IDL> cgPlot, [0, 1], [0, 1], XTitle='M / M$\sub\\sun$', Output='sunsymbol.png'

You see the results in the figure below.

An astronomically correct Sun Symbol as a subscript.
An astronomically correct Sun Symbol as a subscript.
 

If you don't use Coyote Graphics, you can use Function Graphics (where the DejaVuSans font is always the default font), like this.

   IDL> p = Plot([0, 1], [0, 1], XTitle='M / M$_{\Sun}$')

Or, if you just use straight direct graphics, and you have IDL 8 or higher, you can use the format code !10 to switch to the DejaVuSans font and draw the sun symbol. Remember, however, that you must use True-Type fonts (e.g., !P.Font=1).

   IDL> Plot, [0, 1], [0, 1], XTitle='M / M!D!10!Z(2609)!X!N', FONT=1, CharSize=2.0

Version of IDL used to prepare this article: IDL 8.2.3

Written: 5 December 2014