# How to understand the LaTeX warning “there were undefined references”?

I am running this LaTeX file through pdflatex and getting these warnings:

latex warning: there were undefined references.
latex warning: label(s) may have changed. Rerun to get cross-reference right.

and also some more warnings like this:

latex warning: reference 'lastpage' on page 76 undefined on input line 3200.

on every page end.

My LaTeX file is like this

\documentclass[a4paper,leqno,twoside]{article}

\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{multirow}

\renewcommand{\familydefault}{\sfdefault}

\usepackage{color}
\usepackage{draftwatermark}
\SetWatermarkText{EXPERIMENTAL}
\SetWatermarkScale{0.6}
\usepackage{parskip}

\graphicspath{{Figure/}}

\let\oldsection\section
\renewcommand{\section}{\clearpage\oldsection}
\begin{document}

% Issued by {Name, acronym, department, phone}
\issuedby{vrebwr}
% Checked by
\checkedby{-}
% Approved by
\approvedby{-}
% Document title. Use \doctitleShort{} to insert a shorter title in the header.
\doctitle{test numbers with id}
\doctitleShort{document for tests}
% Publish date
\publishdate{\today}

% Titlepage
\frontmatter % Should be on first page
\maketitle

\vspace*{08eX}
\begin{center}
\subsection*{Abstract}
\end{center}

\noindent
\newpage
\mainmatter
% Main pages. This command should be on page 2 or later.
\phantom{phantom}
\cleardoublepage

\subsection*{Change Record}

\begin{itemize}
\item R.1: Initial version.
\begin{itemize}
\item  generation of documentation using the vrebwr
\end{itemize}
\end{itemize}

\cleardoublepage

\setcounter{tocdepth}{2}
\tableofcontents

\cleardoublepage

\section{ How to read the tset information}

\begin{enumerate}
\item information of tests
\end{enumerate}

\section{test numbers}

\subsection*{1, temperature sensor. }
\subsubsection*{data}
some data regarding test where we performed
\subsubsection*{values}
temperature sensor value here three or more.
\subsubsection*{reason}
why we get like this.
\newpage

\subsection*{2, humidity sensor. }
\subsubsection*{data}
some data regarding test where we performed
\subsubsection*{values}
humidity sensor value here three or more.
\subsubsection*{reason}
why we get like this.

\subsection*{3, pressure sensor. }
\subsubsection*{data}
some data regarding test where we performed
\subsubsection*{values}
pressure sensor value here three or more.
\subsubsection*{reason}
why we get like this.
\newpage
\end{document}


In the above LaTeX file I have around 100 tests. I used the * symbol to eliminate numbering in subsections, because I am using test names with number so there is no need to add numbering. It looks bad in the PDF, so I tried to add that test name and number in table of contents by using this command:

\addcontentsline{toc}{subsection}{1,temperature sensor.}


When I used this command I am getting errors like as I explained above. I searched and I found some reasons why this error occurred, because of \label{} and \ref{} is not used like that. But I don't know how to use that in my file. Can anyone help me with it?

-

## migrated from stackoverflow.comNov 15 '11 at 15:30

This question came from our site for professional and enthusiast programmers.

Oops, I started editing the title but forgot to finish before I migrated it. Sorry about that. –  Michael Myers Nov 15 '11 at 15:31
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Torbjørn T. Nov 15 '11 at 15:34
how to rectify that warning. –  pavani Nov 15 '11 at 15:52
Getting a warning about undefined references after the first latex run is nothing to worry about; just rerun latex once or twice more, and all cross-references should be resolved (including the one to lastpage). On the other hand, if you have typos in your labels and/or your cross-referencing commands, the warnings are useful because they tell you so something is amiss and needs to be corrected. –  Mico Nov 15 '11 at 16:07
If all your subsections and subsubsections are to be unnumbered, you could add \setcounter{secnumdepth}{1} to your preamble to turn off numbering for these. subsections will still be added to the TOC, without numbering. That will save you the \addcontentslines. –  Torbjørn T. Nov 15 '11 at 18:30

Getting a warning about undefined references after the first LaTeX run is nothing to worry about. Just rerun LaTeX once or twice more and all cross-references should be resolved (including the one to lastpage).

On the other hand, if you have typos in your labels and/or in your cross-referencing commands, the warnings won't go away upon recompiling the code once or twice more. At that state, they become useful because they tell you something is amiss and needs to be corrected.

-
17 April 2013: The 10th upvote of this answer got me my 200th "badge" on this fabulous site. Many thanks!! –  Mico Apr 19 '13 at 22:23

Placement of the label can also be an issue. For instance, in my case I had the following structure, and I couldn't correctly reference fig:2F43 with this:

\begin{figure*}
\label{fig:2F43} %This is bad, labels should always appear after captions.
\centering
\includegraphics[clip=true,trim=0cm 0cm 0cm 0cm, width=12cm]{2F43}
\caption{Illustration of the $F_1$ part of the ATP Synthase complex
(PDB ID 1E79; \citealt{Gibbons2000,Bernstein1978,Gezelter}).
TEXT TEXT  TEXT TEXT  TEXT TEXT  TEXT TEXT  TEXT TEXT
}
%\label{fig:2F43} <-- Should actually be here
\end{figure*}


The reason this is so is because \label takes an argument, which is typically generated by some other command (e.g. \caption or \section). More discussion is available at Why does an environment's label have to appear after the caption?.

-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. This does not really answer the question. Also, see here for why \label must always follow \caption. –  Paul Gessler Feb 26 '14 at 23:03
Thanks and double thanks, I updated it to be more reasonable I believe. –  bbarker Feb 27 '14 at 0:06
No the format is better; but still not really an answer to the question. –  zunbeltz Feb 27 '14 at 8:12
I would contend that this is an answer to the question 'How to understand the LaTeX warning “there were undefined references”?'. It is a question that can have multiple answers, due to the same error message having multiple causes. It is not an exact answer to the problem that is fully described. Is that the only acceptable route to answers on TeX.SX? –  bbarker Feb 27 '14 at 16:07

I'd go the extra mile to define your own commands to typeset each of the tests. Better documentation in the source, gives flexibility for later changes (redefine the commands involved to change format or such).

-