在同一台机器上,以下Rnw文件的knitr+LaTeX编译在RStudio中失败,出现Invalid UTF-8 byte "97 LaTeX错误;但与TexShop合编.以下是源代码:

\documentclass[nobib,notoc,nofonts]{tufte-book}

\usepackage{authorindex}
\usepack[nohits]{minitoc}

\renewcommand{\Rcolor}{\color{black}}
\renewcommand{\Rbackground}{\color[RGB]{253, 246 ,228}}
\renewcommand{\Routbackground}{\color[RGB]{228, 246, 253}}
\renewcommand{\Sweavesize}{\footnotesize}
\definecolor{stringColor}{RGB}{237, 121, 83}
\definecolor{commentColor}{RGB}{204, 70, 120}
\definecolor{linkColor}{RGB}{13, 8, 135}
\definecolor{keywordColor}{RGB}{93, 1, 166}
\usepackage{listings}
\lstset{
    language = R,
    breaklines = TRUE,
    frame = single,
    numbers = left,
    numberstyle = \scriptsize,
    numbersep = 5pt,
    framesep = 1pt,
    rulesepcolor=\color{gray},
    rulecolor=\color{black},
        stepnumber = 2,
    firstnumber = 1,
    stringstyle = \color{stringColor},
    commentstyle = \color{commentColor},
    keywordstyle = \color{keywordColor}
}

<<setup, include = FALSE, cache = FALSE>>=
opts_chunk$set(
    fig.path = 'figure/listings-',
    tidy = TRUE,
    tidy.opts = list(
        blank = FALSE,
        collapse = TRUE,
        arrow = TRUE,
        indent = 2,
        width.cutoff = 60,
        tidy_eval = TRUE
    )
)
render_listings()
require(tidyverse)
@

\begin{document}

<<iq>>=
iq <- c(129, 112, 114, 126, 104, 112, 101, 99, 93)
iq
iq <- as_tibble(iq)
iq
@
<<sess>>=
sessionInfo()
@
\end{document}

注意:我不清楚为什么没有这些行就无法编译

\usepackage{authorindex}

\usepack[nohits]{minitoc}

因为它们似乎与这个问题无关

以下是TeXShop的输出图像:

output of compilation with TeXShop

推荐答案

问题似乎是中间的×人.特克斯档案.

通过 Select 支持unicode的引擎(如lualatex或xelatex)来编译文档,可以避免这个问题:

enter image description here

R相关问答推荐

更改网格的crs以匹配简单要素点对象的crs

使用预定值列表将模拟数量(n)替换为rnorm()

使用sensemakr和fixest feols模型(R)

从R中的另一个包扩展S3类的正确方法是什么

R Markdown中的交叉引用表

从R导出全局环境中的所有sf(numrames)对象

使用tidy—select创建一个新的带有mutate的摘要变量

如何直接从R中的风险分数计算c指数?

如何在所有绘图中保持条件值的 colored颜色 相同?

以相同的方式对每个表进行排序

函数可以跨多个列搜索多个字符串并创建二进制输出变量

在R中,如何从一系列具有索引名的变量快速创建数据帧?

使用geom_sf跨越日期线时的闭合边界

TidyVerse中长度不等的列结合向量

使用函数从R中的列中删除标高

R try Catch in the loop-跳过缺少的值并创建一个DF,显示跳过的内容

如何将图例文本添加到图例符号中

使用dqur在不同变量上创建具有多个条件的变量

如何计算多个变量的百分比与总和的百分比?

动态统计函数在ShinyApp内部更改