R Markdown / Bookdown - 如何切换到rticles?

3

输入数据

我准备了一个带有对图表和方程的引用的 Rmd 示例文件,并将其设置为输出“bookdown::pdf_document2”。它可以编译成 PDF 而不出错。

我将其放在 Dropbox 上:https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0


问题

现在我想要将输出格式设置为“rticles::elsevier_article”。

我该怎么做?

问题描述

当我将输出行从:

bookdown::pdf_document2

更改为:

rticles::elsevier_article

我收到了错误信息。

即使我从输出中删除其他参数:

TriedToSwitch

我仍然收到错误信息:

! Undefined control sequence.
2个回答

4
当输入“as is”时,带重音的字符在与elsevier_article一起使用时似乎无法正常工作。请参见以下建议。

基础文档

这是一个使用rticles::elsevier_article的基础文档:

---
title: "Sample document"
author: 
  - name: "Mateusz Kędzior"
    affiliation: Some Institute of Technology
    email: Mateusz@example.com
    footnote: Corresponding Author
  - name: Żąćł Źęń    
csl: https://www.zotero.org/styles/geoderma
output:
  rticles::elsevier_article:
    citation_package: natbib
    keep_tex: yes
    number_sections: yes
    toc: no
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---

Hello world.

没有任何投诉的渲染:

enter image description here


带重音的参考文献

现在,我们想添加一个带重音的参考文献。我们遵循这里的答案:https://tex.stackexchange.com/questions/57743/how-to-write-%C3%A4-and-other-umlauts-and-accented-letters-in-bibliography。我将您的参考文献导入了Zotero,然后使用“中欧(ISO)”编码(而不是UTF-8)导出项目,以获得

@article{kedzior_this_2018,
    title = {This is sample title only {\k A} {\L }},
    volume = {99},
    url = {http://megooglethat.com/},
    journal = {Some journal},
    author = {K{\k e}dzior, Mateusz and {\'Z}{\k e}{\'n}, {\.Z}{\k a}{\'c}{\l }},
    year = {2018},
    keywords = {keywordC},
    pages = {21 -- 31}
}

现在,R Markdown文档变得

---
title: "Sample document"
author: 
  - name: "Mateusz Kędzior"
    affiliation: Some Institute of Technology
    email: Mateusz@example.com
    footnote: Corresponding Author
  - name: Żąćł Źęń    
csl: https://www.zotero.org/styles/geoderma
output:
  rticles::elsevier_article:
    citation_package: natbib
    keep_tex: yes
    number_sections: yes
    toc: no
biblio-files: bibliography2.bib
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---

## Citations and references

Let me cite an article: [@kedzior_this_2018]

# References

我在RStudio中编织了这个内容,但是意识到我需要获取tex输出并重新构建它(在RStudio之外)才能得到所需的结果。 enter image description here


其他问题

对于图题中的重音字符,需要按照相应方式进行编码(如参考文献)。您可以访问http://w2.syronex.com/jmr/latex-symbols-converter来获得帮助。此外,据我所知,bookdown样式的交叉引用无法与rticles兼容。如果您有后续问题,请将问题细分为更小的部分以获得更好的回答。


R Markdown文档存在许多问题。我认为你的回答中这部分内容暗示了读者我的文档根本无法工作,这是不正确的。当你将输出设置为pdf_document2时,它可以编译没有错误。我认为如果“重音字符”不是主要问题,而基本上整个文档都应该显着更改,最好的方法是简单地回答rticles与pdf_document2 不兼容 - matandked
好的,我编辑了我的答案以澄清。我不知道rticles是否一定与pdf_document2不兼容。但是当使用爱思维尔模板时,参考文献和标题确实需要适当编码。 - Weihuang Wong
谢谢!我接受了你的回答。我记得当我在准备文章时遇到重音字符的问题,我直接在LaTeX文档中使用了一些库来支持UTF-8字符...但现在,我希望直接在Rmd中准备所有的工作。 - matandked

1

我已经在评论https://github.com/rstudio/rticles/issues/92#issuecomment-402784283中添加了一些更新的材料,其中指出(可能已更新):

output: 
  bookdown::pdf_document2:
    base_format: rticles::elsevier_article
    number_sections: yes

因此,我让它使用pdf_book而不是pdf_document2的方式来工作:

output:
  bookdown::pdf_book:
    base_format: rticles::elsevier_article
    number_sections: yes

这使得在rticles文档中可以引用图表。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接