Skip to content

Commit a6e8eed

Browse files
committed
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')
1 parent f8f64b8 commit a6e8eed

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

R/tikz.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
#' @param verbose A logical value indicating whether diagnostic messages are
113113
#' printed when measuring dimensions of strings. Defaults to `TRUE` in
114114
#' interactive mode only, to `FALSE` otherwise.
115+
#' @param pictureOptions A character string that contains additional options
116+
#' provided to the tikzpicture environment. Defaults to the empty string.
115117
#'
116118
#' @return `tikz()` returns no values.
117119
#'
@@ -221,7 +223,8 @@ tikz <- function(file = ifelse(onefile, "./Rplots.tex", "./Rplot%03d.tex"),
221223
symbolicColors = getOption("tikzSymbolicColors"), colorFileName = "%s_colors.tex",
222224
maxSymbolicColors = getOption("tikzMaxSymbolicColors"),
223225
timestamp = TRUE,
224-
verbose = interactive()) {
226+
verbose = interactive(),
227+
pictureOptions = "") {
225228
tryCatch(
226229
{
227230
# 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"),
308311
TikZ_StartDevice, file, width, height, onefile, bg, fg, baseSize, lwdUnit,
309312
standAlone, bareBones, documentDeclaration, packages, footer, console,
310313
sanitize, engine, symbolicColors, colorFileName, maxSymbolicColors,
311-
timestamp, verbose
314+
timestamp, verbose, pictureOptions
312315
)
313316

314317
invisible()

man/tikz.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tikzDevice.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ SEXP TikZ_StartDevice ( SEXP args ){
172172
int maxSymbolicColors = asInteger(CAR(args)); args = CDR(args);
173173
Rboolean timestamp = asLogical(CAR(args)); args = CDR(args);
174174
Rboolean verbose = asLogical(CAR(args)); args = CDR(args);
175+
const char *pictureOptions = CHAR(asChar(CAR(args))); args = CDR(args);
175176

176177
/* Ensure there is an empty slot avaliable for a new device. */
177178
R_CheckDeviceAvailable();
@@ -203,7 +204,7 @@ SEXP TikZ_StartDevice ( SEXP args ){
203204
if( !TikZ_Setup( deviceInfo, fileName, width, height, onefile, bg, fg, baseSize, lwdUnit,
204205
standAlone, bareBones, documentDeclaration, packages,
205206
footer, console, sanitize, engine, symbolicColors, colorFileName,
206-
maxSymbolicColors, timestamp, verbose ) ){
207+
maxSymbolicColors, timestamp, verbose, pictureOptions ) ){
207208
/*
208209
* If setup was unsuccessful, destroy the device and return
209210
* an error message.
@@ -249,7 +250,8 @@ static Rboolean TikZ_Setup(
249250
const char *packages, const char *footer,
250251
Rboolean console, Rboolean sanitize, int engine,
251252
Rboolean symbolicColors, const char* colorFileName,
252-
int maxSymbolicColors, Rboolean timestamp, Rboolean verbose){
253+
int maxSymbolicColors, Rboolean timestamp, Rboolean verbose,
254+
const char *pictureOptions ){
253255

254256
/*
255257
* Create tikzInfo, this variable contains information which is
@@ -315,6 +317,7 @@ static Rboolean TikZ_Setup(
315317
tikzInfo->onefile = onefile;
316318
tikzInfo->timestamp = timestamp;
317319
tikzInfo->verbose = verbose;
320+
tikzInfo->pictureOptions = calloc_strcpy(pictureOptions);
318321

319322
/* initialize strings, just to be on the safe side */
320323
strscpy(tikzInfo->drawColor, "drawColor");
@@ -2291,7 +2294,9 @@ static void TikZ_CheckState(pDevDesc deviceInfo)
22912294

22922295
if ( tikzInfo->bareBones != TRUE )
22932296
{
2294-
printOutput(tikzInfo, "\\begin{tikzpicture}[x=1pt,y=1pt]\n");
2297+
printOutput(tikzInfo, "\\begin{tikzpicture}[x=1pt,y=1pt%s%s]\n",
2298+
tikzInfo->pictureOptions[0] != '\0' ? "," : "",
2299+
tikzInfo->pictureOptions);
22952300

22962301
if( tikzInfo->symbolicColors && tikzInfo->outColorFileName)
22972302
printOutput(tikzInfo, "\\InputIfFileExists{%s}{}{}\n", tikzInfo->outColorFileName);

src/tikzDevice.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ typedef struct {
9393
char fillColor[32];
9494
Rboolean timestamp;
9595
Rboolean verbose;
96+
char *pictureOptions;
9697
} tikzDevDesc;
9798

9899

@@ -114,7 +115,8 @@ static Rboolean TikZ_Setup(
114115
const char *packages, const char *footer,
115116
Rboolean console, Rboolean sanitize, int engine,
116117
Rboolean symbolicColors, const char *colorFileName,
117-
int maxSymbolicColors, Rboolean timestamp, Rboolean verbose );
118+
int maxSymbolicColors, Rboolean timestamp, Rboolean verbose,
119+
const char *pictureOptions );
118120

119121

120122
/* Graphics Engine function hooks. Defined in GraphicsDevice.h . */

vignettes/tikzDevice.Rnw

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,13 @@ formatR::usage(tikz)
740740

741741
\item[footer]
742742
See \autoref{sec:options}, ``Options That Affect Package Behavior.''
743-
\end{flexlabelled}
743+
744+
\item[pictureOptions]
745+
A character string containing additional options which are provided
746+
to the \code{'tikzpicture'} environment, e.g.,
747+
\code{'font=\\\\sffamily'}. The \code{bareBones} argument needs to
748+
be \code{FALSE} for this to have an effect.
749+
\end{flexlabelled}
744750

745751
The first six options should be familiar to anyone who has used the default
746752
graphics devices shipped with \lang{R}. The options \code{standAlone}

0 commit comments

Comments
 (0)