首页 > 解决方案 > 在 Rmarkdwon 中编译 Latex 文档时读取 md/tex/Rmd 文件时出错

问题描述

在 Rmarkdown 中使用 Latex 时,我试图在引用之后添加一个或多个附录页。在尝试“ Pandoc insert appendix after bib ”和“ Insert Annex after references ”中的解决方案后,我收到一个对我来说没有任何意义的错误,因为它提供的解决方案与数字类型有关(我不是在处理和?)。

我的标题:

---
title: "A smart title here"
author: "Ashameed Person"
geometry: margin=1in
header-includes:
  \usepackage{array}
  \usepackage{tabularx}
  \AtBeginDocument{\let\maketitle\relax} #to hide title
output:
  bookdown::pdf_book:
    fig_caption: yes
    keep_tex: no
    number_sections: yes
    toc: yes
    toc_bib: yes
    toc_depth: 2
    citation_package: natbib
    pandoc_args: ["--include-after-body=appendix.md"]
fontsize: 12pt
bibliography: WorkCited.bib
biblio-style: humannat
link-citations: true
---

我的 Rmd 文件:

knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, eval = TRUE)
\section{new section}
A lot of gibirish \citep{scottdamblon2010, hirth2010}.
See appendix for more info.

编译我的文档时出现以下错误:

! Missing $ inserted.
                $
l.142   bookdown::pdf_
                      book: 

Try to find the following text in Draft1.Rmd:
  bookdown::pdf_ 

You may need to add $ $ around a certain inline R expression `r ` in Draft1.Rmd (see the above hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Error: LaTeX failed to compile Draft1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Draft1.log for more info.
Execution halted

我的appendix.md类似于上面的,它看起来像这样:

---
output:
  bookdown::pdf_book:
    keep_tex: yes
    number_sections: no
    citation_package: natbib
fontsize: 12pt
link-citations: true
---

\section{Appendix B - Raw Data}
\newpage
Raw data can be found at some repository

我还尝试使用文件扩展名 .Rmd 和 .tex 而不是在参数之后找到的 .md pandoc_args:。另外,我尝试过更改pandoc_args:includes: after_body: appendix.md但这会编译我的pdfbook,但不会添加附录部分。

您可以在这些 github 的链接中找到我的参考资料我的原始 rmdhumannat 文件附录文件。

标签: rlatexr-markdownknitrpandoc

解决方案


推荐阅读