# Error with splitbib and natbib : Undefined control sequence

I am using {natbib} package for the bibliography style and {splitbib} package for separate my bibiography into categories at the end of my documents, for example : all articles in one group, all the books in an other group.

The author of {splitbib} advised to use the [export] argument when usign {natbib} package.

Everything is working, I have my final document as I wanted but the problem is that I get an error message from LaTeX : "Undefined control sequence \begin{thebibliography}"

If I don't use {natbib} package, I don't have any error. If I use {natbib} package without [export] argument it is worth. If I use {natbib} package with [export] argument it works but with an error message.

How can I solve this ?

Thank you

Here is an example :

\documentclass[a4paper,12pt]{book}

\usepackage[comma,longnamesfirst]{natbib}
\bibliographystyle{plainnat}
\usepackage[export]{splitbib}

\begin{category}{Articles}
\SBentries{Article1,Article2}
\end{category}
\begin{category}{Books}
\SBentries{Book1,Book2}
\end{category}

\usepackage{filecontents}

\begin{filecontents}{bibliography.bib}

@article{Article1,
author={Jhon Doe},
title={Blabla},
journal={Blabla},
year={2019},
volume={145},
number={4},
pages={1-25}
}
@book{Book2,
author={Fabrice Doe},
title={Blabla4},
journal={Blabla4},
year={2016},
volume={142},
pages={4-22}
}
\end{filecontents}

\begin{document}

I want to cite Article1~\cite{Article1} and then Book2~\cite{Book2}.

\bibliography{bibliography}

\end{document}


The undefined command is not \begin{bibliography} but \SBlongestlabel:

! Undefined control sequence.
\thebibliography ...\expandafter {\SBlongestlabel
} \immediate \write \NMSB@...
l.1 \begin{thebibliography}{2}


It is clearly a bug in the package, but it is not completly clear what the author intended.

The following patch could work:

\documentclass[a4paper,12pt]{book}

\usepackage[comma,longnamesfirst]{natbib}
\bibliographystyle{plainnat}
\usepackage[export]{splitbib}

\begin{category}{Articles}
\SBentries{Article1,Article2}
\end{category}
\begin{category}{Books}
\SBentries{Book1,Book2}
\end{category}

\usepackage{filecontents}

\begin{filecontents}{bibliography.bib}

@article{Article1,
author={Jhon Doe},
title={Blabla},
journal={Blabla},
year={2019},
volume={145},
number={4},
pages={1-25}
}
@book{Book2,
author={Fabrice Doe},
title={Blabla4},
journal={Blabla4},
year={2016},
volume={142},
pages={4-22}
}
\end{filecontents}
\makeatletter
\usepackage{xpatch}
\xpatchcmd\thebibliography
{\expandafter\NMSB@tok\expandafter{\SBlongestlabel}}
{\@ifundefined{SBlongestlabel}{\NMSB@tok{}}{\expandafter\NMSB@tok\expandafter{\SBlongestlabel}}}
{}{\fail}
\makeatother
\begin{document}

I want to cite Article1~\cite{Article1} and then Book2~\cite{Book2}.

\bibliography{bibliography}

\end{document}

• It works ! thank you very much. Finally what did you add ? You force the program to not display the error ? Aug 8 '19 at 15:20