Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an 'engine_args' option similar to tinytex's. #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ Encoding: UTF-8
Package: tikzDevice
Type: Package
Title: R Graphics Output in LaTeX Format
Version: 0.12.1
Version: 0.12.2
Authors@R: c( person("Charlie", "Sharpsteen", role = "aut"),
person("Cameron", "Bracken", role = "aut"), person("Kirill",
"Müller", role = c("ctb"), email =
"[email protected]"), person("Yihui", "Xie", role = "ctb"),
person("Ralf", "Stubner", email = "[email protected]",
role = "cre"), person("Nico", "Bellack",
email = "[email protected]", role = "ctb") )
email = "[email protected]", role = "ctb"),
person("Emmanuel", "Charpentier",
email = "[email protected]", role = "ctb"))
URL: https://github.com/daqana/tikzDevice
BugReports: https://github.com/daqana/tikzDevice/issues
Description: Provides a graphics output device for R that records plots
Expand Down
5 changes: 5 additions & 0 deletions R/deviceUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ getDocumentPointsize <- function(docString) {
#' @export
setTikzDefaults <- function(overwrite = TRUE) {
tikzDefaults <- list(

tikzDefaultEngine = "pdftex",

tikzEngineArgs = "",

tikzLatex = getOption("tikzLatexDefault"),

tikzDocumentDeclaration = "\\documentclass[10pt]{article}\n",
Expand Down Expand Up @@ -360,13 +363,15 @@ tikzCompilerInfo <- function(verbose = TRUE) {
#' @export
tikzTest <- function(texString = "A",
engine = getOption("tikzDefaultEngine"),
engine_args=getOption("tikzEngineArgs"),
documentDeclaration = getOption("tikzDocumentDeclaration"),
packages) {
latex_cmd <- get_latex_cmd(engine)
print_compiler_info(latex_cmd, "Active")
getLatexStrWidth(
texString,
engine = engine,
engine_args = engine_args,
documentDeclaration = documentDeclaration,
packages = packages,
diagnose = TRUE
Expand Down
23 changes: 13 additions & 10 deletions R/latexStrWidth.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
#'
#' @references PGF Manual
#' @export
getLatexStrWidth <- function(texString, cex = 1, face = 1, engine = getOption("tikzDefaultEngine"),
documentDeclaration = getOption("tikzDocumentDeclaration"), packages,
verbose = interactive(), diagnose = FALSE) {
getLatexStrWidth <- function(texString, cex = 1, face = 1,
engine = getOption("tikzDefaultEngine"),
engine_args=getOption("tikzEngineArgs"),
documentDeclaration = getOption("tikzDocumentDeclaration"),
packages, verbose = interactive(),
diagnose = FALSE) {
texString <- enc2utf8(texString) # convert the encoding of input string to UTF8

switch(engine,
Expand Down Expand Up @@ -77,7 +80,7 @@ getLatexStrWidth <- function(texString, cex = 1, face = 1, engine = getOption("t
TeXMetrics <- list(
type = "string", scale = cex, face = face, value = texString,
documentDeclaration = documentDeclaration,
packages = packages, engine = engine
packages = packages, engine = engine, engine_args = engine_args
)

if (diagnose) {
Expand Down Expand Up @@ -127,6 +130,7 @@ getLatexStrWidth <- function(texString, cex = 1, face = 1, engine = getOption("t
#'
#' @export
getLatexCharMetrics <- function(charCode, cex = 1, face = 1, engine = getOption("tikzDefaultEngine"),
engine_args = getOption("tikzEngineArgs"),
documentDeclaration = getOption("tikzDocumentDeclaration"), packages,
verbose = interactive()) {

Expand Down Expand Up @@ -203,7 +207,7 @@ getLatexCharMetrics <- function(charCode, cex = 1, face = 1, engine = getOption(
TeXMetrics <- list(
type = "char", scale = cex, face = face, value = charCode,
documentDeclaration = documentDeclaration,
packages = packages, engine = engine
packages = packages, engine = engine, engine_args = engine_args
)

# Check to see if we have metrics stored in
Expand Down Expand Up @@ -401,11 +405,10 @@ getMetricsFromLatex <- function(TeXMetrics, verbose = verbose, diagnose = FALSE)
latexCmd <- get_latex_cmd(TeXMetrics$engine)

# Append the batchmode flag to increase LaTeX
# efficiency.
latexCmd <- paste(
shQuote(latexCmd), "-interaction=batchmode", "-halt-on-error",
"-output-directory", shQuote(texDir), shQuote(texFile)
)
# efficiency, and other useful flags...
latexCmd <- paste(shQuote(latexCmd), TeXMetrics$engine_args,
"-interaction=batchmode", "-halt-on-error",
"-output-directory", shQuote(texDir), shQuote(texFile))

message("Running command: ", latexCmd)

Expand Down
131 changes: 72 additions & 59 deletions R/tikz.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,69 +50,81 @@
#' automatically written if the path of a color file `colorFileName` is
#' set.
#'
#' @param file,filename A character string indicating the desired path to the output
#' file. If both arguments are used in the function call, `file` will be
#' preferred.
#' @param file,filename A character string indicating the desired path
#' to the output file. If both arguments are used in the function
#' call, `file` will be preferred.
#' @param width The width of the output figure, in **inches**.
#' @param height The height of the output figure, in **inches**.
#' @param onefile Should output be directed to separate environments in a
#' single file (default `TRUE`). If `FALSE` this option works
#' exactly like the argument of the same name to [pdf()]
#' (see there for more details).
#' @param onefile Should output be directed to separate environments
#' in a single file (default `TRUE`). If `FALSE` this option works
#' exactly like the argument of the same name to [pdf()] (see
#' there for more details).
#' @param bg The starting background color for the plot.
#' @param fg The starting foreground color for the plot.
#' @param pointsize Base pointsize used in the LaTeX document. This option is
#' only used if a valid pointsize cannot be extracted from the value of
#' `getOption("tikzDocumentDeclaration")`. See the section "Font Size
#' Calculations" in \link{tikzDevice-package} for more details.
#' @param pointsize Base pointsize used in the LaTeX document. This
#' option is only used if a valid pointsize cannot be extracted
#' from the value of `getOption("tikzDocumentDeclaration")`. See
#' the section "Font Size Calculations" in
#' \link{tikzDevice-package} for more details.
#' @param lwdUnit The number of `pt`s in LaTeX that `lwd = 1` in R is
#' translated to. Defaults to 0.4 (LaTeX and TikZ default); for compatibility
#' with R default, please use 72.27/96 (96 pixels in R is 1 inch, which is 72.27
#' points in TeX).
#' @param standAlone A logical value indicating whether the output file should
#' be suitable for direct processing by LaTeX. A value of `FALSE`
#' indicates that the file is intended for inclusion in a larger document.
#' See \sQuote{Details}.
#' @param bareBones A logical value. When `TRUE` the figure will not be
#' wrapped in a `tikzpicture` environment. This option is useful for
#' embedding one TikZ picture within another. When `TRUE` multipage
#' output will be drawn on a single page.
#' @param console Should the output of tikzDevice be directed to the R console
#' (default `FALSE`). This is useful for dumping tikz output directly into a
#' LaTeX document via [sink()]. If TRUE, the `file` argument
#' is ignored. Setting `file = ''` is equivalent to setting
#' `console=TRUE`.
#' @param sanitize Should special latex characters be replaced (Default FALSE).
#' See the section "Options That Affect Package Behavior" for which
#' characters are replaced.
#' @param engine a string specifying which TeX engine to use. Possible values
#' are 'pdftex', 'xetex' and 'luatex'. See the Unicode section of
#' \link{tikzDevice-package} for details.
#' @param documentDeclaration See the sections "Options That Affect Package
#' Behavior" and "Font Size Calculations" of \link{tikzDevice-package}
#' for more details.
#' @param packages See the section "Options That Affect Package Behavior" of
#' \link{tikzDevice-package}.
#' @param footer See the section "Options That Affect Package Behavior" of
#' \link{tikzDevice-package}.
#' @param symbolicColors A logical value indicating whether colors are written
#' as RGB values or as symbolic names in which case the need to be defined in
#' the LaTeX document. These definitions can be generated with the following
#' `colorFileName` parameter. See also the section "Options That Affect
#' Package Behavior" of \link{tikzDevice-package}.
#' @param colorFileName a character string indicating where the color map for
#' symbolic colors is to be stored. It can contain a placeholder \code{\%s}
#' where the tikz filename is inserted. If the string is empty, no file is
#' written.
#' @param maxSymbolicColors an integer number indicating the maximal number
#' of distinct colors to write symbolically. Any excess color will be defined
#' as if `symbolicColors` was set to `FALSE`. See also the section
#' "Options That Affect Package Behavior" of \link{tikzDevice-package}.
#' @param timestamp A logical value indicating whether a timestamp is written
#' to the TeX file.
#' @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.
#' translated to. Defaults to 0.4 (LaTeX and TikZ default); for
#' compatibility with R default, please use 72.27/96 (96 pixels in
#' R is 1 inch, which is 72.27 points in TeX).
#' @param standAlone A logical value indicating whether the output
#' file should be suitable for direct processing by LaTeX. A value
#' of `FALSE` indicates that the file is intended for inclusion in
#' a larger document. See \sQuote{Details}.
#' @param bareBones A logical value. When `TRUE` the figure will not
#' be wrapped in a `tikzpicture` environment. This option is
#' useful for embedding one TikZ picture within another. When
#' `TRUE` multipage output will be drawn on a single page.
#' @param console Should the output of tikzDevice be directed to the R
#' console (default `FALSE`). This is useful for dumping tikz
#' output directly into a LaTeX document via [sink()]. If TRUE,
#' the `file` argument is ignored. Setting `file = ''` is
#' equivalent to setting `console=TRUE`.
#' @param sanitize Should special latex characters be replaced
#' (Default FALSE). See the section
#' "Options That Affect Package Behavior" for which characters are
#' replaced.
#' @param engine a string specifying which TeX engine to use. Possible
#' values are 'pdftex', 'xetex' and 'luatex'. See the Unicode
#' section of \link{tikzDevice-package} for details.
#' @param engine_args Command-line arguments to be passed toengine(can
#' be set in the global option tikzEngineArgs,
#' e.g. `options(tikzEngineArgs ='-shell-escape')`
#' @param documentDeclaration See the sections
#' "Options That Affect Package Behavior" and
#' "Font Size Calculations" of \link{tikzDevice-package} for more
#' details.
#' @param packages See the section
#' "Options That Affect Package Behavior" of
#' \link{tikzDevice-package}.
#' @param footer See the section
#' "Options That Affect Package Behavior" of
#' \link{tikzDevice-package}.
#' @param symbolicColors A logical value indicating whether colors are
#' written as RGB values or as symbolic names in which case the
#' need to be defined in the LaTeX document. These definitions can
#' be generated with the following `colorFileName` parameter. See
#' also the section "Options That Affect Package Behavior" of
#' \link{tikzDevice-package}.
#' @param colorFileName a character string indicating where the color
#' map for symbolic colors is to be stored. It can contain a
#' placeholder \code{\%s} where the tikz filename is inserted. If
#' the string is empty, no file is written.
#' @param maxSymbolicColors an integer number indicating the maximal
#' number of distinct colors to write symbolically. Any excess
#' color will be defined as if `symbolicColors` was set to
#' `FALSE`. See also the section
#' "Options That Affect Package Behavior" of
#' \link{tikzDevice-package}.
#' @param timestamp A logical value indicating whether a timestamp is
#' written to the TeX file.
#' @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.
#'
#' @return `tikz()` returns no values.
#'
Expand Down Expand Up @@ -217,6 +229,7 @@ tikz <- function(file = filename,
bg="transparent", fg="black", pointsize = 10, lwdUnit = getOption("tikzLwdUnit"),
standAlone = FALSE, bareBones = FALSE, console = FALSE, sanitize = FALSE,
engine = getOption("tikzDefaultEngine"),
engine_args = getOption("tikzEngineArgs"),
documentDeclaration = getOption("tikzDocumentDeclaration"),
packages,
footer = getOption("tikzFooter"),
Expand Down Expand Up @@ -309,7 +322,7 @@ tikz <- function(file = filename,
.External(
TikZ_StartDevice, file, width, height, onefile, bg, fg, baseSize, lwdUnit,
standAlone, bareBones, documentDeclaration, packages, footer, console,
sanitize, engine, symbolicColors, colorFileName, maxSymbolicColors,
sanitize, engine, engine_args, symbolicColors, colorFileName, maxSymbolicColors,
timestamp, verbose
)

Expand Down
6 changes: 6 additions & 0 deletions R/tikzDevice-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#' values trigger the use of the `pdflatex`, `xelatex` and
#' `lualatex` compilers. }
#'
#' \item{`tikzEngineArgs`}{ Specifies supplementary command line
#' arguments to be passed to the engine. Use this to satisfy such
#' requirements of LaTeX packages used in your documents (example :
#' the `minted` package requires `-shell-escape` in order to write
#' its its intermediary files). }
#'
#' \item{`tikzLatex`}{ Specifies the location of the LaTeX compiler to be
#' used by \pkg{tikzDevice}. Setting this option may help the package locate a
#' missing compiler. The default is searched for when the package is loaded,
Expand Down
29 changes: 19 additions & 10 deletions man/getLatexStrWidth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading