[Dplr-commits] r863 - in pkg/dplR: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun May 11 00:28:46 CEST 2014


Author: mvkorpel
Date: 2014-05-11 00:28:45 +0200 (Sun, 11 May 2014)
New Revision: 863

Modified:
   pkg/dplR/R/latexify.R
   pkg/dplR/man/latexify.Rd
Log:
"Interestingly", \Sexpr behaves differently in knitr vs Sweave.
Added an option, 'doublebackslash', to latexify().


Modified: pkg/dplR/R/latexify.R
===================================================================
--- pkg/dplR/R/latexify.R	2014-05-10 21:12:04 UTC (rev 862)
+++ pkg/dplR/R/latexify.R	2014-05-10 22:28:45 UTC (rev 863)
@@ -18,7 +18,10 @@
 ## (newlines, tabs, etc.) will be lost.  Note that the set of
 ## characters actually supported depends on the font, LaTeX engine and
 ## set of packages used.
-latexify <- function(x) {
+##
+## It seems that Sweave needs doublebackslash = TRUE
+## but knitr needs doublebackslash = FALSE.
+latexify <- function(x, doublebackslash=TRUE) {
     y <- as.character(x)
     ## Kludge for converting from "byte" to the current encoding
     ## in a way which preserves the hex notation.
@@ -66,6 +69,9 @@
     for (subst in substitutions) {
         y <- gsub(subst[1], subst[2], y, perl = TRUE)
     }
+    if (isTRUE(doublebackslash)) {
+        y <- gsub("\\", "\\\\", y, fixed=TRUE)
+    }
     ## gsub() may have changed encodings. Therefore we check them
     ## again.
     encs <- Encoding(y)

Modified: pkg/dplR/man/latexify.Rd
===================================================================
--- pkg/dplR/man/latexify.Rd	2014-05-10 21:12:04 UTC (rev 862)
+++ pkg/dplR/man/latexify.Rd	2014-05-10 22:28:45 UTC (rev 863)
@@ -10,10 +10,13 @@
   used together with \samp{\Sexpr} in vignettes.
 }
 \usage{
-latexify(x)
+latexify(x, doublebackslash = TRUE)
 }
 \arguments{
   \item{x}{ a \code{character} vector }
+  \item{doublebackslash}{ a \code{logical} flag.  If \code{TRUE},
+    backslashes in the output are doubled.  It seems that Sweave needs
+    \code{TRUE} and knitr \code{FALSE}. }
 }
 \details{
 
@@ -66,7 +69,7 @@
       '#various$ \%other^ &characters_ ~escaped"/coded',
       x1,
       x2)
-latexStrings <- latexify(testStrings)
+latexStrings <- latexify(testStrings, doublebackslash = FALSE)
 ## 5th element should be "UTF-8", the rest "unknown"
 Encoding(latexStrings)
 cat(latexStrings, sep="\n")



More information about the Dplr-commits mailing list