Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
###########################################################################/**
|
|
2 |
# @set class=character
|
|
3 |
# @RdocMethod toLatex
|
|
4 |
# @alias toLatex.default
|
|
5 |
# @alias le
|
|
6 |
#
|
|
7 |
# @title "Escapes character strings to become LaTeX compatible"
|
|
8 |
#
|
|
9 |
# \description{
|
|
10 |
# @get "title".
|
|
11 |
# }
|
|
12 |
#
|
|
13 |
# @synopsis
|
|
14 |
#
|
|
15 |
# \arguments{
|
|
16 |
# \item{object}{A @character @vector of N strings.}
|
|
17 |
# \item{...}{Not used.}
|
|
18 |
# }
|
|
19 |
#
|
|
20 |
# \value{
|
|
21 |
# A @character @vector of N strings.
|
|
22 |
# }
|
|
23 |
#
|
|
24 |
# @author
|
|
25 |
#
|
|
26 |
# \seealso{
|
|
27 |
# @see "utils::toLatex" for escaping @see "utils::sessionInfo" objects.
|
|
28 |
# }
|
|
29 |
#
|
|
30 |
# @keyword internal
|
|
31 |
#*/###########################################################################
|
|
32 |
setMethodS3("toLatex", "character", function(object, ...) { |
|
33 |
s <- object
|
|
34 |
replace <- c("\\"="\\textbackslash", "{"="\\{", "}"="\\}", |
|
35 |
"&"="\\&", "%"="\\%", "$"="\\$", "#"="\\#", |
|
36 |
"_"="\\_", |
|
37 |
"~"="\\~{}", "^"="\\^{}"); # <== ? |
|
38 |
search <- names(replace) |
|
39 |
for (ii in seq_along(replace)) { |
|
40 |
s <- gsub(search[ii], replace[ii], s, fixed=TRUE) |
|
41 |
}
|
|
42 |
s |
|
43 |
}) # toLatex() |
|
44 |
|
|
45 |
# To handle the NULL case
|
|
46 |
setMethodS3("toLatex", "default", function(object, ...) { |
|
47 |
if (is.null(object)) return("") |
|
48 |
object |
|
49 |
}) # toLatex() |
|
50 |
|
|
51 |
|
|
52 |
le <- function(...) { |
|
53 |
sapply(c(...), FUN=function(s) { |
|
54 |
gsub("_", "\\_", s, fixed=TRUE) |
|
55 |
})
|
|
56 |
} # le() |
Read our documentation on viewing source code .