3

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:

TriedToSwitch

I still receive an error message:

! Undefined control sequence.
matandked
  • 1,527
  • 4
  • 26
  • 51

2 Answers2

4

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:

enter image description here


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 enter image description here


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.

Community
  • 1
  • 1
Weihuang Wong
  • 12,868
  • 2
  • 27
  • 48
  • "There are many problems with the R Markdown document" --> I think that this part of your answer suggest the reader that my document is not working at all. Which is not true, it compiles **without** errors when you set as an output pdf_document2. I think that if the "accented characters" are not the main problem, but basically whole document should be significantly changed it will be better to simply answer that rticles is **not** compatible with pdf_document2. – matandked Feb 19 '17 at 18:19
  • Fair enough, I've edited my answer to clarify. I don't know if `rticles`is necessarily incompatible with `pdf_document2`. But it's true that the bibliography and captions need to be encoded appropriately when the Elsevier template is used. – Weihuang Wong Feb 19 '17 at 18:25
  • Thanks! I accepted your answer. I remember that when I had issue with accented characters and preparing article, I used some library in my LaTeX document directly to add support to UTF-8 characters... But know, I wish to prepare all my work directly in Rmd – matandked Feb 19 '17 at 18:32
1

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.

John M
  • 1,115
  • 8
  • 10