2

Continuing resolving the misc entry in https://tex.stackexchange.com/a/482872, let's conside the input

\documentclass{elsarticle}%% V3.1 from https://ctan.org/tex-archive/macros/latex/contrib/elsarticle
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{LevesonTurner-InvestigationOfTheTherac25Accidents,
  author    = {Nancy Gail Leveson and Clark Savage Turner},
  title     = {Investigation of the {Therac}-25 accidents},
  journal   = {{IEEE} Computer},
  volume    = 26,
  number    = 7,
  pages     = {18--41},
  year      = 1993
}
\end{filecontents}
\bibliographystyle{elsarticle-num}%%% V2.1 From https://ctan.org/tex-archive/macros/latex/contrib/elsarticle
\begin{document}
\cite{LevesonTurner-InvestigationOfTheTherac25Accidents}
\bibliography{\jobname}
\end{document}

Running the standard pdflatex-bibtex loop on it produces the year (1993) twice:year twice

When I look at the style file around line 1177, I see that the year is being processed only once:

FUNCTION {article}
{ output.bibitem
  format.authors "author" output.check
  title empty$ 'skip$ 'setup.inlinelink if$ % urlbst
  format.title "title" output.check
  crossref missing$
    { journal
      "journal" output.check
      % add.blank
  before.all 'output.state :=
      format.vol.num.pages output
    }
    { format.article.crossref output.nonnull
      format.pages output
    }
  if$
  format.journal.pages
  format.note output
    format.date "year" output.check
  fin.entry
  write.url
}

I don't see what's wrong. Any bugfix?

  • 1
    This one, I think, is in the format.journal.pages function which contains a call to format.year, for some reason. If you comment that whole line (804) the extra year disappears. I'm not sure what this will do to other entry types, though... Hm... It looks like format.journal.pages is only used by article, so I think it's safe to remove that line... This style is really annoying you :) – Phelype Oleinik Apr 3 at 0:08
  • Good point! I added an answer addressing that as well. However, I didn't find what prints the year twice in @book and @inproceedings... – Phelype Oleinik Apr 3 at 0:23
1

Directly, from the article function, the year is indeed processed only once. However, the format.journal.pages function (called by article) does this for some reason. The function looks like this (it's on line 797 of elsarticle-num.bst):

FUNCTION {format.journal.pages}
{ pages empty$
    'skip$
    { duplicate$ empty$
        { pop$ format.pages }
        {
          " " *
          format.year * " " * % <-- This guy here
          pages n.dashify *
        }
      if$
    }
  if$
}

In the normal case, of the pages entry being present, the code does adds a space (" " *), the year followed by another space for some reason (format.year * " " *), and only then the pages (pages n.dashify *). So if you comment out the line that adds the year and a space you'll have only <space> pages.

Answering your comment, I'd comment out this instance of year because:

  1. It's in the format.journal.pages function, so it's semantically in the wrong place, so the code is clumsy. You saw it yourself :)

  2. Most other entry types end with:

    format.note output
      format.date "year" output.check
    fin.entry
    write.url
    

    so the year is the last thing before the URL. It would look odd if only the article type had a different convention; and

  3. If the pages entry was not given, BibTeX wouldn't reach that branch of the conditional, and the year would “mysteriously” disappear.

  • @user49915 I focused the answer on leaving the year at the end because all other entries do so. However, if you like the year before the pages you can (still commenting out line 804) move the format.date "year" output.check above the line that deals with the pages entry in all entry types. You'd be overriding much of the style's definitions, so using it would sort of lose the purpose. My advice: if you'll send the manuscript to Elsevier, don't bother with the style because they will format everything in their own way. If you're not sending to Elsevier, use another style :) – Phelype Oleinik Apr 3 at 0:44
  • 1
    @user49915 Possibly, yes :) As I said you're overriding much of the style, so further changes to adequate the style to that would be needed. And programming a consistent bst file isn't an easy task (if you're interested, take a look at Tame the BeaST, it's an excellent start). However, at this point you would probably need to change the name of the style to something else entirely, so it's probably easier to just drop it. And if the reviewers resort to nitpicking on your bibliography formatting your article is probably good enough for publishing ;) – Phelype Oleinik Apr 3 at 0:52

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.