4

The following is a minimum working example on Overleaf. The below code works as expected, and gives the correct output:

\documentclass[8pt]{article}
%\documentclass[final,5p,times,twocolumn,number,sort&compress]{elsarticle}
\usepackage[utf8]{inputenc}   
\usepackage[labeled,resetlabels]{multibib}
\newcites{G}{Good references}
\newcites{B}{Bad references}

\begin{document} These are normal references \cite{johnjane}. The special references are \citeG{goodbook} and \citeB{badbook}.

\bibliographystyle{plain} \bibliography{normalref.bib} \bibliographystyleG{plain} \bibliographyG{goodref.bib} \bibliographystyleB{plain} \bibliographyB{badref.bib}

\begin{filecontents}{normalref.bib} @inproceedings{ johnjane, title={Cinderella}, author={Doe, John and Doe, Jane}, booktitle={Bedtime stories}, pages={200}, year={2020} } \end{filecontents}

\begin{filecontents}{goodref.bib} @inproceedings{ goodbook, title={How to hack?}, author = {Monkey Luffy}, booktitle={Ethical hacking}, pages={36--40}, year={2015} } \end{filecontents}

\begin{filecontents}{badref.bib} @inproceedings{ badbook, title={How to hack?}, author={Blackbeard}, booktitle={Unethical hacking}, pages={36--40}, year={2015} } \end{filecontents} \end{document}

Correct output with the usage of multibib:

Expected output

When I use the elsarticle class instead of the article class, i.e., when I comment out the first line and uncomment the second line in the above code, the output is not as expected.

Wrong output when using elsarticle class file (which is apparently provided by Overleaf):

This is not the expected output

Can someone help me get the correct output when using the elsarticle class file? As mentioned, my code is on Overleaf.

imnothere
  • 14,215
ap123
  • 43
  • 2
    elsarticle uses natbib. See https://tex.stackexchange.com/a/471427/226 but you'll have to replace \citeO, \oldCiteO with \citeG, \citeB, \oldciteG, \oldciteB to suit your own purposes. – imnothere Oct 03 '20 at 02:26

1 Answers1

4

elsarticle uses natbib; so see Natbib-Multibib problem with prefix labels.

As you're using Overleaf, the accepted answer for that question might not be applicable for you as you won't be able to edit the .aux files. You might try with the approach in https://tex.stackexchange.com/a/471427/226, but you'll have to replace \citeO, \oldCiteO with \citeG, \citeB, \oldciteG, \oldciteB to suit your own purposes.

\usepackage{xparse}
\let\oriCiteG\citeG
\let\oriCiteB\citeB

%% The O{} in this re-definition means "an optional argument %% with an empty default value"; m is a mandatory argument. \RenewDocumentCommand{\citeG}{O{} O{} m}{% \renewcommand{\citenumfont}[1]{G##1}%
\oriCiteG[#1][#2]{#3}% \renewcommand{\citenumfont}[1]{##1}% }

\RenewDocumentCommand{\citeB}{O{} O{} m}{% \renewcommand{\citenumfont}[1]{B##1}%
\oriCiteB[#1][#2]{#3}% \renewcommand{\citenumfont}[1]{##1}% }

Same disclaimers apply: I'm not entirely sure if this breaks any other natbib behavior, so try with care!

imnothere
  • 14,215