我正在使用 rticles 包创建报告,并且在编织包含代码块的rticle IEEE论文时遇到以下错误:
输出文件:rticles_IEEE.knit.md ! LaTeX错误:环境阴影未定义。
我试图了解如何解决此问题,并尝试使用此question/answer。但是我看不到将修补程序放置到通过编织创建的文件中的位置(例如mydoc.tex,IEEE_trans.cls)。
这是我的最小示例:
---
title: Cool IEEE ArticleS
author:
- name: Ray
abstract: |
The abstract of my first IEEE paper with rmarkdown
output: rticles::ieee_article
---
Introduction
=============
This is the introduction. And here comes a cool code chunk.
```{r}
x <- seq(-3,3,0.1)
y <- x^3
plot(x,y)
```
注释:
答案 0 :(得分:3)
总体问题是,在IEEE论文的文章中显示代码块会引发指向未定义阴影环境的错误。
如果将以下内容添加到基础LaTeX template.tex
,则older post works中给出的解决方案。我的问题是我尝试在工作目录中编辑tex或cls模板。当我偶然发现以下{相关的stackoverflow question}时,尤里卡时刻来了。
对于文章软件包,template.tex
不在您的文章R Markdown文件上的目录中。相反,它们存储在软件包库文件夹(即.libPaths()
使用的文件夹)中。可以在rmarkdown/templates/
中找到该文件,然后搜索您正在使用的rticles文件夹(在我的情况下为ieee_article
)。在resources
子文件夹中,您将找到目标template.tex。复制它,以便恢复。
打开template.tex,然后在LATEX命令行\begin{document}
之前的任何位置插入以下内容(注意:又名template.tex文件的序言)。例如,我将其插入\ begin {document}行之前:
% code to insert to fix environment Shaded undefined issue with
% showing code chunks in rticle IEEE template.
$if(highlighting-macros)$
$highlighting-macros$
$endif$
\begin{document}
保存更改,然后返回R / RStudio和您的IEEE纸R Markdown文件,然后单击“编织”按钮。现在将显示R代码块(如果需要)。
我还没有对它进行彻底的测试,但是此食谱应该适用于所有缺少环境定义以显示r代码块(即environment{Shaded}
)的模板模板
答案 1 :(得分:2)
您无需复制模板,而是可以将用于突出显示所需的代码放在单独的header.tex
文件中。当您在模板中添加$highlighting-macros$
时,基本上就是这样:
header.tex
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\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}
在您的目录中复制此文件,然后在YAML中引用此标头:
---
title: Short Paper
output:
rticles::ieee_article:
includes:
in_header: header.tex
---
# Introduction
This is the introduction. And here comes a cool code chunk.
```{r}
x <- seq(-3,3,0.1)
y <- x^3
plot(x,y)
```
此方法应适用于包含
的任何模板$header-includes$ tag in the
template.tex`