# [R] metapost device in R (again ;-)

Paul Murrell p.murrell at auckland.ac.nz
Mon Jul 14 05:02:31 CEST 2003

Hi

Tamas Papp wrote:
> Hi,
>
> I read the 2000 thread on a MetaPost device in R. If I understand
> correctly, the main problem with the concept is that R wants the device
> driver to give back information on the size of strings/labels.
>
> To the bet of my knowledge, MetaPost _does_ make it possible to
> measure the bounding box of text (see section 7.3: Measuring text in
> the MetaPost manual). For example, one could get the size of the
> bounding box of btex $\int_a^b x^2$ etex -- would that be enough to
> make an implementation possible? Or are the size of individual
> characters and kerning information necessary?

Kerning information is not required, but a device driver does need to
provide information on the size of individual characters (or return
zeroes which in some cases will prompt a warning that such information
is not available, but most stuff will still work it just may look a bit
nastier).

> Another question: can graphics devices be implemented solely in R (ie
> without writing C code)? I realize that it will be much slower, but
> first I would like to see how it works before writing in C. What
> source files should I be looking at?

Unfortunately, you can't write a device driver solely in R -- all the
hooks are at the C-level.  You need to look at ...

R/src/include/R_ext/GraphicsDevice.h

... for a description of the device structures and function calls you
have to fill in, and see one of the existing device drivers, e.g., ...

R/src/modules/X11/devX11.c

... for an example of how an existing device does the filling in.

> You may ask why I should bother about using Metapost. Well, I'd like
> my TeX documents to be more consistent typographically, and MP has
> quite a lot of useful features (such as the possibility to include its
> eps output in LaTeX directly, EVEN when generating PDF files with
> latexpdf). But the biggest bonus would clearly be the ability to
> typeset math formulas nicely. (I realize that this would require one
> to start a MetaPost process, but IMO the benefits would be worth the

I assume that you know about the mathematical annotation facilities in R
-- help(plotmath) -- and want something "nicer" ...

Paul
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz