First a little setup.
$$.default_output_handler <- knit_hooks$get("output")
knit_hooks$set(output = function(x, options) {
if (options["results"] == "jax") {
sprintf("\\[\n %s\n \\]\n", x)
} else if ((options["results"] == "hold") && (options["holdjax"] == TRUE)) {
sprintf("\\[\n %s\n \\]\n", x)
} else {
default_output_handler(x, options)
}
})
opts_template$set(jax = list(comment = "", results = "jax"))
opts_template$set(jaxasis = list(comment = "", results = "asis", echo = FALSE))
opts_template$set(jaxhold = list(comment = "", results = "hold", holdjax = TRUE))
toMathJax.xtable <- function(object, ...) {
dotArgs <- list(...)
dotArgs$x <- object
dotArgs$type <- "latex"
dotArgs$print.results <- FALSE
dotArgs$floating <- FALSE
dotArgs$tabular.environment <- "array"
z <- do.call("print.xtable", dotArgs)
z <- strsplit(z, split = "\n")[[1]]
class(z) <- "Latex"
z
}
The array environment is supported by MathJax tex.
## Load example dataset
library(xtable)
data(tli)
## Demonstrate data.frame
tli.table <- xtable(tli[1:10, ])
digits(tli.table)[c(2, 6)] <- 0
toMathJax.xtable(tli.table)
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrlllr} \hline & grade & sex & disadvg & ethnicty & tlimth \\ \hline 1 & 6 & M & YES & HISPANIC & 43 \\ 2 & 7 & M & NO & BLACK & 88 \\ 3 & 5 & F & YES & HISPANIC & 34 \\ 4 & 3 & M & YES & HISPANIC & 65 \\ 5 & 8 & M & YES & WHITE & 75 \\ 6 & 5 & M & NO & BLACK & 74 \\ 7 & 8 & F & YES & HISPANIC & 72 \\ 8 & 4 & M & YES & BLACK & 79 \\ 9 & 6 & M & NO & WHITE & 88 \\ 10 & 7 & M & YES & HISPANIC & 87 \\ \hline \end{array} \]
## Demonstrate matrix
design.matrix <- model.matrix(~sex * grade, data = tli[1:10, ])
design.table <- xtable(design.matrix)
toMathJax.xtable(design.table)
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrr} \hline & (Intercept) & sexM & grade & sexM:grade \\ \hline 1 & 1.00 & 1.00 & 6.00 & 6.00 \\ 2 & 1.00 & 1.00 & 7.00 & 7.00 \\ 3 & 1.00 & 0.00 & 5.00 & 0.00 \\ 4 & 1.00 & 1.00 & 3.00 & 3.00 \\ 5 & 1.00 & 1.00 & 8.00 & 8.00 \\ 6 & 1.00 & 1.00 & 5.00 & 5.00 \\ 7 & 1.00 & 0.00 & 8.00 & 0.00 \\ 8 & 1.00 & 1.00 & 4.00 & 4.00 \\ 9 & 1.00 & 1.00 & 6.00 & 6.00 \\ 10 & 1.00 & 1.00 & 7.00 & 7.00 \\ \hline \end{array} \]
## Demonstrate aov
fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data = tli)
fm1.table <- xtable(fm1)
toMathJax.xtable(fm1.table,
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline sex & 1 & 75.37 & 75.37 & 0.38 & 0.5417 \\ ethnicty & 3 & 2572.15 & 857.38 & 4.27 & 0.0072 \\ grade & 1 & 36.31 & 36.31 & 0.18 & 0.6717 \\ disadvg & 1 & 59.30 & 59.30 & 0.30 & 0.5882 \\ Residuals & 93 & 18682.87 & 200.89 & & \\ \hline \end{array} \]
*The fm2.table for the lm demonstration needs the sanitize.colnames.function().
## Demonstrate lm
fm2 <- lm(tlimth ~ sex*ethnicty, data = tli)
fm2.table <- xtable(fm2)
toMathJax.xtable(fm2.table,
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrr} \hline & Estimate & Std. Error & t value & Pr(>|t|) \\ \hline (Intercept) & 73.6364 & 4.2502 & 17.33 & 0.0000 \\ sexM & -1.6364 & 5.8842 & -0.28 & 0.7816 \\ ethnictyHISPANIC & -9.7614 & 6.5501 & -1.49 & 0.1395 \\ ethnictyOTHER & 15.8636 & 10.8360 & 1.46 & 0.1466 \\ ethnictyWHITE & 4.7970 & 4.9687 & 0.97 & 0.3368 \\ sexM:ethnictyHISPANIC & 10.6780 & 8.7190 & 1.22 & 0.2238 \\ sexM:ethnictyWHITE & 5.1230 & 7.0140 & 0.73 & 0.4670 \\ \hline \end{array} \]
# anova object
toMathJax.xtable(xtable(anova(fm2)),
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline sex & 1 & 75.37 & 75.37 & 0.38 & 0.5395 \\ ethnicty & 3 & 2572.15 & 857.38 & 4.31 & 0.0068 \\ sex:ethnicty & 2 & 298.43 & 149.22 & 0.75 & 0.4748 \\ Residuals & 93 & 18480.04 & 198.71 & & \\ \hline \end{array} \]
# another anova object
fm2b <- lm(tlimth ~ ethnicty, data = tli)
toMathJax.xtable(xtable(anova(fm2b, fm2)),
sanitize.colnames.function=function(x){x} )
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrrr} \hline & Res.Df & RSS & Df & Sum of Sq & F & Pr(>F) \\ \hline 1 & 96 & 19053.59 & & & & \\ 2 & 93 & 18480.04 & 3 & 573.55 & 0.96 & 0.4141 \\ \hline \end{array} \]
## Demonstrate glm
fm3 <- glm(disadvg ~ ethnicty*grade, data=tli, family=binomial())
fm3.table <- xtable(fm3)
toMathJax.xtable(fm3.table,
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrr} \hline & Estimate & Std. Error & z value & Pr(>|z|) \\ \hline (Intercept) & 3.1888 & 1.5966 & 2.00 & 0.0458 \\ ethnictyHISPANIC & -0.2848 & 2.4808 & -0.11 & 0.9086 \\ ethnictyOTHER & 212.1701 & 22122.7093 & 0.01 & 0.9923 \\ ethnictyWHITE & -8.8150 & 3.3355 & -2.64 & 0.0082 \\ grade & -0.5308 & 0.2892 & -1.84 & 0.0665 \\ ethnictyHISPANIC:grade & 0.2448 & 0.4357 & 0.56 & 0.5742 \\ ethnictyOTHER:grade & -32.6014 & 3393.4687 & -0.01 & 0.9923 \\ ethnictyWHITE:grade & 1.0171 & 0.5185 & 1.96 & 0.0498 \\ \hline \end{array} \]
# anova object
toMathJax.xtable(xtable(anova(fm3)))
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrr} \hline & Df & Deviance & Resid. Df & Resid. Dev \\ \hline NULL & & & 99 & 129.49 \\ ethnicty & 3 & 47.24 & 96 & 82.25 \\ grade & 1 & 1.73 & 95 & 80.52 \\ ethnicty:grade & 3 & 7.20 & 92 & 73.32 \\ \hline \end{array} \]
## Demonstrate aov
## Taken from help(aov) in R 1.1.1
## From Venables and Ripley (1997) p.210.
N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,
62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
npk <- data.frame(block = gl(6,4), N = factor(N), P = factor(P),
K = factor(K), yield = yield)
npk.aov <- aov(yield ~ block + N*P*K, npk)
op <- options(contrasts = c("contr.helmert", "contr.treatment"))
npk.aovE <- aov(yield ~ N*P*K + Error(block), npk)
options(op)
summary(npk.aov)
## Df Sum Sq Mean Sq F value Pr(>F)
## block 5 343 68.7 4.45 0.0159 *
## N 1 189 189.3 12.26 0.0044 **
## P 1 8 8.4 0.54 0.4749
## K 1 95 95.2 6.17 0.0288 *
## N:P 1 21 21.3 1.38 0.2632
## N:K 1 33 33.1 2.15 0.1686
## P:K 1 0 0.5 0.03 0.8628
## Residuals 12 185 15.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
These tables are the same…
toMathJax.xtable(xtable(npk.aov),
sanitize.colnames.function=function(x){x})
# anova object
toMathJax.xtable(xtable(anova(npk.aov)),
sanitize.colnames.function=function(x){x})
# another anova object
toMathJax.xtable(xtable(summary(npk.aov)),
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline block & 5 & 343.29 & 68.66 & 4.45 & 0.0159 \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.13 & 33.13 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals & 12 & 185.29 & 15.44 & & \\ \hline \end{array} \] \[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline block & 5 & 343.29 & 68.66 & 4.45 & 0.0159 \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.13 & 33.13 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals & 12 & 185.29 & 15.44 & & \\ \hline \end{array} \] \[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline block & 5 & 343.29 & 68.66 & 4.45 & 0.0159 \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.13 & 33.13 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals & 12 & 185.29 & 15.44 & & \\ \hline \end{array} \]
summary(npk.aovE)
##
## Error: block
## Df Sum Sq Mean Sq F value Pr(>F)
## N:P:K 1 37 37.0 0.48 0.53
## Residuals 4 306 76.6
##
## Error: Within
## Df Sum Sq Mean Sq F value Pr(>F)
## N 1 189.3 189.3 12.26 0.0044 **
## P 1 8.4 8.4 0.54 0.4749
## K 1 95.2 95.2 6.17 0.0288 *
## N:P 1 21.3 21.3 1.38 0.2632
## N:K 1 33.1 33.1 2.15 0.1686
## P:K 1 0.5 0.5 0.03 0.8628
## Residuals 12 185.3 15.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
These are the same.
toMathJax.xtable(xtable(npk.aovE),
sanitize.colnames.function=function(x){x})
toMathJax.xtable(xtable(summary(npk.aovE)),
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline N:P:K & 1 & 37.00 & 37.00 & 0.48 & 0.5252 \\ Residuals & 4 & 306.29 & 76.57 & & \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.14 & 33.14 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals1 & 12 & 185.29 & 15.44 & & \\ \hline \end{array} \] \[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline N:P:K & 1 & 37.00 & 37.00 & 0.48 & 0.5252 \\ Residuals & 4 & 306.29 & 76.57 & & \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.14 & 33.14 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals1 & 12 & 185.29 & 15.44 & & \\ \hline \end{array} \]
## Demonstrate lm
## Taken from help(lm) in R 1.1.1
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
toMathJax.xtable(xtable(lm.D9),
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrr} \hline & Estimate & Std. Error & t value & Pr(>|t|) \\ \hline (Intercept) & 5.0320 & 0.2202 & 22.85 & 0.0000 \\ groupTrt & -0.3710 & 0.3114 & -1.19 & 0.2490 \\ \hline \end{array} \]
toMathJax.xtable(xtable(anova(lm.D9)),
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline group & 1 & 0.69 & 0.69 & 1.42 & 0.2490 \\ Residuals & 18 & 8.73 & 0.48 & & \\ \hline \end{array} \]
That might look better side-by-side…
\[ \begin{array}[c]{cc} \begin{array}[c]{} \text{[Table A]} \end{array} & \hskip4em \begin{array}[c]{} \text{[Table B]} \end{array} \\ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrr} \hline & Estimate & Std. Error & t value & Pr(>|t|) \\ \hline (Intercept) & 5.0320 & 0.2202 & 22.85 & 0.0000 \\ groupTrt & -0.3710 & 0.3114 & -1.19 & 0.2490 \\ \hline \end{array} & \hskip4em % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline group & 1 & 0.69 & 0.69 & 1.42 & 0.2490 \\ Residuals & 18 & 8.73 & 0.48 & & \\ \hline \end{array} \end{array} \\ \]
## Demonstrate glm
## Taken from help(glm) in R 1.1.1
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
d.AD <- data.frame(treatment, outcome, counts)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
toMathJax.xtable(xtable(glm.D93, align = "r|llrc"),
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{r|llrc} \hline & Estimate & Std. Error & z value & Pr(>|z|) \\ \hline (Intercept) & 3.0445 & 0.1709 & 17.81 & 0.0000 \\ outcome2 & -0.4543 & 0.2022 & -2.25 & 0.0246 \\ outcome3 & -0.2930 & 0.1927 & -1.52 & 0.1285 \\ treatment2 & 0.0000 & 0.2000 & 0.00 & 1.0000 \\ treatment3 & 0.0000 & 0.2000 & 0.00 & 1.0000 \\ \hline \end{array} \]
# A "small" table.
toMathJax.xtable(xtable(anova(glm.D93)),
hline.after = c(1), size = "small",
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 {\small \begin{array}{lrrrr} & Df & Deviance & Resid. Df & Resid. Dev \\ NULL & & & 8 & 10.58 \\ \hline outcome & 2 & 5.45 & 6 & 5.13 \\ treatment & 2 & 0.00 & 4 & 5.13 \\ \end{array} } \]
## Demonstration of additional formatC() arguments.
toMathJax.xtable(fm1.table,
format.args = list(big.mark = "'", decimal.mark = ","),
sanitize.colnames.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline sex & 1 & 75,37 & 75,37 & 0,38 & 0,5417 \\ ethnicty & 3 & 2'572,15 & 857,38 & 4,27 & 0,0072 \\ grade & 1 & 36,31 & 36,31 & 0,18 & 0,6717 \\ disadvg & 1 & 59,30 & 59,30 & 0,30 & 0,5882 \\ Residuals & 93 & 18'682,87 & 200,89 & & \\ \hline \end{array} \]
The caption found in tabular is not available via MathJax.
## Demonstration of 'short caption' support.
fm1sc <- aov(tlimth ~ sex + ethnicty + grade, data = tli)
fm1sc.table <- xtable(fm1sc, caption = c("ANOVA Model with Predictors Sex, Ethnicity, and Grade",
"ANOVA: Sex, Ethnicity, Grade"))
toMathJax.xtable(fm1sc.table, sanitize.colnames.function = function(x) {
x
})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr(>F) \\ \hline sex & 1 & 75.37 & 75.37 & 0.38 & 0.5401 \\ ethnicty & 3 & 2572.15 & 857.38 & 4.30 & 0.0069 \\ grade & 1 & 36.31 & 36.31 & 0.18 & 0.6706 \\ Residuals & 94 & 18742.17 & 199.38 & & \\ \hline \end{array} \]
The next few tables don't really translate to plain web pages, and MathJax doesn't support them. Not Run
Also, the MathJax hook would override the floating.environment and a normal table would appear.
## Demonstration of longtable support. Remember to insert
## \usepackage{longtable} on your LaTeX preamble
x <- matrix(rnorm(1000), ncol = 10)
x.big <- xtable(x, label = "tabbig", caption = "Example of longtable spanning several pages")
toMathJax.xtable(x.big, tabular.environment = "longtable", floating = FALSE)
x <- x[1:30, ]
x.small <- xtable(x, label = "tabsmall", caption = "regular table env")
toMathJax.xtable(x.small) # default, no longtable
## Demonstration of sidewaystable support. Remember to insert
## \usepackage{rotating} on your LaTeX preamble
toMathJax.xtable(x.small, floating.environment = "sidewaystable")
if (require(stats, quietly = TRUE)) {
## Demonstrate prcomp Taken from help(prcomp) in mva package of R 1.1.1
data(USArrests)
pr1 <- prcomp(USArrests)
toMathJax.xtable(xtable(pr1))
toMathJax.xtable(xtable(summary(pr1)))
# ## Demonstrate princomp ## Taken from help(princomp) in mva package of R
# 1.1.1
pr2 <- princomp(USArrests)
toMathJax.xtable(xtable(pr2))
}
Mathjax doesn't support vertical spacing since that is more a function of styling (css)…
## Demonstrate include.rownames, include.colnames, only.contents and
## add.to.row arguments
set.seed(2345)
res <- matrix(sample(0:9, size = 6 * 9, replace = TRUE), ncol = 6, nrow = 9)
xres <- xtable(res)
digits(xres) <- rep(0, 7)
addtorow <- list()
addtorow$pos <- list()
addtorow$pos[[1]] <- c(0, 2)
addtorow$pos[[2]] <- 4
# \vspace isn't supported in MathJax
addtorow$command <- c("\\vspace{2mm} \n", "\\vspace{10mm} \n")
toMathJax.xtable(xres, add.to.row = addtorow, include.rownames = FALSE, include.colnames = TRUE,
only.contents = TRUE, hline.after = c(0, 0, 9, 9))
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 1 & 2 & 3 & 4 & 5 & 6 \\ \vspace{2mm} \hline \hline 1 & 7 & 6 & 6 & 5 & 9 \\ 1 & 1 & 1 & 5 & 7 & 7 \\ \vspace{2mm} 7 & 3 & 9 & 8 & 0 & 5 \\ 0 & 0 & 4 & 1 & 5 & 2 \\ \vspace{10mm} 4 & 1 & 8 & 5 & 7 & 1 \\ 2 & 4 & 5 & 9 & 5 & 4 \\ 6 & 3 & 3 & 5 & 5 & 8 \\ 7 & 6 & 1 & 0 & 7 & 6 \\ 4 & 4 & 8 & 8 & 3 & 2 \\ \hline \hline \]
# This could be done but honestly doesn't look too good.
addtorow$command <- c("\\cr \n", "\\cr \n")
toMathJax.xtable(xres, add.to.row = addtorow, include.rownames = FALSE, include.colnames = TRUE,
only.contents = FALSE, hline.after = c(0, 0, 9, 9))
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrrr} 1 & 2 & 3 & 4 & 5 & 6 \\ \cr \hline \hline 1 & 7 & 6 & 6 & 5 & 9 \\ 1 & 1 & 1 & 5 & 7 & 7 \\ \cr 7 & 3 & 9 & 8 & 0 & 5 \\ 0 & 0 & 4 & 1 & 5 & 2 \\ \cr 4 & 1 & 8 & 5 & 7 & 1 \\ 2 & 4 & 5 & 9 & 5 & 4 \\ 6 & 3 & 3 & 5 & 5 & 8 \\ 7 & 6 & 1 & 0 & 7 & 6 \\ 4 & 4 & 8 & 8 & 3 & 2 \\ \hline \hline \end{array} \]
Thinking of addtorow as a possible way to add row specific css info might be worthwhile.
## Demonstrate sanitization
mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
rownames(mat) <- "$y_{t-1}$"
colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW")
toMathJax.xtable(xtable(mat), type = "latex")
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrrr} \hline & \$R\verb|^|2\$ & \$$\backslash$bar\{R\}\verb|^|2\$ & F-stat & S.E.E & DW \\ \hline \$y\_\{t-1\}\$ & 0.90 & 0.89 & 200.00 & 0.04 & 2.00 \\ \hline \end{array} \]
toMathJax.xtable(xtable(mat), type = "latex",
sanitize.text.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:13 2014 \begin{array}{rrrrrr} \hline & $R^2$ & $\bar{R}^2$ & F-stat & S.E.E & DW \\ \hline $y_{t-1}$ & 0.90 & 0.89 & 200.00 & 0.04 & 2.00 \\ \hline \end{array} \]
rownames(mat) <- "y_{t-1}"
colnames(mat) <- c("R^2", "\\bar{R}^2", "F-stat", "S.E.E", "DW")
toMathJax.xtable(xtable(mat), type = "latex")
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:14 2014 \begin{array}{rrrrrr} \hline & R\verb|^|2 & $\backslash$bar\{R\}\verb|^|2 & F-stat & S.E.E & DW \\ \hline y\_\{t-1\} & 0.90 & 0.89 & 200.00 & 0.04 & 2.00 \\ \hline \end{array} \]
toMathJax.xtable(xtable(mat), type = "latex",
sanitize.text.function=function(x){x})
\[ % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:14 2014 \begin{array}{rrrrrr} \hline & R^2 & \bar{R}^2 & F-stat & S.E.E & DW \\ \hline y_{t-1} & 0.90 & 0.89 & 200.00 & 0.04 & 2.00 \\ \hline \end{array} \]
Well, that is all.
\[ \begin{equation} f(x) = \left[ \hspace2ex ```{r, opts.label="jaxasis"} toMathJax.xtable( xtable( matrix( 1:9, 3, 3) ), hline.after=NULL, include.rownames=FALSE, include.colnames=FALSE ) ``` \hspace2ex \right] \end{equation} \]
\[ \begin{equation} f(x) = \left[ \hspace2ex % latex table generated in R 3.0.2 by xtable 1.7-1 package % Sat Feb 15 14:18:14 2014 \begin{array}{rrr} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \\ \end{array} \hspace2ex \right] \end{equation} \]