如何在 r 考试中包含突出显示的 R 代码块?



我试图创建一个包含格式化r代码的练习。

问题

= = = = = == =

你想要加载整洁的包。请填写以下 r 代码。

```r _______(tidyverse) ```

现在,相应的环境shaded等在 rmarkdown 中丢失了。 我尝试在exams2nops函数中使用header参数。但这只会包括文档正文中的字符串。如何编辑输出 pdf 的序言?

谢谢:)

我找到了解决方案。我创建了一个inject.tex文件,扫描后将其传递给header参数。该文件包含以下内容

usepackage{color}
usepackage{fancyvrb}
newcommand{VerbBar}{|}
newcommand{VERB}{Verb[commandchars=\{}]}
DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\{}}
usepackage{framed}
definecolor{shadecolor}{RGB}{248,248,248}
newenvironment{Shaded}{begin{snugshade}}{end{snugshade}}
newcommand{KeywordTok}[1]{textcolor[rgb]{0.13,0.29,0.53}{textbf{#1}}}
newcommand{DataTypeTok}[1]{textcolor[rgb]{0.13,0.29,0.53}{#1}}
newcommand{DecValTok}[1]{textcolor[rgb]{0.00,0.00,0.81}{#1}}
newcommand{BaseNTok}[1]{textcolor[rgb]{0.00,0.00,0.81}{#1}}
newcommand{FloatTok}[1]{textcolor[rgb]{0.00,0.00,0.81}{#1}}
newcommand{ConstantTok}[1]{textcolor[rgb]{0.00,0.00,0.00}{#1}}
newcommand{CharTok}[1]{textcolor[rgb]{0.31,0.60,0.02}{#1}}
newcommand{SpecialCharTok}[1]{textcolor[rgb]{0.00,0.00,0.00}{#1}}
newcommand{StringTok}[1]{textcolor[rgb]{0.31,0.60,0.02}{#1}}
newcommand{VerbatimStringTok}[1]{textcolor[rgb]{0.31,0.60,0.02}{#1}}
newcommand{SpecialStringTok}[1]{textcolor[rgb]{0.31,0.60,0.02}{#1}}
newcommand{ImportTok}[1]{#1}
newcommand{CommentTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{textit{#1}}}
newcommand{DocumentationTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{textbf{textit{#1}}}}
newcommand{AnnotationTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{textbf{textit{#1}}}}
newcommand{CommentVarTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{textbf{textit{#1}}}}
newcommand{OtherTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{#1}}
newcommand{FunctionTok}[1]{textcolor[rgb]{0.00,0.00,0.00}{#1}}
newcommand{VariableTok}[1]{textcolor[rgb]{0.00,0.00,0.00}{#1}}
newcommand{ControlFlowTok}[1]{textcolor[rgb]{0.13,0.29,0.53}{textbf{#1}}}
newcommand{OperatorTok}[1]{textcolor[rgb]{0.81,0.36,0.00}{textbf{#1}}}
newcommand{BuiltInTok}[1]{#1}
newcommand{ExtensionTok}[1]{#1}
newcommand{PreprocessorTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{textit{#1}}}
newcommand{AttributeTok}[1]{textcolor[rgb]{0.77,0.63,0.00}{#1}}
newcommand{RegionMarkerTok}[1]{#1}
newcommand{InformationTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{textbf{textit{#1}}}}
newcommand{WarningTok}[1]{textcolor[rgb]{0.56,0.35,0.01}{textbf{textit{#1}}}}
newcommand{AlertTok}[1]{textcolor[rgb]{0.94,0.16,0.16}{#1}}
newcommand{ErrorTok}[1]{textcolor[rgb]{0.64,0.00,0.00}{textbf{#1}}}
newcommand{NormalTok}[1]{#1}

最新更新