2012-10-10 31 views
2

我想用一些中文插入來編寫一個英文LyX文檔,而且我也希望針對這些數字和分析編寫一個。我的安裝喜歡knitr,它喜歡中文(使用「替代」方法:http://wiki.lyx.org/LyX/Chinese#toc5),但我無法獲得帶有CJK的文檔進行編織。用LyX編織的CJK(Windows 7)

我測試文檔具有這樣的文本(特克斯在TeX的代碼箱):

Hello  
\cntxt{你好嗎} 

我的用戶定義的前導碼是(從LyX的維基):

\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 
+1

您正在使用Windows,因此可能是此處所述的區域設置問題?這可能聽起來像巫術,但不幸的是,Windows下的R似乎不能很好地與CJK腳本搭配。 http://stackoverflow.com/questions/11069908/r-extracting-clean-utf-8-text-from-a-web-page-scraped-with-rcurl – SlowLearner

+0

是的,我已經與R和locales進行過戰鬥(並失去了;請參閱[我問了幾個月前的問題](http://stackoverflow.com/questions/10675360/utf-8-file-output-in-r),這似乎是你鏈接的一個副本我也是)。如果我有時間,也許我會亂搞LyX-> knitr腳本,看看這個問題中的「修復」是否有效。讓我感到滿足的是knitr例子中的034-chinese.html中的CJK,所以有一點希望。 – Patrick

+0

如果可能請粘貼完整的日誌,否則我必須猜測很多東西,例如如果這個bug正在咬你,你可以http://www.lyx.org/trac/ticket/7741另見http://www.mail-archive.com/[email protected]/msg93501.html –

回答

0

不知道這是否算作一個答案,而是採取了網頁從SlowLearner的書我在LyX20 \資源區域設置\腳本\ lyxknitr搞砸左右。 R.

添加代碼

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

針織()之前做了什麼,我想要的。儘管如此,上帝保佑我不應該在文件中加入另一種非羅馬語言。

+0

不這樣做 - 從不硬編碼區域;看到我上面的評論 –