[Tex/LaTex] elsarticle error: You can’t pop an empty literal stack for entry

bibtexelsarticle

Consider the input

\documentclass{elsarticle}%%% V3.1 from CTAN
\usepackage{hyperref}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{MITRE-CWE-ConcurrencyIssues,
  author = {{The {MITRE} corporation}},
  title = {{CWE} category: concurrency issues},
  year = 2017,
  month = may,
  note={\url{http://cwe.mitre.org/data/definitions/557.html}}
}
\end{filecontents}
\bibliographystyle{elsarticle-num}%%% Version 2.1 from http://mirrors.ctan.org/macros/latex/contrib/elsarticle/elsarticle-num.bst
\begin{document}
\cite{MITRE-CWE-ConcurrencyIssues}
\bibliography{\jobname}
\end{document}

Running the usual pdflatex-bibtex loop on it produces an error message:

You can't pop an empty literal stack for entry MITRE-CWE-ConcurrencyIssues
while executing---line 1499 of file elsarticle-num.bst
ptr=1, stack=
 (May 2017)
---the literal stack isn't empty for entry MITRE-CWE-ConcurrencyIssues
while executing---line 1499 of file elsarticle-num.bst

Bibtex does its job but returns error code 2, which prevents further automatic processing. Is there any error in the input, in bibtex or in the .bst file? In the latter case, how to repair elsarticle-num.bst?

Best Answer

It looks like there is a duplicate line in elsarticle-num.bst which is trying to use an item from the stack which isn't there anymore. I think that the function misc (line 1360 of elsarticle-num.bst), which looks like this:

FUNCTION {misc}
{ output.bibitem
  format.authors output
  title empty$ 'skip$ 'setup.inlinelink if$ % urlbst
  format.title output
  howpublished output
  format.note output
    format.date "year" output.check
  fin.entry
    format.date "year" output.check
  write.url
  empty.misc.check
}

should have the second format.date "year" output.check removed:

FUNCTION {misc}
{ output.bibitem
  format.authors output
  title empty$ 'skip$ 'setup.inlinelink if$ % urlbst
  format.title output
  howpublished output
  format.note output
    format.date "year" output.check
  fin.entry
%    format.date "year" output.check <-- Remove/comment this
  write.url
  empty.misc.check
}
Related Question