[Dplr-commits] r919 - in pkg/dplR: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 21 09:59:07 CET 2014


Author: mvkorpel
Date: 2014-11-21 09:59:07 +0100 (Fri, 21 Nov 2014)
New Revision: 919

Modified:
   pkg/dplR/DESCRIPTION
   pkg/dplR/R/latexify.R
Log:
Using character classes to reduce the number of gsub() calls.  A
rather obvious optimization, but the inspiration to this came from the
source code of knitr.


Modified: pkg/dplR/DESCRIPTION
===================================================================
--- pkg/dplR/DESCRIPTION	2014-11-20 14:26:07 UTC (rev 918)
+++ pkg/dplR/DESCRIPTION	2014-11-21 08:59:07 UTC (rev 919)
@@ -3,7 +3,7 @@
 Type: Package
 Title: Dendrochronology Program Library in R
 Version: 1.6.1
-Date: 2014-11-20
+Date: 2014-11-21
 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph",
         "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko",
         "Korpela", role = c("aut", "trl")), person("Franco", "Biondi",

Modified: pkg/dplR/R/latexify.R
===================================================================
--- pkg/dplR/R/latexify.R	2014-11-20 14:26:07 UTC (rev 918)
+++ pkg/dplR/R/latexify.R	2014-11-21 08:59:07 UTC (rev 919)
@@ -49,6 +49,9 @@
     ## newline belongs to both groups.
     y <- gsub("[[:space:]]+", " ", y)
     ## Escape LaTeX special characters.
+    ## Some substitutions are mandatory, others affect matters such as
+    ## the rendering of the character in question (\textquote...) or
+    ## line breaks (\slash).
     ## Source: Scott Pakin (2009) The Comprehensive LaTeX Symbol List.
     ## Accessible through "texdoc symbols".
     ## Particularly section 8.6 "ASCII and Latin 1 quick reference".
@@ -59,16 +62,11 @@
     ## but not if followed by { or }.
     ## After that, the order does not matter.
     substitutions <-
-        list(c("\\{", "\\\\{"),
-             c("\\}", "\\\\}"),
+        list(c("([{}])", "\\\\\\1"),
              c("\\\\(?!\\{|\\})", "\\\\textbackslash{}"),
-             c("\\#", "\\\\#"),
-             c("\\$", "\\\\$"),
-             c("%", "\\\\%"),
              c("\\^", "\\\\textasciicircum{}"),
-             c("&", "\\\\&"),
-             c("_", "\\\\_"),
              c("~", "\\\\textasciitilde{}"),
+             c("([#$%&_])", "\\\\\\1"),
              if (textcomp && straightQuotes) {
                  c("'", "\\\\textquotesingle{}")
              },



More information about the Dplr-commits mailing list