From ea567c6675d20d85bebd557c2dec4cd5c12e5c6d Mon Sep 17 00:00:00 2001 From: Kyle Butts Date: Wed, 12 Jun 2024 12:15:40 -0400 Subject: [PATCH] Add `getTikzDefaults` function --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/deviceUtils.R | 162 ++++++++++++++++++++++---------------- R/tikzDevice-package.R | 4 +- man/getTikzDefaults.Rd | 28 +++++++ man/setTikzDefaults.Rd | 2 +- man/tikzDevice-package.Rd | 1 - 7 files changed, 125 insertions(+), 75 deletions(-) create mode 100644 man/getTikzDefaults.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 029b7d6..73cef56 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,5 +41,5 @@ Suggests: SystemRequirements: pgf (>= 2.00) LazyLoad: yes VignetteBuilder: knitr -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index fdc2857..b9778f3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ S3method(format,PATH) export(anyMultibyteUTF8Characters) export(getLatexCharMetrics) export(getLatexStrWidth) +export(getTikzDefaults) export(grid.tikzAnnotate) export(grid.tikzCoord) export(grid.tikzNode) diff --git a/R/deviceUtils.R b/R/deviceUtils.R index 041b7ae..b683f19 100644 --- a/R/deviceUtils.R +++ b/R/deviceUtils.R @@ -26,6 +26,74 @@ getDocumentPointsize <- function(docString) { as.numeric(pointsize[pointsize != ""][1]) } +tikzDefaults <- list( + tikzDefaultEngine = "pdftex", + + tikzLatex = getOption("tikzLatexDefault"), + + tikzDocumentDeclaration = "\\documentclass[10pt]{article}\n", + + tikzLatexPackages = c( + "\\usepackage{tikz}\n", + "\\usepackage[active,tightpage,psfixbb]{preview}\n", + "\\PreviewEnvironment{pgfpicture}\n", + "\\setlength\\PreviewBorder{0pt}\n" + ), + + tikzXelatexPackages = c( + "\\usepackage{tikz}\n", + "\\usepackage[active,tightpage,xetex]{preview}\n", + "\\usepackage{fontspec,xunicode}\n", + "\\PreviewEnvironment{pgfpicture}\n", + "\\setlength\\PreviewBorder{0pt}\n" + ), + + tikzLualatexPackages = c( + "\\usepackage{tikz}\n", + "\\IfFileExists{luatex85.sty}{\\usepackage{luatex85}}{}\n", + "\\usepackage[active,tightpage,psfixbb]{preview}\n", + "\\usepackage{fontspec}\n", + "\\PreviewEnvironment{pgfpicture}\n", + "\\setlength\\PreviewBorder{0pt}\n" + ), + + tikzFooter = "", + + tikzMetricPackages = c( + # The fontenc package is very important here! + # R assumes the output device is uing T1 encoding. + # LaTeX defaults to OT1. This package makes the + # symbol codes consistant for both systems. + "\\usepackage[T1]{fontenc}\n", + "\\usetikzlibrary{calc}\n" + ), + + tikzUnicodeMetricPackages = c( + # The fontenc package is very important here! + # R assumes the output device is uing T1 encoding. + # LaTeX defaults to OT1. This package makes the + # symbol codes consistant for both systems. + "\\usepackage[T1]{fontenc}\n", + "\\usetikzlibrary{calc}\n", + "\\usepackage{fontspec}\n" + ), + + + tikzSanitizeCharacters = c("%", "$", "}", "{", "^", "_", "#", "&", "~"), + + tikzReplacementCharacters = c( + "\\%", "\\$", "\\}", "\\{", "\\^{}", "\\_{}", + "\\#", "\\&", "\\char`\\~" + ), + + tikzLwdUnit = 0.4, + + tikzPdftexWarnUTF = TRUE, + + tikzSymbolicColors = FALSE, + tikzMaxSymbolicColors = 100 +) + #' Reset tikzDevice options to default values. #' @@ -46,7 +114,7 @@ getDocumentPointsize <- function(docString) { #' \item `tikzPdftexWarnUTF` #' } #' -#' @param overwrite Should values that are allready set in `options()` be +#' @param overwrite Should values that are already set in `options()` be #' overwritten? #' @return Nothing returned. #' @@ -64,74 +132,6 @@ getDocumentPointsize <- function(docString) { #' #' @export setTikzDefaults <- function(overwrite = TRUE) { - tikzDefaults <- list( - tikzDefaultEngine = "pdftex", - - tikzLatex = getOption("tikzLatexDefault"), - - tikzDocumentDeclaration = "\\documentclass[10pt]{article}\n", - - tikzLatexPackages = c( - "\\usepackage{tikz}\n", - "\\usepackage[active,tightpage,psfixbb]{preview}\n", - "\\PreviewEnvironment{pgfpicture}\n", - "\\setlength\\PreviewBorder{0pt}\n" - ), - - tikzXelatexPackages = c( - "\\usepackage{tikz}\n", - "\\usepackage[active,tightpage,xetex]{preview}\n", - "\\usepackage{fontspec,xunicode}\n", - "\\PreviewEnvironment{pgfpicture}\n", - "\\setlength\\PreviewBorder{0pt}\n" - ), - - tikzLualatexPackages = c( - "\\usepackage{tikz}\n", - "\\IfFileExists{luatex85.sty}{\\usepackage{luatex85}}{}\n", - "\\usepackage[active,tightpage,psfixbb]{preview}\n", - "\\usepackage{fontspec}\n", - "\\PreviewEnvironment{pgfpicture}\n", - "\\setlength\\PreviewBorder{0pt}\n" - ), - - tikzFooter = "", - - tikzMetricPackages = c( - # The fontenc package is very important here! - # R assumes the output device is uing T1 encoding. - # LaTeX defaults to OT1. This package makes the - # symbol codes consistant for both systems. - "\\usepackage[T1]{fontenc}\n", - "\\usetikzlibrary{calc}\n" - ), - - tikzUnicodeMetricPackages = c( - # The fontenc package is very important here! - # R assumes the output device is uing T1 encoding. - # LaTeX defaults to OT1. This package makes the - # symbol codes consistant for both systems. - "\\usepackage[T1]{fontenc}\n", - "\\usetikzlibrary{calc}\n", - "\\usepackage{fontspec}\n" - ), - - - tikzSanitizeCharacters = c("%", "$", "}", "{", "^", "_", "#", "&", "~"), - - tikzReplacementCharacters = c( - "\\%", "\\$", "\\}", "\\{", "\\^{}", "\\_{}", - "\\#", "\\&", "\\char`\\~" - ), - - tikzLwdUnit = 0.4, - - tikzPdftexWarnUTF = TRUE, - - tikzSymbolicColors = FALSE, - tikzMaxSymbolicColors = 100 - ) - if (!overwrite) { # We don't want to overwrite options that have allready been set. @@ -153,6 +153,30 @@ setTikzDefaults <- function(overwrite = TRUE) { invisible(tikzSetOptions) } +#' Get default options set by tikzDevice. +#' +#' @return +#' This function returns a list with elements +#' \itemize{ +#' \item `tikzDefaultEngine` +#' \item `tikzLatex` +#' \item `tikzDocumentDeclaration` +#' \item `tikzFooter` +#' \item `tikzLatexPackages` +#' \item `tikzXelatexPackages` +#' \item `tikzLualatexPackages` +#' \item `tikzMetricPackages` +#' \item `tikzUnicodeMetricPackages` +#' \item `tikzSanitizeCharacters` +#' \item `tikzReplacementCharacters` +#' \item `tikzPdftexWarnUTF` +#' } +#' +#' @export +getTikzDefaults <- function() { + return(tikzDefaults) +} + isTikzDevice <- function(which = dev.cur()) { if (which == 1) { return(FALSE) diff --git a/R/tikzDevice-package.R b/R/tikzDevice-package.R index cfa490b..0b3a850 100644 --- a/R/tikzDevice-package.R +++ b/R/tikzDevice-package.R @@ -10,7 +10,6 @@ #' #' @name tikzDevice-package #' @aliases tikzDevice-package tikzDevice -#' @docType package #' @section Options That Affect Package Behavior: The \pkg{tikzDevice} package #' is currently influenced by a number of global options that may be set in #' scripts, from the console or in a `.Rprofile` file. All of the options @@ -122,8 +121,7 @@ #' @seealso [tikz()] #' @references The TikZ and PGF Packages: Manual for version 2.00\cr #' \cr Till Tantau, February 20, 2008 -#' @keywords package -NULL +"_PACKAGE" #' @importFrom grDevices as.raster dev.cur dev.list dev.off png #' @importFrom graphics grconvertX grconvertY par plot.new rasterImage diff --git a/man/getTikzDefaults.Rd b/man/getTikzDefaults.Rd new file mode 100644 index 0000000..21e6cb3 --- /dev/null +++ b/man/getTikzDefaults.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deviceUtils.R +\name{getTikzDefaults} +\alias{getTikzDefaults} +\title{Get default options set by tikzDevice.} +\usage{ +getTikzDefaults() +} +\value{ +This function returns a list with elements +\itemize{ +\item \code{tikzDefaultEngine} +\item \code{tikzLatex} +\item \code{tikzDocumentDeclaration} +\item \code{tikzFooter} +\item \code{tikzLatexPackages} +\item \code{tikzXelatexPackages} +\item \code{tikzLualatexPackages} +\item \code{tikzMetricPackages} +\item \code{tikzUnicodeMetricPackages} +\item \code{tikzSanitizeCharacters} +\item \code{tikzReplacementCharacters} +\item \code{tikzPdftexWarnUTF} +} +} +\description{ +Get default options set by tikzDevice. +} diff --git a/man/setTikzDefaults.Rd b/man/setTikzDefaults.Rd index e34ea94..0387c2d 100644 --- a/man/setTikzDefaults.Rd +++ b/man/setTikzDefaults.Rd @@ -7,7 +7,7 @@ setTikzDefaults(overwrite = TRUE) } \arguments{ -\item{overwrite}{Should values that are allready set in \code{options()} be +\item{overwrite}{Should values that are already set in \code{options()} be overwritten?} } \value{ diff --git a/man/tikzDevice-package.Rd b/man/tikzDevice-package.Rd index 7f365a9..ef3c382 100644 --- a/man/tikzDevice-package.Rd +++ b/man/tikzDevice-package.Rd @@ -133,4 +133,3 @@ See \code{packageDescription("tikzDevice")}. Submit bug reports to: \url{https://github.com/daqana/tikzDevice/issues} } -\keyword{package}