2

我正在尝试用英文写一个 LyX 文档,其中穿插一些中文,我还想要 knitr 用于数字和分析。我的安装喜欢 knitr,它喜欢中文(在此处使用“替代”方法:http ://wiki.lyx.org/LyX/Chinese#toc5 ),但我无法获取包含 CJK 的文档来编织。

我的测试文档有这个文本(TeX 代码框中的 Tex):

Hello    
\cntxt{你好吗}

我的用户定义序言是(来自 LyX wiki):

\usepackage{CJKutf8}
\usepackage[overlap, CJK]{ruby}
\newenvironment{SChinese}{%
\CJKfamily{gbsn}%
\CJKtilde
\CJKnospace}{}
\newcommand{\cntxt}[1]{\begin{CJK}{UTF8}{}\begin{SChinese}#1\end{SChinese}\end{CJK}}

文档设置:我的语言是英语,编码是 utf8(这些的其他选项似乎没有任何改变)。谢一辉网站上提到的,关闭了 LyX 中的语言标记。

当 knitr 被加载并且我查看 [PDF (pdflatex)] 时,它在发送到 R 时会打嗝:

10:13:40.589: Warning in readLines(input, warn = FALSE) :
10:13:40.597:   invalid input found on input connection 'test-chinese-2.Rnw'

乳胶不喜欢它得到的东西:

! File ended while scanning use of \cntxt.

取出中文字符即可消除错误。离开中文并卸载knitr也消除了错误。关于如何保留 CJK、保持 knitr 加载以及仍然获取文档的任何建议?

Lyx 是原生 Windows 2.0.4,R 是 2.15.1,knitr 是 0.8。knitr-examples中的034-chinese.Rhtml示例完美运行。

这是消息窗口输出:

13:45:45.419: Previewing ...
13:45:45.581: Rscript --verbose --no-save --no-restore "C:/Program Files (x86)/LyX20/Resources/scripts/lyxknitr.R" "C:/Users/Patrick/AppData/Local/Temp/lyx_tmpdir.Hp8472/lyx_tmpbuf2/""test-chinese-2.Rnw" "C:/Users/Patrick/AppData/Local/Temp/lyx_tmpdir.Hp8472/lyx_tmpbuf2/""test-chinese-2.tex" UTF-8 "C:/Users/Patrick/Downloads/"
Running: Rscript --verbose --no-save --no-restore "C:/Program Files (x86)/LyX20/Resources/scripts/lyxknitr.R" "C:/Users/Patrick/AppData/Local/Temp/lyx_tmpdir.Hp8472/lyx_tmpbuf2/""test-chinese-2.Rnw" "C:/Users/Patrick/AppData/Local/Temp/lyx_tmpdir.Hp8472/lyx_tmpbuf2/""test-chinese-2.tex" UTF-8 "C:/Users/Patrick/Downloads/"
13:45:47.202: [1] TRUE
13:45:47.203: [1] TRUE
13:45:47.230: running
13:45:47.237:   'C:\PROGRA~1\R\R-215~1.1\bin\i386\Rterm.exe --slave --no-restore --no-save --no-restore --file=C:/Program Files (x86)/LyX20/Resources/scripts/lyxknitr.R --args C:/Users/Patrick/AppData/Local/Temp/l
13:45:47.247: yx_tmpdir.Hp8472/lyx_tmpbuf2/test-chinese-2.Rnw C:/Users/Patrick/AppData/Local/Temp/lyx_tmpdir.Hp8472/lyx_tmpbuf2/test-chinese-2.tex UTF-8'
13:45:47.252: 
13:45:47.258: Warning in readLines(input, warn = FALSE) :
13:45:47.266:   invalid input found on input connection 'test-chinese-2.Rnw'
13:45:47.802: 
  |                                                                       
  |                                                                 |   0%
  |                                             
13:45:47.813:                           
  |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100%
13:45:47.820:   ordinary text without R code
13:45:47.826: 
13:45:47.828: 
13:45:47.832: [1] "test-chinese-2.tex"
13:45:47.836: [1] TRUE
13:45:47.837: [1] TRUE
13:45:47.843: 
13:45:47.844: 
13:45:47.848: processing file: test-chinese-2.Rnw
13:45:47.854: output file: C:\Users\Patrick\Downloads\test-chinese-2.tex
13:45:47.860: 
13:45:47.875: pdflatex  "test-chinese-2.tex"
Running: pdflatex  "test-chinese-2.tex" > nul
13:45:48.186: This is pdfTeX, Version 3.1415926-2.3-1.40.12 (MiKTeX 2.9)
13:45:48.215: entering extended mode
13:45:48.219: 
13:45:48.224: (C:\Users\Patrick\AppData\Local\Temp\lyx_tmpdir.Hp8472\lyx_tmpbuf2\test-chinese
13:45:48.229: -2.tex
13:45:48.233: LaTeX2e <2011/06/27>
13:45:48.239: Babel <v3.8m> and hyphenation patterns for english, afrikaans, ancientgreek, ar
13:45:48.247: abic, armenian, assamese, basque, bengali, bokmal, bulgarian, catalan, coptic, 
13:45:48.255: croatian, czech, danish, dutch, esperanto, estonian, farsi, finnish, french, ga
13:45:48.263: lician, german, german-x-2009-06-19, greek, gujarati, hindi, hungarian, iceland
13:45:48.269: ic, indonesian, interlingua, irish, italian, kannada, kurmanji, lao, latin, lat
13:45:48.275: vian, lithuanian, malayalam, marathi, mongolian, mongolianlmc, monogreek, ngerm
13:45:48.280: an, ngerman-x-2009-06-19, nynorsk, oriya, panjabi, pinyin, polish, portuguese, 
13:45:48.285: romanian, russian, sanskrit, serbian, slovak, slovenian, spanish, swedish, swis
13:45:48.291: sgerman, tamil, telugu, turkish, turkmen, ukenglish, ukrainian, uppersorbian, u
13:45:48.296: senglishmax, welsh, loaded.
13:45:48.300: 
13:45:48.638: Error while previewing format: pdf2C:\Users\Vincent\Documents\LyX\source\lyx20x\src\support\Systemcall.cpp(273): Systemcall: 'pdflatex  "test-chinese-2.tex"' finished with exit code 1
4

1 回答 1

0

不确定这是否算作一个答案,但是从 SlowLearner 的书中拿了一页我弄乱了 LyX20\Resources\scripts\lyxknitr.R 中的语言环境设置。

添加代码

## add a kludge for locale 
print(Sys.getlocale(category = "LC_CTYPE"))
Sys.setlocale("LC_CTYPE","chinese")

在 knit() 做我想要的之前。不过,上帝禁止我想在文档中添加另一种非罗马语言。

于 2012-10-10T23:52:46.560 回答