knitr LaTeX单引号排版不正确

knitr LaTeX单引号排版不正确,latex,knitr,Latex,Knitr,呃, 我们的实验室在使用LaTeX正确排版包含单引号的R代码时遇到问题。这些文档编译得很好,没有错误,但是用单引号括起来的R代码没有排版,因此R代码没有正确显示 问题仍然存在,与用于将.Rnw编译为pdf的工具无关。到目前为止,我们已经尝试在RStudio中进行编译,并在CLI上使用knit()调用pdflatex,以及使用knit2pdf()进行编译 我们为我们的问题提供了一个工作示例: \documentclass{article} \usepackage{graphicx} \usepac

呃,

我们的实验室在使用LaTeX正确排版包含单引号的R代码时遇到问题。这些文档编译得很好,没有错误,但是用单引号括起来的R代码没有排版,因此R代码没有正确显示

问题仍然存在,与用于将.Rnw编译为pdf的工具无关。到目前为止,我们已经尝试在RStudio中进行编译,并在CLI上使用knit()调用pdflatex,以及使用knit2pdf()进行编译

我们为我们的问题提供了一个工作示例:

\documentclass{article}
\usepackage{graphicx}
\usepackage{upquote} %Using this pkg does not fix single quotes problem
\usepackage[sc]{mathpazo} %Problem persists with or without Computer Modern
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}
\usepackage{breakurl}
\usepackage{inconsolata} %Problem persists with or without inconsolata
\usepackage[auth-sc]{authblk}
%
\title{Some title \\ \vspace{3 mm}
{\large \textit{Supplemental Methods To:}\\ 
\normalsize "Even bigger title"}}

\begin{document}

<<setup, include=FALSE, cache=FALSE>>=
# this is equivalent to \SweaveOpts{...}
opts_chunk$set(fig.path='figure/minimal-', fig.align='center', fig.show='hold')
options(replace.assign=TRUE,width=90)
#require(highlight) # Problem persists with or without highlight
@

\maketitle

\section{Some Section}
In R, characters can be entered with double quotes or single quotes. The single quote is the apostrophe key next to ENTER on an American keyboard.\\
This R code with characters contained by single quotes does not render correctly in \LaTeX{}. But characters in double quotes do render correctly.
<<raw_nums>>=
Vector1<-c('A','B','C') # This line not typeset correctly; the quotes are missing in the pdf
Vector1
Vector2<-c("A","B","C") # Typeset correctly
Vector2
@

<<sessionInfo>>=
sessionInfo()
@

\end{document}
\documentclass{article}
\usepackage{graphicx}
\使用此pkg的usepackage{upquote}%无法修复单引号问题
\usepackage[sc]{mathpazo}%问题在使用或不使用计算机时仍然存在
\usepackage[T1]{fontenc}
\usepackage{geometry}
\几何体{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
{hyperref}
\usepackage{breakurl}
\usepackage{Incolata}%有或没有Incolata时问题仍然存在
\usepackage[auth sc]{authblk}
%
\标题{Some title\\\vspace{3 mm}
{\large\textit{补充方法:}\\
\normalsize“更大的标题”}
\开始{document}
=
#这相当于\swaveopts{…}
选择块$set(图path='figure/minimal-',图align='center',图show='hold')
选项(replace.assign=TRUE,width=90)
#需要(突出显示)#无论是否突出显示,问题仍然存在
@
\maketitle
\节{某些节}
在R中,可以使用双引号或单引号输入字符。单引号是美国键盘上ENTER旁边的撇号键\\
此R代码的字符包含在单引号中,无法在\LaTeX{}中正确呈现。但双引号中的字符确实正确呈现。
=

Vector1当我保存您的“最小”示例时,它编译得很好。我猜您的配置(区域设置、文件编码)有问题。你到底是如何编译PDF的?RStudio中的“编译为PDF”按钮,
knit2pdf()
knit()
,然后手动调用
pdflatex
,…..Rnw可以很好地编译为PDF,但在我们的系统中,R code
vector1实际上,您发布的行包含在这里生成的TEX文件中,这行在最终的PDF中呈现得很好(包括单引号!)。这就是为什么我想这不是一个直接的
knitr
相关问题,但还有一些其他原因,比如您用来编译或编码的工具。当您将问题压缩为仅
未渲染时,可能更适合您的问题。当我保存您的“最小值”时例如,它编译得很好。我猜您的配置(区域设置、文件编码)有问题。您如何编译PDF?RStudio中的“编译为PDF”按钮,
knit2pdf()
knit()
然后手动调用
pdflatex
,…?.Rnw可以很好地编译为pdf,但在我们的系统中,R代码
矢量1实际上,您发布的行包含在此处生成的TEX文件中,该行在最终pdf中呈现得很好(包括单引号!)。这就是为什么我想这不是一个直接的
knitr
相关问题,而是有一些其他原因,比如您用来编译或编码的工具。当您将其压缩为仅
未被渲染时,可能更适合您的问题。