2016-09-16 11 views
1

私はPDFファイルに(下記を参照してください).Rmdファイルを変換するために、RStudio(バージョン0.99.903)とknitrを使用していました。RStudio Knitrは(Windows 7の)PDFへのRMDの変換に失敗しました

--- 
title: "test" 
output: pdf_document 
--- 

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}. 

私は実行すると"ニットPDF" I次のエラーメッセージが表示されました:

processing file: test.Rmd 
output file: test.knit.md 

! Undefined control sequence. 
l.87 Roses are \textcolor 

pandoc.exe: Error producing PDF 
Error: pandoc document conversion failed with error 43 
In addition: Warning message: 
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\fuq\R\R-3.3.1\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43 
Execution halted 

しかし、私は例えば、その.Rmdファイルの任意の場所にRコードチャンクを追加した場合:

--- 
title: "test" 
output: pdf_document 
--- 

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}. 

```{r} 
summary(cars) 
``` 

私は期待したPDFを正常に取得できました。

しかし、どのような変だったことは上記.Rmdファイル(下記参照)

--- 
title: "test" 
output: pdf_document 
--- 

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}. 

```{r, echo=FALSE}} 
summary(cars) 
``` 

その後、再びecho=FALSE設定した場合、私は同じエラーメッセージが表示されましたということであった:

! Undefined control sequence. 
l.87 Roses are \textcolor 

pandoc.exe: Error producing PDF 
Error: pandoc document conversion failed with error 43 
In addition: Warning message: 
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\fuq\R\R-3.3.1\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43 
Execution halted 

私はWindows 7 64bitで作業していて、MiKTexの最新バージョンを持っています。誰か私に間違っていた何か考えを与えることができますか?

答えて

2

パッケージcolorを含める必要があります。私はなぜこれがちょうどRのチャンクで動作するのかわかりません。しかし、この解決策は、この問題を解決します:

--- 
title: "test" 
output: pdf_document 
header-includes: \usepackage{color} 
--- 


Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}. 

あなたがHTMLに色をニットしたい場合は、このコードを使用する必要があります。

--- 
title: "test" 
output: html_document 
--- 

Roses are <span style="color:red">red</span>, 
violets are <span style="color:blue">blue</span>. 
+0

はありがとうございました。それはPDFに変換するために動作します!しかし、同じ.RmdファイルをHTMLファイルに「編み込め」しようとすると、それらの色付きテキストが消えます。あなたはまた、この問題について考えていますか?どうもありがとう。 – mikeqfu

+0

また、「ニットワード」にも問題があります。それらの色付けされたテキストは最終的な文書には現れません。 – mikeqfu

+0

@mikeqfu:HTMLの問題は解決されました。私の編集された答えをご覧ください。 MS Wordの場合、今まで解決策はありません。 –

関連する問題