6

I'm using elsarticle and I would like to apply biblatex for my references but apparantly natbib.sty is loaded by default. In this case how can I use biblatex or how can I disable natbib?

%% natbib.sty is loaded by default. However, natbib options can be
%% provided with \biboptions{...} command. Following options are
%% valid:

%%   round  -  round parentheses are used (default)
%%   square -  square brackets are used   [option]
%%   curly  -  curly braces are used      {option}
%%   angle  -  angle brackets are used    <option>
%%   semicolon  -  multiple citations separated by semi-colon
%%   colon  - same as semicolon, an earlier confusion
%%   comma  -  separated by comma
%%   numbers-  selects numerical citations
%%   super  -  numerical citations as superscripts
%%   sort   -  sorts multiple citations according to order in ref. list
%%   sort&compress   -  like sort, but also compresses numerical citations
%%   compress - compresses without sorting
%%
%% \biboptions{comma,round}

% \biboptions{}

\usepackage[
backend=biber,
style=alphabetic,
citestyle=authoryear 
]{biblatex}

\addbibresource{references.bib}
\begin{document}
 bla bla bla 
\printbibliography
\end{document}

Messages/Log file: Command \bibhang already defined,

  • From your code it's impossible to say: presumably something earlier is loading natbib – Joseph Wright Aug 2 '16 at 7:28
  • 2
    Welcome. Sorry, but that is not your decision. The journal has its workflow and they are using natbib. Maybe it will be different in the future, who knows? – Johannes_B Aug 2 '16 at 7:29
  • Well, that's sad, but thank you, I appreciate it. – DenFoz Aug 2 '16 at 7:34
  • 1
    There is \RequirePackage[\@biboptions]{natbib} inside of elsarticle.cls. – Henri Menke Aug 2 '16 at 7:36
  • In general there is What to do to switch to biblatex?. But your document class loads natbib no matter what options you use, so there is no way you can use biblatex without modifying the class, which you shouldn't. – moewe Aug 2 '16 at 8:09
5

This solution must only be used for typesetting personal notes!


Do not submit your papers like this!


If you consider submitting your papers with this hack in place, please stop reading right now!


Sometimes the macros defined by the journal documentclasses come in handy for typesetting personal notes. For such private documents however one also wants to exploit the convenience of modern package such as biblatex.

The elsarticle documentclass loads natbib internally which is a show stopper for biblatex. The natbib package is loaded with the line

\RequirePackage[\@biboptions]{natbib}

To this end, hacking into \RequirePackage and make it just skip over natbib would solve the problem at hand. I use the xparse package and the underlying expl3 programming layer to realise such a macro. The (re)definition of such a macro obviously has to be placed before \documentclass.

Furthermore, elsarticle defines a counter called author, which is never used by the class but required by biblatex. We simply undefine the counter by letting its underlying count variable to \relax.

\RequirePackage{xparse}

\ExplSyntaxOn

\clist_new:N \pkg_ignored_clist
\clist_put_right:Nn \pkg_ignored_clist { natbib }

\msg_new:nnn { pkg } { pkg-ignored } { Package~#1~ignored! }

\cs_set_eq:NN \latex_require_package:wnw \RequirePackage

\cs_new_protected:Npn \pkg_require_package:nnn #1#2#3
 {
  \IfValueTF { #1 }
   {
    \IfValueTF { #3 }
     { \latex_require_package:wnw [ #1 ] { #2 } [ #3 ] }
     { \latex_require_package:wnw [ #1 ] { #2 }        }
   }
   {
    \IfValueTF { #3 }
     { \latex_require_package:wnw { #2 } [ #3 ] }
     { \latex_require_package:wnw { #2 }        }
   }
 }

\RenewDocumentCommand \RequirePackage { o m o }
 {
  \clist_if_in:NnTF \pkg_ignored_clist { #2 }
   {
    \msg_warning:nnn { pkg } { pkg-ignored } { #2 }
   }
   {
    \pkg_require_package:nnn { #1 } { #2 } { #3 }
   }
 }

\ExplSyntaxOff

\documentclass{elsarticle}
\expandafter\let\csname c@author\endcsname=\relax
\usepackage[style=authoryear,natbib]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\Citet{weinberg}

\printbibliography
\end{document}

enter image description here

5

This solution must only be used for typesetting personal notes!


Do not submit your papers like this!


If you consider submitting your papers with this hack in place, please stop reading right now!


For academic use only


\RequirePackage{scrlfile}
\PreventPackageFromLoading[\typeout{Please don't do this for journal submission}]{natbib}
\documentclass{elsarticle}
\expandafter\let\csname c@author\endcsname=\relax
\usepackage[
    backend=biber,
    style=authoryear,
]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{aristotle:physics}

\printbibliography
\end{document}
  • This breaks with the ´3p´ or ´5p´ options to ´elsarticle´. Any suggestions? – flindeberg Nov 27 '17 at 20:19
  • 1
    @flindeberg Considering the warnings, i would recommend not to use stuff like that. – Johannes_B Nov 28 '17 at 4:13
  • 1
    I'm not questioning the stupidity of doing it, I'm asking how to do it. Anyhow I solved it, and will link when I'm at a computer again. – flindeberg Nov 28 '17 at 11:33
  • Hi @flindeberg, Could you give us a clue how you solved it? Since the logos do not found: elsevier-logo-0p, SDlogo-0p, I tried to put this name's file in my directory, but my title is not aligned. – Oromion Jun 21 '18 at 4:07
  • @Oromion Added an answer, hope it solves the issues. If not just comment on my answer! – flindeberg Jun 21 '18 at 9:42
3

@Oromion asked how I solved it for 3p and 5p so putting an MWE here. Do note that this is not for publications, and I did it after a couple of students requested help since they had been asked to write an "Elsevier style paper" for a course.

\documentclass[5p]{elsarticle}

%% Fix so biblatex works instead of natbib
\makeatletter
\let\c@author\relax
\makeatother
\let\bibhang\relax
\let\citename\relax
\let\bibfont\relax
\let\Citeauthor\relax
\expandafter\let\csname ver@natbib.sty\endcsname\relax

%% Fix headers and footers
\makeatletter
\def\ps@pprintTitle{%
    \let\@oddhead\@empty
    \let\@evenhead\@empty
    \def\@oddfoot{}%
    \let\@evenfoot\@oddfoot}
\makeatother

%% Load some packages and stuff

%% Library and stuff
\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
%% biblatex with apa-style.
\DeclareLanguageMapping{american}{american-apa}
\bibliography{library}

%% Rest as usual....
  • Please Is there any other options to achieve that for publications? – CS Student May 2 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.