我正在尝试用英语写一个LyX文档,中间穿插一些中文,我还需要编织器来进行图表和分析。我的装置喜欢针织衫,也喜欢中文(在这里使用"另类"方法: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}#1end{SChinese}end{CJK}}
文档设置:我的语言是英语,编码是utf8(其他选项似乎不会改变任何内容)。关闭了LyX中的语言标记,正如谢逸辉网站上提到的那样。
当Knitter被加载并且我查看[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.
去掉汉字可以消除错误。离开中国和卸载编织机也消除了错误。关于如何保持CJK,保持编织器加载,并仍然获得文档,有什么建议吗?
Lyx是本机Windows 2.0.4,R是2.15.1,knifer是0.8。编织器示例中的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~1RR-215~1.1bini386Rterm.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:UsersPatrickDownloadstest-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:UsersPatrickAppDataLocalTemplyx_tmpdir.Hp8472lyx_tmpbuf2test-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:UsersVincentDocumentsLyXsourcelyx20xsrcsupportSystemcall.cpp(273): Systemcall: 'pdflatex "test-chinese-2.tex"' finished with exit code 1
不确定这是否算是一个答案,但我从SlowLearner的书中找了一页,在LyX20\Resources\scripts\lyxknitr.R中搞砸了区域设置。
添加代码
## add a kludge for locale
print(Sys.getlocale(category = "LC_CTYPE"))
Sys.setlocale("LC_CTYPE","chinese")
在Knight()做我想做的事之前。不过,上帝保佑我永远不想在文件中加入另一种非罗马语言。