From: Don Armstrong Date: Tue, 3 Nov 2015 17:01:44 +0000 (-0800) Subject: add support for math style exponents to print.xtable X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f97871d54f997cfcafa72585248d7e72127489c3;p=xtable.git add support for math style exponents to print.xtable --- 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) {