2

This question could be linked to this, this and this. However, I opened a new one because I tried two different options from the suggestions and getting different results.

The aim is to get consistent font in latex document (scrbook) when graphs/diagrams are plotted using R. I see two basic approaches.

1) Using tikzDevice and following piece of code

library(tikzDevice)
tikz("rtikzFile.tex" )
plot(1,1,xlab="Real count")
dev.off()

this generates a rtikzFile.tex file which I include with the main.tex file. This works nicely. However, I have many contour, spatial plots, for which the tex file could be really really big. I heard from a colleague of mine that TeX also have a word limit for compilation (though it is a very high value but for a phd thesis with tikzDevice it could be achievable.)

Output --

enter image description here

2) Using extrafont in R and following piece of code

library(extrafont)
 loadfonts()
 pdf("extrafontR.pdf",family="CM Roman")
 plot(1,1,xlab="Real count") 
 dev.off()

I have installed the CM Roman fonts as instructed here. Output --

enter image description here

Now, if I compare the results of the two approaches, the font looks different. I checked this with Mac Preview and Acrobat Reader. This looks completely wrong in default viewer of TeXStudio (less important). I am more concern for the fonts in pdf viewer. I would like to get the same output as in approach 1) but using approach 2). This way, I will have more control on my figures and compile time for tex will be lesser.

My questions are --

  1. Am I using correct font and settings?
  2. Is this to do with my pdf viewer? OR
  3. Should I ask this ok SO instead?**

P.S. My knowledge about fonts is very limited.

novice
  • 1,108
  • 4
    I'm voting to close (or move) this question as off-topic because this question would fit much better at http://stackoverflow.com due to its broad scope. – novice Jul 14 '16 at 12:00

1 Answers1

3

Personally I do not know much about R, but helped prepare a book that used R plots throughout back in 2012. The book is set in Kp-fonts and we wanted as much as we could in that font from R as well (all titles and legends were replaced via psfrag to get proper LaTeX formatting of those, but handling the numbers on axis was a bit too much for psfrag.

Here is more or less what I did at that time

(1) Copy all the appropriate .pfb and .afm files for Kp-fonts into the folder where I have the R files.

(2) Create Kp-fonts.R with this content:

KP <- Type1Font("KpFonts",
                      c("./jkpmn8a.afm", "./jkpbn8a.afm",
                        "./jkpmit8a.afm", "./jkpbit8a.afm",
                        "./jkpssmn8a.afm"),
                      encoding="default"
                      )

(3) start all R files via

source("Kp-fonts.R")

#pss
postscript(family = KP,file="name.eps",useKerning=FALSE)
#pse

The generated EPS is then available for psfrag later. The useKerning is vital for psfrag as R might otherwise apply kerning to the text and thus example is no longer example as a string in the EPS.

daleif
  • 54,450
  • Thanks. By "R files" in (1), do you mean the R installation directory or R scripts? I have R scripts at many directories and sub-directories and copying it too many places is not nice (in my opinion). – novice Jul 13 '16 at 10:59
  • @Amit I only had this single project where all the R files were in one folder. And as I mentioned I know almost nothing about R, so I do not know where to generally place R files in your setup so you can use them in several locations. – daleif Jul 13 '16 at 11:38
  • I will give this a shot and it it works, I will write back here or just add it to your answer. – novice Jul 13 '16 at 11:40