【发布时间】:2020-06-19 13:15:45
【问题描述】:
我有很多降价文件,每个都有很多代码块,请看下面的示例。 (它们通过 pandoc 从其他文件类型转换为这种格式)
我想把它们编成 Rmd 文件。现在,代码块没有装饰器。当我编织下面的文件时,没有代码语法样式/着色。我不想评估代码,我只想打印出来,因此:knitr::opts_chunk$set(warning=FALSE, message=FALSE, cache=FALSE)。
假设所有代码都是 MATLAB 代码,有没有我可以添加的内容,例如:knitr::opts_chunk$set(code=MATLAB),以便它们都能获得 MATLAB 代码样式/着色?
我的代码块实际上都是 MATLAB 代码,因此 MATLAB stlying/coloring 会更有帮助,但任何代码样式都会很好地使输出的 HTML/PDF 等中的代码块更易于阅读。
---
title: matlab code in blocks
output: html_document
---
# RMD file with Markdown Code Blocks
```{r global_options, include = FALSE}
knitr::opts_chunk$set(warning=FALSE, message=FALSE, cache=FALSE)
```
## Example 1
Here is a code block A
fl_fig_wdt = 3;
fl_fig_hgt = 2.65;
figure('PaperPosition', [0 0 fl_fig_wdt fl_fig_hgt], 'Renderer', 'Painters');
x = rand([10,1]);
y = rand([10,1]);
scatter(x, y, 'filled');
grid on;
grid minor;
## Section 2
Here is a code block B
fl_fig_wdt = 5;
fl_fig_hgt = 5.65;
figure('PaperPosition', [0 0 fl_fig_wdt fl_fig_hgt], 'Renderer', 'Painters');
x = rand([20,1]);
y = rand([20,1]);
scatter(x, y, 'filled');
grid on;
grid minor;
End of file.
【问题讨论】:
标签: r-markdown markdown knitr pandoc