result[i] <- gsub("-", "$-$", result[i], fixed = TRUE)\r
}\r
}\r
- if ( math.style.exponents ) {\r
+ if (is.logical(math.style.exponents) && ! math.style.exponents ) {\r
+ } else if (is.logical(math.style.exponents) && math.style.exponents ||\r
+ math.style.exponents == "$$"\r
+ ) {\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
+ result[i] <- gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",\r
+ "$\\1\\2 \\\\times 10^{\\3\\4}$", result[i])\r
+ }\r
+ } else if (math.style.exponents == "ensuremath") {\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
+ } else if (math.style.exponents == "UTF8" ||\r
+ math.style.exponents == "UTF-8") {\r
+ for(i in 1:length(x)) {\r
+ ## this code turns 1e5 into 1×10⁵x\r
+ if (all(grepl("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",result[i]))) {\r
+ temp <- strsplit(result[i],"eE",result[i])\r
+ result[i] <-\r
+ paste0(temp[1],\r
+ "\u00d710",\r
+ chartr("-1234567890","\u207b\u00b9\u00b2\u00b3\u2074\u2075\u20746\u20747\u20748\u20749\u2070",temp[2]))\r
+ }\r
}\r
}\r
return(result)\r
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",\r
"border=1"),\r
print.results = getOption("xtable.print.results", TRUE),\r
\item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use\r
$-$ for the negative sign (as was the behavior prior to version 1.5-3).\r
Default value is \code{FALSE}.}\r
+ \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or\r
+ \code{"$$"}, then use \code{$5 \times 10^{5}$} for 5e5. If\r
+ \code{"ensuremath"}, then use \code{\ensuremath{5 \times 10^{5}}}\r
+ for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to\r
+ approximate the LaTeX typsetting for 5e5.\r
+ Default value is \code{FALSE}.}\r
\item{html.table.attributes}{In an HTML table, attributes associated\r
with the \code{<TABLE>} tag.\r
Default value is \code{"border=1"}.}\r
\r
\newpage\r
\r
+\subsection{Math-Style Exponents}\r
+If you prefer $5 \times 10^5$ in your tables to 5e5, the\r
+\code{math.style.exponents} option to \code{print.xtable} is useful:\r
+\r
+<<results='asis'>>=\r
+print(xtable(data.frame(text=c("foo","bar"),\r
+ googols=c(10e10,50e10),\r
+ small=c(8e-24,7e-5),\r
+ row.names=c("A","B")),\r
+ display=c("s","s","g","g")),\r
+ math.style.exponents=TRUE\r
+ )\r
+@ \r
+\r
+this option also supports the values \code{ensuremath} which uses\r
+\code{\char`\\ensuremath} instead of \code{\$\$} and \code{UTF-8}\r
+which uses UTF-8 to approximate the \LaTeX typesetting.\r
+\r
\section{Sanitization}\r
<<results='asis'>>=\r
insane <- data.frame(Name = c("Ampersand","Greater than","Less than",\r