0

I have the following problem with unsrtnat not following the order of appearance in the document (sort of):

The document is split in several sub-documents. In the main part, a usual .bib file is included as well as citations.

In between a number of sub-documents are included using \import; each has their own share of citations that are added to the main bibliography using

\AtEndEnvironment{thebibliography}{
\bibitem{example}
....
}

The result is, if the main document is structured like

A(main)
B(included)
C(main)

That citations are numbered in the order of appearance following ACB instead of ABC.

Any suggestions?

Edit: Minimal working example, main file

\documentclass{article}
\usepackage{etoolbox}
\bibliographystyle{unsrtnat}
\begin{document}

Example\cite{A}.
\input{sub}
Example\cite{C}.

\bibliographystyle{unsrtnat}
\begin{thebibliography}{1}
\bibitem{A}
This should be the first.
\bibitem{C}
This should be the third.

\end{thebibliography}
\end{document}

And sub-file:

Example\cite{B}.
\AtEndEnvironment{thebibliography}{
\bibitem{B}
This should be the second.
}
  • 1
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Heiko Oberdiek Feb 14 '17 at 10:52
  • May I enquire why you are using \import? I never used that command, and do not know if it may be responsible for the problem. Can you use \input or \include instead, and does the problem persist in that case? Compare here. – Manuel Weinkauf Feb 14 '17 at 10:56
  • 1
    why are you adding to the bibliography like that rather than let bibtex just handle all the \cite as normal? – David Carlisle Feb 14 '17 at 11:11
  • Thanks for first round of feedback. Problem persists with with input and include; above is a minimal working example. I want to include the citations that way because the main file uses a .bib file and the sub-file is an older part that has just a bunch of bib-entries directly written in the document. Alternative approaches are also welcome :) – SelfEnergy Feb 14 '17 at 11:21
  • I agree with @DavidCarlisle, the \AtEndEnvironment may cause the problem. And I do not see a reason why it should be neccessary. A simple \cite{B} in the sub-file should suffice. – Manuel Weinkauf Feb 14 '17 at 11:24
1

Why not use this:

\documentclass{article}
\usepackage{etoolbox}
\begin{document}

Example\cite{A}.
\input{sub}
Example\cite{C}.

\bibliographystyle{unsrtnat}
\bibliography{Lit} %name of your .bib file
\end{document}

With sub-file

Example\cite{B}.

Does that somehow not produce what you want/expect?

Also note, that you call \bibliographystyle{unsrtnat} twice!

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.