从R Markdown到LaTeX的转换不正确

时间:2022-02-04 06:19:35

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

为什么以下R Markdown最小(非)工作示例不能编译为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

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

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

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

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

出于某种原因,这两行都转换为true

LaTeX error: Missing \begin{document}

LaTeX错误:缺少\ begin {document}

thereby preventing the document from compiling to PDF.

从而防止文档编译为PDF。

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.

将\ lfoot和\ cfoot更改为几乎任何其他内容似乎都会导致它们被正确转换。那么这里发生了什么?我认为在转换过程中必须存在knitr或pandoc问题。

NB: I'm not too familiar with R Markdown, and this is a follow-up question to Headers and footers created in Fancyhead not shown in PDF on TeX.SX on Tom's behalf.

注意:我对R Markdown不太熟悉,这是对Fancyhead中创建的页眉和页脚的后续问题,而不代表Tom在TeX.SX上以PDF格式显示。

1 个解决方案

#1


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)

:字符是问题所在。 pandoc似乎试图解析header-includes内容,就像它是变量一样,并且:用于分隔变量和值。如果你引用有问题的行,它会编译(不要忘记,然后,以逃避前导反斜杠)

---
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

#1


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)

:字符是问题所在。 pandoc似乎试图解析header-includes内容,就像它是变量一样,并且:用于分隔变量和值。如果你引用有问题的行,它会编译(不要忘记,然后,以逃避前导反斜杠)

---
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