encoded_text_to_latex         package:tools         R Documentation

_T_r_a_n_s_l_a_t_e _n_o_n-_A_S_C_I_I _T_e_x_t _t_o _L_a_T_e_X _E_s_c_a_p_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Translate non-ASCII characters in text to LaTeX escape sequences.

_U_s_a_g_e:

     encoded_text_to_latex(x, encoding = c("latin1", "latin2", "latin9",
                                            "UTF-8", "utf8"))

_A_r_g_u_m_e_n_t_s:

       x: a character vector.

encoding: the encoding to be assumed.  '"latin9"' is officially
          ISO-8859-15 or Latin-9, but known as latin9 to LaTeX's
          'inputenc' package.

_D_e_t_a_i_l_s:

     Non-ASCII characters in 'x' are replaced by an appropriate LaTeX
     escape sequence, or '?' if there is no appropriate sequence.

     Even if there is an appropriate sequence, it may not be supported
     by the font in use.  Hyphen is mapped to '\-'.

_V_a_l_u_e:

     A character vector of the same length as 'x'.

_S_e_e _A_l_s_o:

     'iconv'

_E_x_a_m_p_l_e_s:

     x <- "fa\xE7ile"
     encoded_text_to_latex(x, "latin1")
     ## Not run: 
     ## create a tex file to show the upper half of 8-bit charsets
     x <- rawToChar(as.raw(160:255), multiple=TRUE)
     (x <- matrix(x, ncol=16, byrow=TRUE))
     xx <- x
     xx[] <- encoded_text_to_latex(x, "latin1") # or latin2 or latin9
     xx <- apply(xx, 1, paste, collapse="&")
     con <- file("test-encoding.tex", "w")
     header <- c(
     "\documentclass{article}",
     "\usepackage[T1]{fontenc}",
     "\usepackage{Rd}",
     "\begin{document}",
     "\HeaderA{test}{}{test}",
     "\begin{Details}\relax",
     "\Tabular{cccccccccccccccc}{")
     trailer <- c("}", "\end{Details}", "\end{document}")
     writeLines(header, con)
     writeLines(paste(xx, "\\", sep=""), con)
     writeLines(trailer, con)
     close(con)
     ## and some UTF_8 chars
     x <- intToUtf8(as.integer(
         c(160:383,0x0192,0x02C6,0x02C7,0x02CA,0x02D8,
           0x02D9, 0x02DD, 0x200C, 0x2018, 0x2019, 0x201C,
           0x201D, 0x2020, 0x2022, 0x2026, 0x20AC)),
                    multiple=TRUE)
     x <- matrix(x, ncol=16, byrow=TRUE)
     xx <- x
     xx[] <- encoded_text_to_latex(x, "UTF-8")
     xx <- apply(xx, 1, paste, collapse="&")
     con <- file("test-utf8.tex", "w")
     writeLines(header, con)
     writeLines(paste(xx, "\\", sep=""), con)
     writeLines(trailer, con)
     close(con)
     ## End(Not run)

