R markdown / bookdown - how to switch to rticles?

冷暖自知 提交于 2019-12-13 16:14:49

问题


Input data

I prepared an example Rmd file with references to figure, table and equation, setting as an output 'bookdown::pdf_document2'. It compiles without errors to PDF.

I placed it on dropbox: https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0


Question

Now I wish to set as an output format 'rticles::elsevier_article'

How can I do that?

Issue

When I change output line from: bookdown::pdf_document2 to rticles::elsevier_article

I'm receiving an error message.

Even if I remove other parameters from output:

I still receive an error message:

! Undefined control sequence.

回答1:


Accented characters when input "as is" do not appear to behave well with elsevier_article. See suggestions below.


Bare-bones document

Here is a bare-bones document using 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.

which renders with no complaints:


Reference with accents

Now, we wish to add a reference with accents. We follow the answer here: https://tex.stackexchange.com/questions/57743/how-to-write-%C3%A4-and-other-umlauts-and-accented-letters-in-bibliography. I imported your bibliography into Zotero, and then exported the item with a "Central European (ISO)" encoding (not UTF-8) to obtain

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

The R Markdown document now becomes

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

I then knited this in RStudio, but realised that I had to get the tex output and rebuild it (outside of RStudio) to get the desired output


Other problems

For accented characters in figure captions, encode them accordingly (as with the bibliography). You may find http://w2.syronex.com/jmr/latex-symbols-converter helpful. In addition, to the best of my knowledge bookdown style cross-referencing does not work with rticles. If you have follow-up questions, you may get more helpful answers if you break your question down into smaller chunks.




回答2:


I've added a bit of updated material to the commenthttps://github.com/rstudio/rticles/issues/92#issuecomment-402784283 where it states (may be updated):

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

such that the way I've had this work is using pdf_book versus pdf_document2:

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

This allows for figure and table referencing within an rticles document.



来源:https://stackoverflow.com/questions/42312601/r-markdown-bookdown-how-to-switch-to-rticles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!