Rev 81680 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/utils/man/RweaveLatex.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2022 R Core Team% Distributed under GPL 2 or later\name{RweaveLatex}\alias{RweaveLatex}\alias{RweaveLatexSetup}\title{R/LaTeX Driver for Sweave}\description{A driver for \code{\link{Sweave}} that translates \R code chunks in\LaTeX files by \dQuote{running them}, i.e., \code{\link{parse}()} and\code{\link{eval}()} each.}\usage{RweaveLatex()RweaveLatexSetup(file, syntax, output = NULL, quiet = FALSE,debug = FALSE, stylepath, \dots)}\arguments{\item{file}{Name of Sweave source file. See the description of thecorresponding argument of \code{\link{Sweave}}.}\item{syntax}{An object of class \code{SweaveSyntax}.}\item{output}{Name of output file. The default is to remove extension\file{.nw}, \file{.Rnw} or \file{.Snw} and to addextension \file{.tex}. Any directory paths in\code{file} are also removed such that the output iscreated in the current working directory.}\item{quiet}{If \code{TRUE} all progress messages are suppressed.}\item{debug}{If \code{TRUE}, input and output of all codechunks is copied to the console.}\item{stylepath}{See \sQuote{Details}.}\item{\dots}{named values for the options listed in \sQuote{SupportedOptions}.}}\details{The \LaTeX file generated needs to contain the line\samp{\\usepackage\{Sweave\}}, and if this is not present in theSweave source file (possibly in a comment), it is inserted by the\code{RweaveLatex} driver as last line before the \samp{\\begin{document}}statement. If \code{stylepath = TRUE}, a hard-codedpath to the file \file{Sweave.sty} in the \R installation is set inplace of \code{Sweave}. The hard-coded path makes the \LaTeX file lessportable, but avoids the problem of installing the current version of\file{Sweave.sty} to some place in your TeX input path. However, TeXmay not be able to process the hard-coded path if it contains spaces(as it often will under Windows) or TeX special characters.The default for \code{stylepath} is now taken from the environmentvariable \env{SWEAVE_STYLEPATH_DEFAULT}, or is \code{FALSE} it that isunset or empty. If set, it should be exactly \code{TRUE} or\code{FALSE}: any other values are taken as \code{FALSE}.The simplest way for frequent Sweave users to ensure that\file{Sweave.sty} is in the TeX input path is to add\file{\var{R_HOME}/share/texmf} as a \sQuote{texmf tree} (\sQuote{rootdirectory} in the parlance of the \sQuote{MiKTeX settings} utility).By default, \file{Sweave.sty} loads the \samp{graphicx} \LaTeX packageand sets the width of all included graphics to:\cr\samp{\\setkeys{Gin}{width=0.8\\textwidth}}.This setting (defined in the \samp{graphicx} package)affects the width size option passed to the\samp{\\includegraphics{}} directive for each plot file and in turnimpacts the scaling of your plot files as they will appear in yourfinal document.Thus, for example, you may set \code{width=3} in your figure chunk andthe generated graphics files will be set to 3 inches inwidth. However, the width of your graphic in your final document willbe set to \samp{0.8\\textwidth} and the height dimension will bescaled accordingly. Fonts and symbols will be similarly scaled in thefinal document.You can adjust the default value by including the\samp{\\setkeys{Gin}{width=...}} directive in your \file{.Rnw} fileafter the \samp{\\begin{document}} directive and changing the\code{width} option value as you prefer, using standard \LaTeXmeasurement values.If you wish to override this default behavior entirely, you can add a\samp{\\usepackage[nogin]{Sweave}} directive in your preamble. In thiscase, no size/scaling options will be passed to the\samp{\\includegraphics{}} directive and the \code{height} and\code{width} options will determine both the runtime generated graphicfile sizes and the size of the graphics in your final document.\file{Sweave.sty} also supports the \samp{[nofontenc]} option, whichskips the default inclusion of \samp{\\usepackage[T1]{fontenc}}for pdfTeX processing.It also supports the \samp{[inconsolata]} option, to render monospacedtext in \code{inconsolata}, the font used by default for \R helppages.The use of fancy quotes (see \code{\link{sQuote}}) can cause problemswhen setting \R output in non-UTF-8 locales (note that pdfTeX assumesUTF-8 by default since 2018). Either set\code{\link{options}(useFancyQuotes = FALSE)} or arrange that \LaTeXis aware of the encoding used and ensure that typewriter fontscontaining directional quotes are used.Some \LaTeX graphics drivers do not include \samp{.png} or \samp{.jpg}in the list of known extensions. To enable them, add something like\samp{\\DeclareGraphicsExtensions{.png,.pdf,.jpg}} to the preamble ofyour document or check the behavior of your graphics driver. Whenboth \code{pdf} and \code{png} are \code{TRUE} both files will beproduced by \code{Sweave}, and their order in the\samp{DeclareGraphicsExtensions} list determines which will be used by\command{pdflatex}.}\section{Supported Options}{\code{RweaveLatex} supports the following options for code chunks (thevalues in parentheses show the default values). Character stringvalues should be quoted when passed from \code{\link{Sweave}} through\code{\dots} but not when used in the header of a code chunk.\describe{\item{engine:}{character string (\code{"R"}). Only chunks with\code{engine} equal to \code{"R"} or \code{"S"} are processed.}\item{echo:}{logical (\code{TRUE}). Include \R code in the outputfile?}\item{keep.source:}{logical (\code{TRUE}). When echoing, if\code{TRUE} the original source is copied to the file. Otherwise,deparsed source is echoed.}\item{eval:}{logical (\code{TRUE}). If \code{FALSE}, the code chunkis not evaluated, and hence no text nor graphical outputproduced.}\item{results:}{character string (\code{"verbatim"}). If\code{"verbatim"}, the output of \R commands is included in theverbatim-like \samp{Soutput} environment. If \code{"tex"}, theoutput is taken to be already proper \LaTeX markup and included asis. If \code{"hide"} then all output is completely suppressed(but the code executed during the weave). Values can be abbreviated.}\item{print:}{logical (\code{FALSE}). If \code{TRUE}, this forcesauto-printing of all expressions.}\item{term:}{logical (\code{TRUE}). If \code{TRUE}, visibility ofvalues emulates an interactive \R session: values of assignmentsare not printed, values of single objects are printed. If\code{FALSE}, output comes only from explicit \code{\link{print}}or similar statements.}\item{split:}{logical (\code{FALSE}). If \code{TRUE}, text outputis written to separate files for each code chunk.}\item{strip.white:}{character string (\code{"true"}). If\code{"true"}, blank lines at the beginning and end of output areremoved. If \code{"all"}, then all blank lines are removed fromthe output. If \code{"false"} then blank lines are retained.A \sQuote{blank line} is one that is empty or includes onlywhitespace (spaces and tabs).Note that blank lines in a code chunk will usually produce aprompt string rather than a blank line on output.}\item{prefix:}{logical (\code{TRUE}). If \code{TRUE} generatedfilenames of figures and output all have the common prefix givenby the \code{prefix.string} option: otherwise only unlabelledchunks use the prefix.}\item{prefix.string:}{a character string, default is the name of thesource file (without extension). Note that this is used as partof filenames, so needs to be portable.}\item{include:}{logical (\code{TRUE}), indicating whether inputstatements for text output (if \code{split = TRUE}) and\samp{\\includegraphics} statements for figures should beauto-generated. Use \code{include = FALSE} if the output shouldappear in a different place than the code chunk (by placing theinput line manually).}\item{fig:}{logical (\code{FALSE}), indicating whether the codechunk produces graphical output. Note that only one figure percode chunk can be processed this way. The labels for figurechunks are used as part of the file names, so should preferably bealphanumeric.}\item{eps:}{logical (\code{FALSE}), indicating whether EPS figuresshould be generated. Ignored if \code{fig = FALSE}.}\item{pdf:}{logical (\code{TRUE}), indicating whether PDF figuresshould be generated. Ignored if \code{fig = FALSE}.}\item{pdf.version, pdf.encoding, pdf.compress:}{passed to\code{\link{pdf}} to set the version, encoding and compression (ornot). Defaults taken from \code{pdf.options()}.}\item{png:}{logical (\code{FALSE}), indicating whether PNG figuresshould be generated. Ignored if \code{fig = FALSE}.Only available in \eqn{\R \ge 2.13.0}{R >= 2.13.0}.}\item{jpeg:}{logical (\code{FALSE}), indicating whether JPEG figuresshould be generated. Ignored if \code{fig = FALSE}.Only available in \eqn{\R \ge 2.13.0}{R >= 2.13.0}.}\item{grdevice:}{character (\code{NULL}): see section\sQuote{Custom Graphics Devices}. Ignored if \code{fig = FALSE}.Only available in \eqn{\R \ge 2.13.0}{R >= 2.13.0}.}\item{width:}{numeric (6), width of figures in inches. See\sQuote{Details}.}\item{height:}{numeric (6), height of figures in inches. See\sQuote{Details}.}\item{resolution:}{numeric (300), resolution in pixels per inch:used for PNG and JPEG graphics. Note that the default is a fairlyhigh value, appropriate for high-quality plots. Something like\code{100} is a better choice for package vignettes.}\item{concordance:}{logical (\code{FALSE}). Write a concordancefile to link the input line numbers to the output line numbers.}\item{figs.only:}{logical (\code{FALSE}).By default each figure chunk is run once, then re-run for eachselected type of graphics. That will open a default graphicsdevice for the first figure chunk and use that device for the firstevaluation of all subsequent chunks. If this option is true, thefigure chunk is run only for each selected type of graphics, forwhich a new graphics device is opened and then closed.}}In addition, users can specify further options, either in the headerof an individual code section or in a \samp{\\SweaveOpts\{\}} line inthe document. For unknown options, their type is set at first use.}\section{Custom Graphics Devices}{If option \code{grdevice} is supplied for a code chunk with both\code{fig} and \code{eval} true, the following call is made\preformatted{ get(options$grdevice, envir = .GlobalEnv)(name=, width=,height=, options)}which should open a graphics device. The chunk's code is thenevaluated and \code{\link{dev.off}} is called. Normally a function ofthe name given will have been defined earlier in the Sweave document, e.g.\preformatted{<<results=hide>>=my.Swd <- function(name, width, height, ...)grDevices::png(filename = paste(name, "png", sep = "."),width = width, height = height, res = 100,units = "in", type = "quartz", bg = "transparent")@}Alternatively for \R >= 3.4.0, if the function exists in a package(rather than the \code{.GlobalEnv}) it can be used by setting\code{grdevice = "pkg::my.Swd"} (or with \samp{:::} instead of\samp{::} if the function is not exported).Currently only one custom device can be used for each chunk, butdifferent devices can be used for different chunks.A replacement for \code{\link{dev.off}} can be provided as a functionwith suffix \code{.off}, e.g.\sspace{}\code{my.Swd.off()} or\code{pkg::my.Swd.off()}, respectively.}\section{Hook Functions}{Before each code chunk is evaluated, zero or more hook functions canbe executed. If \code{getOption("SweaveHooks")} is set, it is takento be a named list of hook functions. For each \emph{logical} option of acode chunk (\code{echo}, \code{print}, \ldots) a hook can bespecified, which is executed if and only if the respective option is\code{TRUE}. Hooks must be named elements of the list returned by\code{getOption("SweaveHooks")} and be functions taking no arguments.E.g., if option \code{"SweaveHooks"} is defined as\code{list(fig = foo)}, and \code{foo} is a function, then it would beexecuted before the code in each figure chunk. This is especiallyuseful to set defaults for the graphical parameters in a series offigure chunks.Note that the user is free to define new Sweave logical options andassociate arbitrary hooks with them. E.g., one could define a hookfunction for a new option called \code{clean} that removes all objectsin the workspace. Then all code chunks specified with\code{clean = TRUE} would start operating on an empty workspace.}\author{Friedrich Leisch and R-core}\seealso{\sQuote{\href{../doc/Sweave.pdf}{Sweave User Manual}}, a vignette inthe \pkg{utils} package.\code{\link{Sweave}}, \code{\link{Rtangle}}}\keyword{utilities}