]> git.donarmstrong.com Git - xtable.git/commitdiff
add support for math style exponents to print.xtable
authorDon Armstrong <don@donarmstrong.com>
Tue, 3 Nov 2015 17:01:44 +0000 (09:01 -0800)
committerDon Armstrong <don@donarmstrong.com>
Tue, 3 Nov 2015 17:01:44 +0000 (09:01 -0800)
pkg/R/print.xtable.R

index 67f48d57a7772e3ed5a9b89a72df12105c0aab45..ce942c7c08a3aea8c79364ed92c9bb0d13965011 100644 (file)
@@ -45,6 +45,7 @@ print.xtable <- function(x,
   sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",\r
                                          sanitize.text.function),\r
   math.style.negative = getOption("xtable.math.style.negative", FALSE),\r
+  math.style.exponents = getOption("xtable.math.style.exponents", FALSE),\r
   html.table.attributes = getOption("xtable.html.table.attributes", "border=1"),\r
   print.results = getOption("xtable.print.results", TRUE),\r
   format.args = getOption("xtable.format.args", NULL),\r
@@ -395,6 +396,12 @@ print.xtable <- function(x,
                     result[i] <- gsub("-", "$-$", result[i], fixed = TRUE)\r
                 }\r
             }\r
+            if ( math.style.exponents ) {\r
+                for(i in 1:length(x)) {\r
+                     result[i] <- gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",\r
+                                       "\\\\ensuremath{\\1\\2 \\\\times 10^{\\3\\4}}", result[i])\r
+                }\r
+            }\r
             return(result)\r
         }\r
         sanitize.final <- function(result) {\r