2012-09-02 10 views
10

「マークダウンは単純ではありませんが、それはしません」と返答されるのは恐ろしいですが、ほとんど尋ねることはありません。印刷時にRマークダウン構文の強調表示を維持する

R Markdownドキュメントを書くとき、私はブラウザでHTMLファイルを見ることができます。紙やPDFで印刷しようとすると、図の色は印刷されますが、構文のハイライトは印刷されません。印刷時に構文ハイライトを維持する方法はありますか?

例:

Minimal Example 
===== 

This text looks great in the file and the plot prints in color, but see commented code  below. 

```{r} 
# this commented line will be green in the HTML file, but will be black when I print it 
z <- cor(mtcars) 
require(lattice) # 'require' will be blue in the HTML file, but will be black when I print it 
levelplot(z) 
``` 

私はRStudioに "ニットHTML" ボタンを押すとChromeやSafariでHTMLを開き、問題はありません。ブラウザからHTMLから印刷すると、すべての構文の強調表示が失われます。

+0

は、あなたのワークフローの最小限の再現性の例を与えることができます? – mnel

+0

Rマークダウンの種類は?ニット? –

+0

Rマークダウンを使用する別の方法はありますか?詳しく教えてください。 –

答えて

9

あなたの元example.Rmdに「ニット」を行った後、あなたが、その後pandocを使用し、作業パスにexample.mdを持っています...

# for pdf (you need to have latex installed) 
system("pandoc example.md -o example.pdf") 

# for syntax-highlight persistant html 
system("pandoc example.md -o example.html -s -S") 
+1

+1でハイライトされているので、私は自分の答えをマージしただけです。 – mnel

関連する問題