Search code examples
rknitrbookdown

R markdown / bookdown - how to switch to rticles?


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.

Solution

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