Closed pepijn-devries closed 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
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.
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 🤔
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
I did the update in the skeleton following this advice. Thank you !
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:
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
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
?
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
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.
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
@cderv Good point. That is probably it. I'm also working with TinyTex as it generally plays nicely with RMarkdown and knitr.
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.
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.
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!
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.
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.
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 addingbiblio-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:
Created on 2023-10-12 with reprex v2.0.2
@cboettig @robjhyndman