【发布时间】:2021-11-01 14:36:47
【问题描述】:
我正在尝试读取包含 LaTeX 代码的 .tex 文件,并将其内容粘贴到不同的 .tex 文件中,具体取决于 R 中的计算结果。
我需要通过使用 R 处理 tex 文件来避免更改它们的任何字符。我正在寻找一种方法来阻止 R 解释文件的内容并使 R 只是“复制”文件字符。
示例 R 文件:
cont <- paste(readLines("path/to/file/a.tex"), collapse = "\n")
write.table(cont , file = "Mother.tex", append = FALSE, quote = FALSE, sep = "",
eol = "\n", na = "NA", dec = ".", row.names = FALSE,
col.names = FALSE, qmethod = c("escape", "double"),
fileEncoding = "")
cont2 <- paste(readLines("path/to/file/b.tex"), collapse = "\n")
write.table(cont2 , file = "Mother.tex", append = TRUE, quote = FALSE, sep = "",
eol = "\n", na = "NA", dec = ".", row.names = FALSE,
col.names = FALSE, qmethod = c("escape", "double"),
fileEncoding = "")
cont3 <- paste(readLines("path/to/file/c.tex"), collapse = "\n")
write.table(cont3 , file = "Mother.tex", append = TRUE, quote = FALSE, sep = "",
eol = "\n", na = "NA", dec = ".", row.names = FALSE,
col.names = FALSE, qmethod = c("escape", "double"),
fileEncoding = "")
cont4 <- paste(readLines("path/to/file/d.tex"), collapse = "\n")
write.table(cont4 , file = "Mother.tex", append = TRUE, quote = FALSE, sep = "",
eol = "\n", na = "NA", dec = ".", row.names = FALSE,
col.names = FALSE, qmethod = c("escape", "double"),
fileEncoding = "")
示例乳胶文件a:
\documentclass{beamer}
\usepackage{listings}
\lstset{basicstyle=\ttfamily, keywordstyle=\bfseries}
\begin{document}
示例 Latex 文件 b:
\begin{frame}
示例 Latex 文件 c:
content based on values in r
\end{frame}
示例 Latex 文件 d:
\end{document}
我现在确实有两个问题:
- readlines 的错误转义信息
- 文件中的非 utf-8 关键字:b、c、d
Latex 无法编译成功,因为在使用 r 处理 Mother 之后,Motherfile 里面有一个非 utf-8 的信息。
如果我手动复制和粘贴每个文件的内容,我就可以成功编译 Latex。由于 Latex 中有关坏 utf-8 信息的信息(TexLive IDE 中没有显示错误字符),我怀疑 r 将信息添加到文件中,IDE TextLive 没有显示。
我不明白为什么在我的母亲 tex 文件中添加了一些“不可见”的东西,而 TexLive 中没有显示。
【问题讨论】:
-
我看不出问题出在哪里。
.tex文件是简单的文本文件。如果 R 打开文本文件并将内容视为字符串,则不会解释内容。也许你可以举一个例子来说明 R 在你不想要的时候是如何解释 TeX 内容的。 -
我确实尝试复制一个工作的乳胶文件,但在处理它之后它是不可压缩的。如果我知道出了什么问题,我可以问一个更好的、更高质量的问题。对此我很抱歉
-
您可以展示您尝试过的内容。提出更好问题的方法是努力制作minimal reproducible example,这使得阅读问题的人能够复制问题。在您启发我们之前,我们的线索比您还少。下面发布的答案是否回答了您的问题?如果是,请接受。如果不是,请努力澄清问题所在。