[R] Graphics and LaTeX documents with the same font

Frank E Harrell Jr f.harrell at vanderbilt.edu
Fri Sep 28 16:57:39 CEST 2007


jiho wrote:
> On 2007-September-28  , at 15:18 , Paul Smith wrote:
>> On 9/28/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>>>> I know how to export graphics as pdf files and then how to include
>>>> them in LaTeX documents. However, I do not know how to do in  
>>>> order to
>>>> have the text of the graphics written with the font selected for the
>>>> LaTeX document. Is that possible?
>>> Well, it depends on what that font is.  But if it is TeX font,
>>> see the section called 'TeX fonts' in ?postscript and the detailed
>>> description in the article in R-news 6/2 by Paul Murrell and myself.
>>>
>>> If it is an Adobe Type1 font such as Times New Roman, just specify an
>>> appropriate family in the pdf() call.
>>>
>>> Dietrich Trenkler wrote:
>>>
>>>> maybe you will find the psfrag package useful.
>>> I doubt it will be even usable with PDF (there are pdfrack and  
>>> Xfigfrag,
>>> though), and with postscript it is at best a kludge as R does its own
>>> micro-positioning of text based on the font metrics.
>> Thanks to both. PSTricks
>>
>> http://en.wikipedia.org/wiki/PSTricks
>>
>> draws figures that, when inserted in a LaTeX document, their font
>> matches the one selected for the LaTeX document. If I may, I would
>> like to submit to your consideration the suggestion of implementing
>> the exportation of R graphics to PSTricks.
> 
> If you don't mind an extra step between R and LaTeX, you could use  
> Inkscape to modify your graphics:
> 	http://www.inkscape.org/
> It is a (very nice!) vector graphics editor which:
> - works with SVGs (as produced with the RSvgDevice package)
> - imports PDFs (really well in the latest development version)
> - is available for free, on most platforms
> and
> - exports PDFs that nicely integrate in LaTeX documents
> - exports PSTricks graphics
> Then two roads are opened for you:
> 1- either get a TTF version of the LaTeX fonts (there are packages  
> for this on all linux distros I know, for use with Lyx and you can  
> probably find them on the web otherwise) and change all the fonts to  
> those once your document is in Inkscape (select all > text and font >  
> select the font)
> 2- or open the document with inkscape and export it to pstricks
> 
> I personally use Inkscape on all my R graphics because I find it  
> easier and quicker to get decent graphics and R and refine their look  
> in Inkscape than to get them perfect in R in one shot ( though with  
> ggplot2 things are improving on R's side).
> 
> Cheers,
> 
> JiHO

As this works against principles of reproducible research, I wouldn't 
recommend it.

Frank

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list