From a6e8eed93629b4f50c0f8f9b8dbe7d158a3f0f51 Mon Sep 17 00:00:00 2001 From: Hendrik Buschmeier Date: Fri, 26 Aug 2016 01:20:09 +0200 Subject: [PATCH] Added argument to provide additional options to tikzpicture. * Added an argument pictureOptions to the R function `tikz`. * Added the argument to the C function `TikZ_Setup` and the structure tikzDevDesc. * Made use of the argument, if provided, in the the C function `TikZ_StartDevice`. * Added R documentation and rebuild documentation with roxygen. * Added argument to vignette (in sec. 3.2 'Usage') --- R/tikz.R | 7 +++++-- man/tikz.Rd | 5 ++++- src/tikzDevice.c | 11 ++++++++--- src/tikzDevice.h | 4 +++- vignettes/tikzDevice.Rnw | 8 +++++++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/R/tikz.R b/R/tikz.R index c9a7f46..d276457 100644 --- a/R/tikz.R +++ b/R/tikz.R @@ -112,6 +112,8 @@ #' @param verbose A logical value indicating whether diagnostic messages are #' printed when measuring dimensions of strings. Defaults to `TRUE` in #' interactive mode only, to `FALSE` otherwise. +#' @param pictureOptions A character string that contains additional options +#' provided to the tikzpicture environment. Defaults to the empty string. #' #' @return `tikz()` returns no values. #' @@ -221,7 +223,8 @@ tikz <- function(file = ifelse(onefile, "./Rplots.tex", "./Rplot%03d.tex"), symbolicColors = getOption("tikzSymbolicColors"), colorFileName = "%s_colors.tex", maxSymbolicColors = getOption("tikzMaxSymbolicColors"), timestamp = TRUE, - verbose = interactive()) { + verbose = interactive(), + pictureOptions = "") { tryCatch( { # Ok, this sucks. We copied the function signature of pdf() and got `file` @@ -308,7 +311,7 @@ tikz <- function(file = ifelse(onefile, "./Rplots.tex", "./Rplot%03d.tex"), TikZ_StartDevice, file, width, height, onefile, bg, fg, baseSize, lwdUnit, standAlone, bareBones, documentDeclaration, packages, footer, console, sanitize, engine, symbolicColors, colorFileName, maxSymbolicColors, - timestamp, verbose + timestamp, verbose, pictureOptions ) invisible() diff --git a/man/tikz.Rd b/man/tikz.Rd index 17c8061..5af3695 100644 --- a/man/tikz.Rd +++ b/man/tikz.Rd @@ -14,7 +14,7 @@ tikz(file = ifelse(onefile, "./Rplots.tex", "./Rplot\%03d.tex"), width = 7, symbolicColors = getOption("tikzSymbolicColors"), colorFileName = "\%s_colors.tex", maxSymbolicColors = getOption("tikzMaxSymbolicColors"), timestamp = TRUE, - verbose = interactive()) + verbose = interactive(), pictureOptions = "") } \arguments{ \item{file}{A character string indicating the desired path to the output @@ -99,6 +99,9 @@ to the TeX file.} \item{verbose}{A logical value indicating whether diagnostic messages are printed when measuring dimensions of strings. Defaults to \code{TRUE} in interactive mode only, to \code{FALSE} otherwise.} + +\item{pictureOptions}{A character string that contains additional options +provided to the tikzpicture environment. Defaults to the empty string.} } \value{ \code{tikz()} returns no values. diff --git a/src/tikzDevice.c b/src/tikzDevice.c index 58064a7..7560e45 100644 --- a/src/tikzDevice.c +++ b/src/tikzDevice.c @@ -172,6 +172,7 @@ SEXP TikZ_StartDevice ( SEXP args ){ int maxSymbolicColors = asInteger(CAR(args)); args = CDR(args); Rboolean timestamp = asLogical(CAR(args)); args = CDR(args); Rboolean verbose = asLogical(CAR(args)); args = CDR(args); + const char *pictureOptions = CHAR(asChar(CAR(args))); args = CDR(args); /* Ensure there is an empty slot avaliable for a new device. */ R_CheckDeviceAvailable(); @@ -203,7 +204,7 @@ SEXP TikZ_StartDevice ( SEXP args ){ if( !TikZ_Setup( deviceInfo, fileName, width, height, onefile, bg, fg, baseSize, lwdUnit, standAlone, bareBones, documentDeclaration, packages, footer, console, sanitize, engine, symbolicColors, colorFileName, - maxSymbolicColors, timestamp, verbose ) ){ + maxSymbolicColors, timestamp, verbose, pictureOptions ) ){ /* * If setup was unsuccessful, destroy the device and return * an error message. @@ -249,7 +250,8 @@ static Rboolean TikZ_Setup( const char *packages, const char *footer, Rboolean console, Rboolean sanitize, int engine, Rboolean symbolicColors, const char* colorFileName, - int maxSymbolicColors, Rboolean timestamp, Rboolean verbose){ + int maxSymbolicColors, Rboolean timestamp, Rboolean verbose, + const char *pictureOptions ){ /* * Create tikzInfo, this variable contains information which is @@ -315,6 +317,7 @@ static Rboolean TikZ_Setup( tikzInfo->onefile = onefile; tikzInfo->timestamp = timestamp; tikzInfo->verbose = verbose; + tikzInfo->pictureOptions = calloc_strcpy(pictureOptions); /* initialize strings, just to be on the safe side */ strscpy(tikzInfo->drawColor, "drawColor"); @@ -2291,7 +2294,9 @@ static void TikZ_CheckState(pDevDesc deviceInfo) if ( tikzInfo->bareBones != TRUE ) { - printOutput(tikzInfo, "\\begin{tikzpicture}[x=1pt,y=1pt]\n"); + printOutput(tikzInfo, "\\begin{tikzpicture}[x=1pt,y=1pt%s%s]\n", + tikzInfo->pictureOptions[0] != '\0' ? "," : "", + tikzInfo->pictureOptions); if( tikzInfo->symbolicColors && tikzInfo->outColorFileName) printOutput(tikzInfo, "\\InputIfFileExists{%s}{}{}\n", tikzInfo->outColorFileName); diff --git a/src/tikzDevice.h b/src/tikzDevice.h index a146d56..1cf8a1d 100644 --- a/src/tikzDevice.h +++ b/src/tikzDevice.h @@ -93,6 +93,7 @@ typedef struct { char fillColor[32]; Rboolean timestamp; Rboolean verbose; + char *pictureOptions; } tikzDevDesc; @@ -114,7 +115,8 @@ static Rboolean TikZ_Setup( const char *packages, const char *footer, Rboolean console, Rboolean sanitize, int engine, Rboolean symbolicColors, const char *colorFileName, - int maxSymbolicColors, Rboolean timestamp, Rboolean verbose ); + int maxSymbolicColors, Rboolean timestamp, Rboolean verbose, + const char *pictureOptions ); /* Graphics Engine function hooks. Defined in GraphicsDevice.h . */ diff --git a/vignettes/tikzDevice.Rnw b/vignettes/tikzDevice.Rnw index e8c3756..312344f 100644 --- a/vignettes/tikzDevice.Rnw +++ b/vignettes/tikzDevice.Rnw @@ -740,7 +740,13 @@ formatR::usage(tikz) \item[footer] See \autoref{sec:options}, ``Options That Affect Package Behavior.'' -\end{flexlabelled} + + \item[pictureOptions] + A character string containing additional options which are provided + to the \code{'tikzpicture'} environment, e.g., + \code{'font=\\\\sffamily'}. The \code{bareBones} argument needs to + be \code{FALSE} for this to have an effect. + \end{flexlabelled} The first six options should be familiar to anyone who has used the default graphics devices shipped with \lang{R}. The options \code{standAlone}