General"unsrt" bibliography entries not appearing in correct order

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
thomasp
Posts: 6
Joined: Tue Apr 27, 2010 1:57 pm

"unsrt" bibliography entries not appearing in correct order

Post by thomasp »

Hi,

I'm using BibDesk with LaTeX/TeXShop and am having some problems with the "unsrt" bibliography style. Basically the bibliography (\cite{blah}) entries are not being numbered in the correct order.

For example, the first instance of \cite{...} in the .tex file is numbered as reference [2], the second, third & fourth are numbered as [6], [7], [8], the fifth is numbered as [3], etc. The numbered reference [1] appears in an appendix at the end, so should theoretically be the highest number. There seems to be no pattern to this numbering.


My document is made up of a number of different .tex files (each chapter is a different file) pulled together with the \include{...} command. Essentially the order is:

Code: Select all

\include{abstract}
\include{chapter1}   %First lot of referencing occurs here - should start reference [1].
\include{chapter2}
...
\appendix
\include{appendix1}   %Final reference included here, but it's listed as the first

\bibliographystyle{unsrt}
\bibliography{Bib}

Can anyone help get the numbering for references in the correct order? Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: "unsrt" bibliography entries not appearing in correct or

Post by josephwright »

You will need to post an entire example, not just snippets. Almost certainly the reason for the order you see is down to the content of your files.
Joseph Wright
thomasp
Posts: 6
Joined: Tue Apr 27, 2010 1:57 pm

"unsrt" bibliography entries not appearing in correct order

Post by thomasp »

Unfortunately the document cannot be made public at this stage so I cannot post the files in their entirety. I have tried creating an example file using exactly the same formatting, code and files as I have, but this does not reproduce the problem.

The main page for the LaTeX is given below. I have also included the first paragraph of the first chapter to have references in it.

Code: Select all

% !TEX TS-program = pdflatexmk

\documentclass[a4paper,11pt,twoside]{ThesisStyle}

% PREAMBLE STARTS HERE
\include{formatAndDefs}

%\usepackage{harvard}
\usepackage[intoc,prefix]{nomencl}
\usepackage{acronym} % Package to write out acronym definitions on first usage

\usepackage[parfill]{parskip} %Adds a line break instead of just an indent to new paragraphs

\makenomenclature
\RequirePackage{ifthen}
\usepackage{vector}

% Preferred numbering format = 2 numbers
\numberwithin{equation}{chapter}
\numberwithin{figure}{chapter}
\numberwithin{table}{chapter}

% Commands for alignment in tables
\usepackage{array}
\newcolumntype{x}[1]{%
>{\centering\hspace{0pt}}m{#1}}%
\newcolumntype{y}[1]{%
>{\raggedleft\hspace{0pt}}m{#1}}%
\newcolumntype{z}[1]{%
>{\raggedright\hspace{0pt}}m{#1}}%


\usepackage{caption}
\usepackage{verbatim}
% PREAMBLE ENDS HERE

\begin{document}
%\include{Acronyms}

\include{TitlePage}
\pagenumbering{roman}

\include{Abstract}
\dominitoc
\tableofcontents\mtcaddchapter % Update minitoc because TOC has been added to TOC
\listoffigures\mtcaddchapter % Update minitoc because LOF has been added to TOC
\listoftables\mtcaddchapter % Update minitoc because LOT has been added to TOC
\include{Nomenclature}
\cleardoublepage

\mainmatter
\acresetall % Reset acronyms
\include{Intro}
\include{ch2}
\include{ch3}

\appendix
\include{appendix1}
\include{appendix2}

\bibliographystyle{unsrt}
\bibliography{Bib}

\end{document}
"Intro.tex" currently has no text in it, just placement headers. "Ch2.tex" is given below. The first reference shown here is the first reference to appear in the document (when viewed as a PDF), yet it is numbered [2]. The second, third and fourth are numbered [6], [7] and [8].

Code: Select all

\chapter{Chapter 2}
\label{chap:ch2}


Blah blah blah \cite{ref_1}, blah blah blah ref one again \cite{ref_1} and three associated papers:  \cite{ref_2,ref_3,ref_4}. Blah blah \cite{ref_1} was blah blah blah blah.

Blah blah blah \cite{ref_5}.
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

"unsrt" bibliography entries not appearing in correct order

Post by josephwright »

This is not the sort of example we are going to be able to help with. You need to post something here that we can compile: remove the text from your real document, leaving just the references, cut out unnecessary packages, etc. As I say, there there will be something that is causing the behaviour you are seeing but unless we can see what you do to cause it then we can't help.
Joseph Wright
thomasp
Posts: 6
Joined: Tue Apr 27, 2010 1:57 pm

Re: "unsrt" bibliography entries not appearing in correct or

Post by thomasp »

I did exactly as you requested in the above post, creating a duplicate document without any of the words in it, just cite commands, and I couldn't replicate the problem - the references were all in the correct order.

Could this be caused by using the "Copy cite command" option from Bibdesk, and then pasting that into the .tex document? I'm guessing the only way round this now is to go through and manually re-enter each cite command in the document.


If you want I can still upload all the relevant files.
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: "unsrt" bibliography entries not appearing in correct or

Post by josephwright »

Copying citations in only inserts the command \cite{...}, which will be the same typed in or copied. So I very much doubt this is the issue. What I'd suggest you do is cut down your original files a bit at a time. Start with the original (checking you get the problem you describe), then cut out for example all of the graphics. Re-compile, and see if the problem remains. Then cut out something else (perhaps a large block of text). Keep going until you isolate something that seems to cause the issue.
Joseph Wright
thomasp
Posts: 6
Joined: Tue Apr 27, 2010 1:57 pm

Re: "unsrt" bibliography entries not appearing in correct or

Post by thomasp »

I think it must be an error with how BibDesk has copied the citations across (can't think how though, because as you say it should be the same). When I made the "test" file, I renamed the citation references in BibDesk and manually in the .tex files, in order to make it easier to show which order the references should be in. I therefore overwrote all the \cite{...} commands which may have been copied & pasted from BibDesk.

I'll go through and check - going to be a long day!


Thanks for the help. I'll post back here if I manage to solve it or not.
thomasp
Posts: 6
Joined: Tue Apr 27, 2010 1:57 pm

"unsrt" bibliography entries not appearing in correct order

Post by thomasp »

I've managed to fix the problem. I was using the \cite{...} command in captions for figures and tables. Since LaTeX runs the toc builder before it runs BibDesk, this meant that the \cite{...} commands within captions were read before they were read from the main body text.

To overcome this, I used the following alteration to the \caption command:

Code: Select all

\caption[TEXT TO BE DISPLAYED IN TOC]{Text to be displayed under figure/table \cite{...}.}
This now puts the text inside the square brackets in the table of contents, while leaving the citation in the correct place under the figure, and leaves the reference numbering in the correct order within the document. This works with figures, tables and sidewaysfigures.
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: "unsrt" bibliography entries not appearing in correct or

Post by josephwright »

BibDesk has nothing to do with this: \cite commands relate to BibTeX (BibDesk is a front end for managing your references). If you'd said you had some citations in captions, or posted an example showing it, then this could have been resolved more rapidly.
Joseph Wright
thomasp
Posts: 6
Joined: Tue Apr 27, 2010 1:57 pm

Re: "unsrt" bibliography entries not appearing in correct or

Post by thomasp »

I didn't realise it was the citations in the captions that was causing the issues, since the figures appeared after each specific reference had been cited in the body text. I only discovered it when I did as you suggested and remove figures from the files.
Post Reply