rstudio / rticles

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

Change bibliographystyle in elsevier_article when using natbib #395

Closed hongyuanjia closed 3 years ago

hongyuanjia commented 3 years ago

Why natbib but not csl?

This is because I want to get a clean TeX file together with the output PDF. Using csl will write all references into the TeX file, e.g.

\hypertarget{refs}{}
\begin{CSLReferences}{0}{0}
\leavevmode\hypertarget{ref-jia2021eplusr}{}%
\CSLLeftMargin{{[}1{]} }
\CSLRightInline{H. Jia, A. Chong, Eplusr: {A} framework for integrating building energy simulation and data-driven analytics, Energy and Buildings. 237 (2021) 110757. doi:\href{https://doi.org/10.1016/j.enbuild.2021.110757}{10.1016/j.enbuild.2021.110757}.}

\leavevmode\hypertarget{ref-crawley2001energyplus}{}%
\CSLLeftMargin{{[}2{]} }
\CSLRightInline{D.B. Crawley, L.K. Lawrie, F.C. Winkelmann, W.F. Buhl, Y.J. Huang, C.O. Pedersen, et al., {EnergyPlus}: Creating a new-generation building energy simulation program, Energy and Buildings. 33 (2001) 319--331. doi:\href{https://doi.org/10.1016/s0378-7788(00)00114-6}{10.1016/s0378-7788(00)00114-6}.}

\end{CSLReferences}

Currently elsevier_article hard-codes \bibliographystyle{plainnat}:

https://github.com/rstudio/rticles/blob/d93d50b39933b6ad91c245c95c008a5e3544716d/inst/rmarkdown/templates/elsevier/resources/template.tex#L58-L63

The default Pandoc LaTeX template exposes an option biblio-style to let the user to define the bibliography style. It is possible to implement this in the elsevier_article? Thanks.

https://github.com/jgm/pandoc-templates/blob/master/default.latex#L365-L374

$if(natbib)$
\usepackage[$natbiboptions$]{natbib}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(biblatex)$
\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex}
$for(bibliography)$
\addbibresource{$bibliography$}
$endfor$
$endif$
cderv commented 3 years ago

I think this has been closed by #402. You can now use biblio-style using dev version of rticles

Thanks for the suggestion !

hongyuanjia commented 3 years ago

Great! Thanks!

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.