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 0
  s <- object
34 0
  replace <- c("\\"="\\textbackslash", "{"="\\{", "}"="\\}", 
35
                "&"="\\&", "%"="\\%", "$"="\\$", "#"="\\#", 
36
                "_"="\\_", 
37
                "~"="\\~{}", "^"="\\^{}");  # <== ?
38 0
  search <- names(replace)
39 0
  for (ii in seq_along(replace)) {
40 0
    s <- gsub(search[ii], replace[ii], s, fixed=TRUE)
41
  } 
42 0
  s
43
}) # toLatex()
44

45
# To handle the NULL case
46
setMethodS3("toLatex", "default", function(object, ...) {
47 0
  if (is.null(object)) return("")
48 0
  object
49
}) # toLatex()
50

51

52
le <- function(...) { 
53 0
  sapply(c(...), FUN=function(s) {
54 0
    gsub("_", "\\_", s, fixed=TRUE)
55
  })
56
} # le()

Read our documentation on viewing source code .

Loading