]> git.donarmstrong.com Git - ool/lipid_simulation_formalism.git/blob - to_latex.R
add missing DPPE acronym
[ool/lipid_simulation_formalism.git] / to_latex.R
1 to.latex <- function(x){
2   gsub("\\\\","\\\\\\\\",latexSN(x))
3 }
4 cleanup.tolatex <- function(output) {
5   gsub("\\\\textrm\\{e\\}(-?)0*(\\d+)","$\\\\times 10^{\\1\\2}$",output);
6 }
7
8
9 table.to.latex <- function(table,
10                            digits=NULL,
11                            format=NULL,
12                            scientific=NULL,
13                            nsmall=0,
14                            colspec="r",
15                            useBooktabs=TRUE,
16                            toprule=if(useBooktabs) "\\toprule" else "\\hline\\hline",
17                            midrule=if(useBooktabs) "\\midrule" else "\\hline",
18                            bottomrule=if(useBooktabs) "\\bottomrule" else "\\hline\\hline",...) {
19   ans <- ""
20   header <- c("",colnames(table));
21   res <- rbind(header,
22                cbind(rownames(table),
23                      apply(table,c(1,2),function(x){format(x,digits=digits,nsmall=nsmall,scientific=scientific,...)})#format(table,digits=digits,scientific=scientific)
24                      ))
25   coefrows <- 2:NROW(res)
26   res[coefrows,-1] <- sub("(\\*+)","^{\\1}",res[coefrows,-1])
27   res[coefrows,-1] <- sub("([eE])\\+?(-?)0*([0-9]+)","$\\\\times 10^{\\2\\3}$",
28                           res[coefrows,-1])
29   
30   tabspec <- rep("l",ncol(res))
31   tabspec[-1] <- colspec
32   tabbegin <- paste("\\begin{tabular}{",paste(tabspec,collapse=""),"}",sep="")
33   tabend <- "\\end{tabular}"
34   ans <- c(ans,tabbegin)
35   if(length(toprule))
36     ans <- c(ans,toprule)
37   for(j in 2:ncol(res))
38     ans <- c(ans,paste(" & \\multicolumn{1}{c}{",trimws(res[1,j]),"}",sep=""))
39   ans <- c(ans,"\\\\")
40   if(length(midrule))
41     ans <- c(ans,midrule)
42   for(i in 2:NROW(res)) {
43     ans <- c(ans,
44              paste(paste(res[i,],collapse=" & "),"\\\\"))
45   }
46   if(length(bottomrule))
47     ans <- c(ans,bottomrule)
48   ans <- c(ans,tabend)
49   structure(ans,class="Latex")
50   
51 }