當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R encoded_text_to_latex 將非 ASCII 文本轉換為 LaTeX 轉義符

R語言 encoded_text_to_latex 位於 tools 包(package)。

說明

將文本中的非 ASCII 字符轉換為 LaTeX 轉義序列。

用法

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

參數

x

一個字符向量。

encoding

假定的編碼。 "latin9" 正式為 ISO-8859-15 或 Latin-9,但在 LaTeX 的 inputenc 包中稱為 latin9。

細節

中的非 ASCII 字符x被替換為適當的 LaTeX 轉義序列,或‘⁠?⁠’如果沒有合適的順序。

即使有適當的順序,所使用的字體也可能不支持該順序。連字符映射到‘⁠\-⁠’。

x 長度相同的字符向量。

例子

x <- "fran\xE7ais"
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(paste0(xx, "\\"), 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)

也可以看看

iconv

相關用法


注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Translate non-ASCII Text to LaTeX Escapes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。