So Long Arial

October 5, 2011 at 4:00 am 8 comments

| Gabriel |

Now that I’ve been looking into setting my graphs in a serif font instead of the default Arial, I find that changing fonts in Stata graphs is surprisingly difficult. It’s not that it’s intrinsically difficult, just confusing to learn because Stata’s handling of fonts breaks with the general Stata convention of specifying options as part of a command and is instead more similar to the Gnuplot style of changing device preferences then executing a command targeting the device. One implication of this is that there’s no option to change the graph font in the graph GUI interface (which is how I usually learn new bits of command-line syntax).

Another issue is that graphs aren’t WYSIWYG. Rather the interactive display graph can look different from the graph saved to disk and that in turn can be inconsistent depending on what file format you use. To avoid confusion I just set everything at once, like this:

local graphfont "Palatino"
graph set eps fontface `graphfont'
graph set eps fontfaceserif `graphfont'
graph set eps  /*echo back preferences*/

graph set window fontface `graphfont'
graph set window fontfaceserif `graphfont'
graph set window /*echo back preferences*/

One of the oddities is that there is no set of PDF options. Rather (at least on a Mac) you control the PDF device as part of the display device (“window”). My understanding is that Stata for Mac relies on the low level OS X PDF support for creating PDFs, and this would explain why it considers PDF to be part of the display device rather than one of the file type devices (as well as why it won’t make PDFs if you suppress screen rendering, why Stata for Mac got PDF support earlier than the other platforms, and why the PDFs looked like this until they fixed it in 11.2 and 12). Note that this means that your PDF will use the EPS fonts if you use my graphexportpdf.ado script and the display fonts if you use the base “graph export foo.pdf” syntax.

I haven’t checked, but I wouldn’t be surprised if the PDF preferences in Stata for Windows are controlled by the EPS preferences rather than the display preferences. In any case, I recommend just setting all devices the same so it won’t matter.

(Thanks to Eric Booth, whose StataList post, helped me figure this out).

About these ads

Entry filed under: Uncategorized. Tags: , .

Adding elements to graphs as a slideshow Importnew.ado (requires R)

8 Comments

  • 1. Eric Booth  |  October 5, 2011 at 7:34 am

    “I haven’t checked, but I wouldn’t be surprised if the PDF preferences in Stata for Windows are controlled by the EPS preferences rather than the display preferences. In any case, I recommend just setting all devices the same so it won’t matter.”

    I tried this in a Win7, Stata 12 environment and couldn’t get the font typeface to change for a graph exported to PDF. I could change the graph window font using the Edit>Preferences>Graph Preferences drop-down, or the -graph set window fontface “”- command, and I could change the font for the EPS exported figure with -graph set eps fontface “”-, but I couldn’t get the PDF font to change. I might be doing something wrong since I don’t use the windows version of Stata very often, but it seemed like odd behavior.

    I started using ‘georgia’ font in Stata graphs since it seems to complement CM when included in LaTeX docs – but after running your examples, I’m starting to think Palatino looks better for these docs.

    • 2. gabrielrossman  |  October 5, 2011 at 8:14 am

      Interesting. Sounds like Windows users who want to change fonts will have to go back to the old trick of first creating an EPS in Stata and then using Distiller or Ghostscript to convert to PDF.

    • 3. gabrielrossman  |  October 6, 2011 at 5:59 pm

      ps, when did you do this experiment? i ask because Stata reports a bug fix related to this issue in the 9/15 update

  • 4. Eric Booth  |  October 7, 2011 at 7:12 am

    I tried this on Oct 5th – I just checked and Stata (v. 12 Windows 7) was up to date with the 9/15 update.

  • 5. Yisu  |  March 21, 2012 at 6:26 pm

    Hi, thanks for the post, which solves part of my problem. I am working cross-platform (Win 7 & Mac version of Stata). I tried your solution. It worked in Stata 12 on both platforms. Interestingly, I wish to replace Palatino with other serif font. I tried two fonts: Calibri and CMU Serif. Neither worked on a mac. I mean, the graph looks normal (with correct font) on mac, it’s just when I use graph export for .eps file, the font changed back to default (Helvatica, I believe). But Stata for windows has no problem what so ever to do exactly the same work. The graph looks normal and the export is ok (it also look normal when I open the windows-generated .eps file on Mac). I am really puzzled by this.

    • 6. gabrielrossman  |  March 21, 2012 at 6:35 pm

      Weird, it may be that those fonts aren’t installed on your Mac. My own Mac has Calibri (probably because I own Word) but I don’t see CMU Serif. Try using another serif font that’s in the base installation for both Windows and OS X, maybe Garamond or Times.

  • 7. Arsenio  |  August 9, 2012 at 9:20 pm

    Gabriel, faced the same problem and found this info on your blog. Have you had any luck changing fonts for graph PDF exports in the newest Stata 12.1 for Win? It would seem this bug is still there. The only workaround is to export through EMF but then converting to PDF creates a strange faint grey frame outline in the PDF which you have to edit out in the PDF itself (Adobe Acrobat Pro X).

    Would greatly appreciate any updates or any info you or the visitors to this page have found!

    Arsenio

    • 8. gabrielrossman  |  August 9, 2012 at 10:13 pm

      weird, can’t say i’ve come across those issues or know how to fix them. good luck


The Culture Geeks

Recent Posts


Follow

Get every new post delivered to your Inbox.

Join 1,477 other followers

%d bloggers like this: