+ if ( math.style.exponents ) {
+ if (is.logical(math.style.exponents) && ! math.style.exponents ) {
+ } else if (is.logical(math.style.exponents) && math.style.exponents ||
+ math.style.exponents == "$$"
+ ) {
+ for(i in 1:length(str)) {
+ result[i] <-
+ gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",
+ "$\\1\\2 \\\\times 10^{\\3\\4}$", result[i])
+ }
+ } else if (math.style.exponents == "ensuremath") {
+ for(i in 1:length(str)) {
+ result[i] <-
+ gsub("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",
+ "\\\\ensuremath{\\1\\2 \\\\times 10^{\\3\\4}}",
+ result[i])
+ }
+ } else if (math.style.exponents == "UTF8" ||
+ math.style.exponents == "UTF-8") {
+ for(i in 1:length(str)) {
+ ## this code turns 1e5 into 1×10⁵x
+ if (all(grepl("^\\$?(-?)\\$?([0-9.]+)[eE]\\$?(-?)\\+?\\$?0*(\\d+)$",
+ result[i]))) {
+ temp <- strsplit(result[i],"eE",result[i])
+ result[i] <-
+ paste0(temp[1],
+ "\u00d710",
+ chartr("-1234567890",
+ "\u207b\u00b9\u00b2\u00b3\u2074\u2075\u20746\u20747\u20748\u20749\u2070",
+ temp[2]))
+ }
+ }
+ }
+ }