从R Markdown到LaTeX的错误转换 [英] Incorrect conversion from R Markdown to LaTeX

查看:542
本文介绍了从R Markdown到LaTeX的错误转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以下R Markdown最小(非)工作示例无法编译为PDF?

Why does the following R Markdown minimal (non)-working example not compile to PDF?

---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{The performance of new graduates}
- \lfoot{From: K. Grant}
- \cfoot{To: Dean A. Smith}
output:
  pdf_document:
    keep_tex: yes
    latex_engine: xelatex
---

# Test

特别是,有问题的转换发生在-\lfoot{From: K. Grant}-\cfoot{To: Dean A. Smith}上,如在输出.tex文件中所见:

In particular, the problematic conversion happens to -\lfoot{From: K. Grant} and -\cfoot{To: Dean A. Smith}, as seen in the output .tex file:

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{The performance of new graduates}
true
true

由于某些原因,这两行都转换为true导致

For some reason, both of these lines are converted to true causing

LaTeX错误:缺少\begin{document}

从而防止文档编译为PDF.

thereby preventing the document from compiling to PDF.

\lfoot\cfoot更改为几乎所有其他内容似乎会导致它们正确转换.那么这是怎么回事?我认为转换过程中knitrpandoc肯定有问题.

Changing \lfoot and \cfoot to just about anything else seems to lead to them being converted correctly. So what's going on here? I take it that there must be a problem with either knitr or pandoc in the conversion process.

注意:我对R Markdown不太熟悉,这是对推荐答案

问题是:字符. pandoc似乎试图解析header-includes内容,就好像它是变量一样,并且:用于分隔变量和值.如果您引用有问题的行,它将编译(不要忘记,以免引起反斜杠)

The : character is the problem. pandoc seems to be trying to parse the header-includes content as if it were variables, and : is used to separate variables and values. It compiles if you quote the lines in question (don't forget, then, to escape the leading backslash)

---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{The performance of new graduates}
- "\\lfoot{From: K. Grant}"
- "\\cfoot{To: Dean A. Smith}"
output:
  pdf_document:
    keep_tex: yes
    latex_engine: xelatex
---

# Test

这篇关于从R Markdown到LaTeX的错误转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆