From f97871d54f997cfcafa72585248d7e72127489c3 Mon Sep 17 00:00:00 2001
From: Don Armstrong <don@donarmstrong.com>
Date: Tue, 3 Nov 2015 09:01:44 -0800
Subject: [PATCH] add support for math style exponents to print.xtable

---
 pkg/R/print.xtable.R | 7 +++++++
 1 file changed, 7 insertions(+)

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