From hintak_leung at yahoo.co.uk  Mon Oct 31 22:56:25 2011
From: hintak_leung at yahoo.co.uk (Hin-Tak Leung)
Date: Mon, 31 Oct 2011 21:56:25 +0000 (GMT)
Subject: [Rd] Sweave, cairo_pdf, xetex, CJK (Re:  Sweave, cairo_pdf, CJK,
	ghostscript)
In-Reply-To: <1319837755.2360.YahooMailClassic@web29514.mail.ird.yahoo.com>
Message-ID: <1320098185.89713.YahooMailClassic@web29515.mail.ird.yahoo.com>

I am still doing some cosmetic things (adding annotations with some of the really minority languages in Sichuan), but here are a few misc tips and quirks so far:

- cairo_pdf() behaves differently via "R CMD Sweave <file>" vs Sweave("file") within R. The former produces a lot of warnings about not being able to determine strwidth and have to substitute. Probably understandable, but still annoying.

- It generates pdf 1.5 - when used in combination with xetex, - which uses xdvipdfmx for pdf generation, and xdvipdfmx has the rather disturbing behavior of *silently* *skipping* included pdf's that's higher than the default (instead of do it with warning like pdfTeX) so no graphics will be included, unless xetex is run with -output-driver="xdvipdfmx -V 5"... to declare to output pdf 1.5 .

- xetex needs noae in \usepackage{SWeave}. FWIW, Werner Lemberg's CJK (the LaTeX package) can work without declaring noae, so that's my preferred choice at the moment, although I have got both of them working, for doing Chinese in a LaTeX document.

I think some of these information should go into the man page of cairo_pdf()...

--- On Fri, 28/10/11, Hin-Tak Leung <hintak_leung at yahoo.co.uk> wrote:

> Reading ?RWeaveLatex more carefully,
> I worked out that the outcome I want could be achieved
> without patching R, by having this towards the beginning:
> 
> <<custom=hide>>=
> ? cairo <- function(name, width, height, ...)
> ? grDevices::cairo_pdf(file = paste(name, "pdf", sep =
> "."),
> ? ? ? ? ? ? ? ?
> ? ? ???width = width, height =
> height)
> @
> 
> Then declaring grdevice= like this:
> 
> <<another1,fig=TRUE,pdf=FALSE,grdevice=cairo,eval=TRUE,width=6,height=3>>=
> grid.text("\u4F60\u597D", y=2/3,
> gp=gpar(fontfamily="CNS1"))
> @
> 
> So all is well. is there any chance of either updating
> ?RWeaveLatex with this actual use-case example, or make it
> easier with the attached patch (and updated version of what
> I did, just adding the corresponding documentation)? I
> thought there might be a a use for cairo_ps() as well, but
> then most people who can do latex could do pdflatex,
> especially those who has cairo installed.
> 
> FWIW, besides Chinese, I am doing Tibetan and Arabic as
> well - needed/wanted those two for Sichuan (south-western
> China) and Ningxia (northern western, just south of
> Mongolia).
> 
> --- On Sun, 23/10/11, Hin-Tak Leung <htl10 at users.sourceforge.net>
> wrote:
> 
> > --- On Sat, 22/10/11, Prof Brian
> > Ripley <ripley at stats.ox.ac.uk>
> > wrote:
> > 
> > > On Sat, 22 Oct 2011, Duncan Murdoch
> > > wrote:
> > > 
> > > > On 11-10-21 8:57 PM, Hin-Tak Leung wrote:
> > > >> I have had some fun in the last few
> days
> > trying to
> > > put together an annotated map of China with R
> and
> > some
> > > public GIS data:
> > > >> 
> > > >> http://sourceforge.net/projects/outmodedbonsai/files/snpMatrix%20next/1.17.7.11/China_Choropleth_Maps.pdf/download
> > > >> 
> > > >> It is done, and rather nice... there are
> a
> > few
> > > issues:
> > > >> 
> > > >> - the default pdf() device cannot do
> CJK
> > with
> > > embedded fonts - and cairo_pdf() is not hooked up
> to
> > Sweave
> > > yet. I have had a quick look, and it does not
> look
> > too
> > > complicated, other than the fact that cairo_pdf()
> is
> > > mutually exclusive with pdf(); and the jpeg/png
> are
> > new to
> > > 2.13 so it is probably just nobody has gotten
> round to
> > it.
> > > (and cairo_pdf() also behaves differently with
> the
> > onefile
> > > option). I guess I am almost saying I might get
> my
> > hand
> > > dirty or help somebody else who wants to. So it
> is
> > probably
> > > best to start some discussion.
> > > > 
> > > > It is not hard to write your own device
> > functions,
> > > especially in 2.14.0.? See rgl::rgl.Sweave for
> an
> > > example.
> > > 
> > > And guess what the example in the Sweave manual
> > uses??
> > > cairo_pdf() ...
> > 
> > I don't want a new device - I just wanted cairo_pdf()
> to be
> > hooked up to Sweave as an alternative to the default
> pdf().
> > See my later post with the patch against? R trunk
> and
> > the worked examples.
> > 
> > It looks like cairo_pdf() is just using my current
> > fontconfig settings.
> > 
> >



[Rd] Sweave, cairo_pdf, xetex, CJK (Re: Sweave, cairo_pdf, CJK, ghostscript)
Hin-Tak Leung