[Tikzdevice-bugs] Context and tikz?

Charlie Sharpsteen chuck at sharpsteen.net
Tue Apr 19 04:16:58 CEST 2011


Hi Mat,

On Mon, Apr 18, 2011 at 6:54 AM, Matthieu Stigler <
matthieu.stigler at gmail.com> wrote:

>  Charlie
>
> Thanks a lot for actually looking at my r-list e-mail, and trying to sort
> out, much appreciated!!!
>
> So for the bad news: too bad indeed, hoped it would be possible, and would
> have been an elegant solution (current solution is to hack the .ps, very
> ugly).
>
> For the good news, I could not evaluate how good they are :-) I'm getting
> more and more confused, discovering new Tex-like things at each e-mail :-)
> Basically, your suggestion is: should use context which should entail
> METAPOST figure code, right? And METAPOST code could be generated from the
> tikz one? I am totally fine to forget about features like raster or
> polypath, but you think conversion from tikz to metapost would be easy? Just
> watched the tikz and metapost code and still seemed quite different, no? If
> it would be done once, I guess it's on the far roadmap? We are in the
> situation where we need to be able to convert to pentone our R plots in a
> few days :-(
>

Sorry for the confusion. What I ment is that the tikzDevice could be
modified to produce METAPOST code instead of TikZ code because the syntax of
the two languages is similar. Till Tantau, the creator of TikZ, was inspired
by METAPOST and adopted a lot of ideas such as the path construction syntax.
Over the weekend, I took a stab at re-building the tikzDevice as a METAPOST
device. The results are available in the `experimental/metapost` branch of
the git repostiory:

  https://github.com/Sharpie/RTikZDevice/tree/experimental/metapost
  https://github.com/Sharpie/RTikZDevice/tarball/experimental/metapost

To use this branch, will need to install 'roxygen' and run `make install`
inside the package source. There are a few caveats with this branch:

   - The new device has full support for filling and drawing---however I
   didn't have time over the weekend to translate the text handling routines.
   Font metrics are still calculated by LaTeX instead of ConTeXt which causes
   some of the text strings to be mis-aligned.  Additionally, there is no
   support for applying colors or font sizes to text.
   - There is no documentation.
   - If we do add METAPOST support to a later release (which I hope we
   will!), it may have a completely different interface and functionality.

After installing the package, a new `metapost` device will be available:

    metapost('my_plot.tex')

The output must be typeset with ConTeXt MKIV (I did my testing with the
version from TeX Live 2010). If you have not run ConTeXt before, you may
need to do some set up:

    luatools --generate
    context --make

The `metapost` device produces output similar to `tikz` in the `standAlone =
TRUE` mode, so the resulting `.tex` files are compiled directly:

    context my_plot.tex

I also re-wired the way colors are handled so that spot colors can be
defined:

    metapost('spot_colors.tex')
    % Define a spot color
    define_metap_color("Red", 'red', 'Spot Color Red')

    plot(BOD, col = 'red')

    dev.off()

The `define_metap_color` function takes three parameters:

   - The first is a string containing only letters, no spaces or numbers,
   that is used as the color name in the TeX output.


   - The second is a string containing a R color name, or a RGB vector
   c(r,g,b) containing the rgb value as numbers in the range 0-255


   - The third parameter is the spot color name and is optional. If used, it
   will cause the creation of a spot color channel that will be named using the
   contents of the string.

For example, the call used above would cause the following color definition
in the ConTeXt file:

 \definecolor
   [Red]
   [r=1.000,g=0.000,b=0.000]

 \definespotcolor
   [RedSpot]
   [Red]
   [p=1,e=Spot Color Red]


All the points in the BOD graph will be defined using the color RedSpot and
the resulting PDF output should have a new color channel named "Spot Color
Red" that contains the information for the points.  If you want to use
PANTONE colors, you will have to look up the color names in a PANTONE swatch
book and compute (or guess) the corresponding RGB values:

define_metap_color('PantoneBlue', 'blue', 'PANTONE 308 CV')


Now, this will assign all colors matching R's RBG vale for 'blue' to the
'PANTONE 308 CV' spot color channel. I don't know if assigning colors to
spot channels is all that is required to do a professional print job, so I
would definitely encourage consulting a professional before attempting to
use any of these PDFs in a large scale print job.

I don't know if this experiment will help you or not, but it gave me some
good ideas on where to take the tikzDevice for future releases.  It would be
nice to add color separation to our list of features someday!

-Charlie


> Thanks so much, your help is very precious!
>
> Mat
>


More information about the Tikzdevice-bugs mailing list