[英]How to customize a css for markdown + knitr in Rstudio?
I want to change the default style sheet for the KnitHTML
function in RStudio 0.96.331
.我想更改
KnitHTML
0.96.331 中RStudio 0.96.331
的默认样式表。
I follow the instructions in this post .我按照这篇文章中的说明进行操作。
First I copy past the original markdown.css from here .首先,我从这里复制过去的原始 markdown.css。 As a test I change the first few lines from:
作为测试,我将前几行从:
body, td {
font-family: sans-serif;
background-color: white;
font-size: 12px;
margin: 8px;
}
to red background到红色背景
body, td {
font-family: sans-serif;
background-color: red;
font-size: 12px;
margin: 8px;
}
and save it as mymd.css
in my working directory.并将其另存为
mymd.css
在我的工作目录中。 I then create a style.R file as follows:然后我创建一个 style.R 文件,如下所示:
options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
require(markdown)
markdownToHTML(inputFile, outputFile, stylesheet='mymd.css')
}
)
Finally, I source the style.R file by clicking source and then go back to the .Rmd
file and knit it to HTML. I get the red background, but the math is not compiled eg $\alpha$最后,我通过单击 source 来获取 style.R 文件,然后将 go 返回到
.Rmd
文件并将其编织为 HTML。我得到红色背景,但数学未编译,例如 $\alpha$
AFAIK,MathJax service was down yesterday due to the GoDaddy outage. 由于GoDaddy中断,AFAIK,MathJax服务昨天下降 。 Can you confirm the math problem was not due to that?
你能否确认数学问题不是由于那个?
So I may have a work around for you, but it involves using pandoc : 所以我可能会为你解决一些问题,但它涉及到使用pandoc :
Suppose your style sheet is called style.css
假设您的样式表称为
style.css
Source the following code: 来源以下代码:
options(rstudio.markdownToHTML = function(inputFile, outputFile) {
system(paste("pandoc -c style.css", shQuote(inputFile),
"-o", shQuote(outputFile)))
}
)
This is maybe a new feature that was not available at the time the question was asked.这可能是在提出问题时不可用的新功能。 However, there is a simple solution I found here:
但是,我在这里找到了一个简单的解决方案:
https://bookdown.org/yihui/rmarkdown/html-document.html#appearance-and-style https://bookdown.org/yihui/rmarkdown/html-document.html#appearance-and-style
In the preamble of your.Rmd, just write this:在 your.Rmd 的序言中,只需这样写:
---
title: "Your title"
output:
html_document:
css: yourstylefile.css
---
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.