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 getTikzDefaults function #229

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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ S3method(format,PATH)
export(anyMultibyteUTF8Characters)
export(getLatexCharMetrics)
export(getLatexStrWidth)
export(getTikzDefaults)
export(grid.tikzAnnotate)
export(grid.tikzCoord)
export(grid.tikzNode)
Expand Down
162 changes: 93 additions & 69 deletions R/deviceUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -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.
#'
Expand All @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions R/tikzDevice-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -122,8 +121,7 @@
#' @seealso [tikz()]
#' @references The TikZ and PGF Packages: Manual for version 2.00\cr
#' <https://sourceforge.net/projects/pgf>\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
Expand Down
28 changes: 28 additions & 0 deletions man/getTikzDefaults.Rd

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

2 changes: 1 addition & 1 deletion man/setTikzDefaults.Rd

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

1 change: 0 additions & 1 deletion man/tikzDevice-package.Rd

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