rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.46k stars 516 forks source link

Biobliography not formatted correctly in rticles::elsevier_article #545

Closed pepijn-devries closed 8 months ago

pepijn-devries commented 8 months ago

Thanks for your work on rticles. It really helped me to streamline my publication process.

When using rticles::elsevier_article I noticed that the bibliography was formatted incorrectly (e.g., first names showing first instead of last names). For me adding biblio-style: elsarticle-harv to the yaml header fixed the issue. Maybe this can be included in the default template, or it can be noted in the documentation?

This is my session info:

sessionInfo()
#> R version 4.1.1 (2021-08-10)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252   
#> [3] LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C                      
#> [5] LC_TIME=Dutch_Netherlands.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.31   withr_2.5.0     lifecycle_1.0.3 reprex_2.0.2   
#>  [5] evaluate_0.21   rlang_1.1.0     cli_3.4.1       rstudioapi_0.13
#>  [9] fs_1.6.2        rmarkdown_2.22  tools_4.1.1     glue_1.6.2     
#> [13] xfun_0.37       yaml_2.3.7      fastmap_1.1.0   compiler_4.1.1 
#> [17] htmltools_0.5.4 knitr_1.42

Created on 2023-10-12 with reprex v2.0.2

@cboettig @robjhyndman

cderv commented 8 months ago

It seems the template was done using plainnat by default https://github.com/rstudio/rticles/blob/fcbcf83c739b98971e3122a179a5448f993e73d2/inst/rmarkdown/templates/elsevier/resources/template.tex#L57-L60

The LaTeX package guideline (https://www.elsevier.com/authors/policies-and-guidelines/documents/elsdoc-1.pdf)

Three bibliographic style files (*.bst) are provided — elsarticle-num.bst, elsarticle-num-names.bst and elsarticle-harv.bst

I am fine by using one of this as the default if that is better

pepijn-devries commented 8 months ago

Or perhaps include all options in the template and comment out all but one. Than it is visible to the user what the options are.

cderv commented 8 months ago

In fact re-reading the guidelines, I am seeing this about class option

authoryear author-year citation style of natbib.sty. If you want to add extra options of natbib.sty, you may use the options as comma delimited strings as arguments to \biboptions command.

And we use it in the template in classoptions. Is it set for you ?

Not sure how it effect and which bibliostyle should be set with it 🤔

pepijn-devries commented 8 months ago

This is what my yaml-header looks like at the moment. I do have the authoryear option set at the classoption. But without the biblio-style setting defined the bibliography is not formatted correctly. I've added it myself to the default template.

title: "TODO"
author:
  - name: TODO
    email: TODO
    affiliation: TODO
    correspondingauthor: true
address:
  - code: WUR
    organization: TODO
    addressline: TODO
    city: TODO
    postcode: TODO
    country: The Netherlands
abstract: |
  TODO
keywords: 
  - TODO
  - TODO
journal: "TODO"
date: "`r Sys.Date()`"
classoption: preprint, 3p, authoryear
bibliography: library.bib
biblio-style: elsarticle-harv
linenumbers: true
numbersections: true
# Use a CSL with `citation_package = "default"`
# csl: https://www.zotero.org/styles/elsevier-harvard
output: 
  rticles::elsevier_article:
    keep_tex: true
    citation_package: natbib
cderv commented 8 months ago

I did the update in the skeleton following this advice. Thank you !

eugenividal commented 6 months ago

Hi @cderv. Great package! I have the same problem reported here: The Reference list shows first names instead of last names. Adding biblio-style: elsarticle-harv to the yaml header does not work for me. If I add it I get: Screenshot from 2023-12-25 16-19-55

pepijn-devries commented 6 months ago

Hi @eugenividal,

For me the solution above did work. Maybe you could add the complete yaml header that you are using. Otherwise it is impossible to reproduce or solve your problem.

Cheers,

Pepijn

eugenividal commented 6 months ago

Hi @pepijn-devries, thanks for your quick reply. My complete yaml header is below. Now, if I use biblio-style: elsarticle-harv, I get no reference list at all; otherwise, I get the reference list but with first names showing first instead of last names. Should I add a file or something in my main folder to support this biblio-style: elsarticle-harv?

Screenshot from 2023-12-28 08-55-18

pepijn-devries commented 6 months ago

Hi @eugenividal,

I've installed the latest version of rticles from CRAN, and created an RMarkdown document in RStudio from the rticles template. I've used the same settings in my yaml header as you are using above. You don't need to place any files (other than the bibliography) anywhere. All required files are included in the package. For me the pdf is generated without any issues. Which latex engine are you using?

Cheers,

Pepijn

eugenividal commented 6 months ago

Hi @pepijn-devries, thanks for your answer. I've installed the latest version of rticles too but I still get an error (below). I've no idea which latex engine I am using. I guess the one markdown uses by default. Not sure how can I check that.

Screenshot from 2023-12-28 17-01-17

cderv commented 6 months ago

elsarticle-harv.bst seems not found. Though it should be availabel through the CTAN package https://ctan.org/tex-archive/macros/latex/contrib/elsarticle

So check that you have this package installed, and latest version.

If you are using TinyTeX, it should be installed automatically when missing. You can also install and update manually

pepijn-devries commented 6 months ago

@cderv Good point. That is probably it. I'm also working with TinyTex as it generally plays nicely with RMarkdown and knitr.

eugenividal commented 6 months ago

Thanks @cderv. It is working properly now! What do you mean by checking that the package is installed? I just had to save the elsarticle-harv.bst file in the main folder and knit the Rmd with the biblio-style: elsarticle-harv uncommented.

cderv commented 6 months ago

What do you mean by checking that the package is installed?

elsarticle-harv.bst is availabel through a CTAN package https://ctan.org/tex-archive/macros/latex/contrib/elsarticle, so if that package is installed, files provided by this package should have been found correctly.

Placing the file locally works too though.

eugenividal commented 5 months ago

Hi @cderv. Thanks for the clarification. This is what I thought. I just do not know how to install the CTAN package. Is this an R package? Can I install it using my ubuntu terminal? Thanks!

cderv commented 5 months ago

CTAN is https://ctan.org/ - this is the package repository for LaTeX package. Like CRAN for R or CPAN for perl.

Installing a package for LaTeX can be done using TeX Live tlmgr install command. Or tinytex::tlmgr_install() from R is you use TinyTeX and tinytex R package.

Though as I said, it should be done automatically when a missing package is detected. So if it does not do it for you, it means either you don't use TeX Live, or something else prevent installation.

Anyhow, if you start managing TeX Live yourself, or at least do some stuff with LaTeX distribution, you should understand how it works.

eugenividal commented 5 months ago

Thanks for the information, @cderv. I've just run tinytex::install_tinytex() in my Rstudio console and this time the file elsarticle-harv.bst was not required to work properly.