首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从R Markdown到LaTeX的转换不正确

从R Markdown到LaTeX的转换不正确
EN

Stack Overflow用户
提问于 2019-06-10 01:07:45
回答 2查看 0关注 0票数 0

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

代码语言:javascript
复制
---
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的文件:

代码语言:javascript
复制
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{The performance of new graduates}
true
true

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

乳胶错误:遗失 \begin{document}

从而防止文档编译为PDF。

改变\lfoot\cfoot几乎任何其他东西似乎导致他们被正确转换。那么这里发生了什么?我认为转换过程中的任何一个knitrpandoc转换过程都存在问题。

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

EN

回答 2

Stack Overflow用户

发布于 2019-06-10 09:38:52

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

代码语言:javascript
复制
---
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
票数 0
EN

Stack Overflow用户

发布于 2019-06-10 10:31:20

拼接的答案在这里与反复试验,我发现,只有通过删除title键,用YAML管表示多字符串语法会编译:

代码语言:javascript
复制
---
output:
  pdf_document: 
    keep_tex: yes
    latex_engine: xelatex
header-includes: |
   \usepackage{fancyhdr}
   \pagestyle{fancy}
   \fancyhead{}
   \fancyfoot{}
   \lhead{My Title}
   \rhead{My Note}
   \lfoot{\today}\rfoot{Page \thepage}
---
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100009083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档