This issue actually frustrates me for a while, but prior for finding the solution, I would like to know why this happens. In a nutshell: My TeXStudio does recognise ALL my \label, but the output does not recognise some labels.
Problem
I am writing my notes on Physics, however, sometimes I got warnings of:
LaTeX Warning: Reference `eq:pointcd' on page 196 undefined on input line 985.
This is just for example, I have other examples in the document that does not have \label recognised. There are also some weird situation where I have the same format of putting \label, but got recognised by the compiler.
MWE
\documentclass[12pt,a4paper,headinclude,openright]{scrbook}
\usepackage{amsmath}
\usepackage{amssymb}
% ------------here comes the problem part------------
\usepackage[listings,theorems,skins,breakable]{tcolorbox}
\tcbuselibrary{breakable}
%======================== Ch.4 boxes =========================
\tcbset{exercisestyle04/.style={arc=0.5mm,coltitle=black,fonttitle=\sffamily\bfseries,colback=color04!50!,colframe=color04}}
\newtcolorbox[auto counter,number within=chapter,list inside=eg]%
{exercise04}[2][]{exercisestyle04,
title={Exercise ~\thetcbcounter: #2}}
\tcbuselibrary{theorems}
\usepackage[amsthm,thmmarks,hyperref]{ntheorem}
% theorem
\usepackage{regexpatch}
\makeatletter
\xpatchcmd*{\thm@@thmline@name}{2.3em}{5em}{}{}
\xpatchcmd*{\thm@@thmline@noname}{2.3em}{5em}{}{}
\makeatother
\makeatletter
\renewtheoremstyle{plain}%
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2 \theorem@separator]}%
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ \sffamily{##3} \theorem@separator]}
\makeatother
\theoremstyle{plain}
\theorembodyfont{\normalfont\sffamily}
\theoremheaderfont{\bfseries}
\newtheorem{theorem}{Theorem}[section]
% ------------here ends the problem part------------
\begin{document}
\begin{equation}
\rho\left(\mathbf{r}\right)\;=\;\sum_{k=1}^{N}\: q_k \delta\left(\mathbf{r}\;-\;\mathbf{r}_k\right)
\label{eq:pointcd}
\end{equation}
However, one should alert for the unphysical divergence in other quantities associated with \eqref{eq:pointcd}.
\end{document}
In your answer...
I am not specifying you of how to answer this question, this section is just my suspects on the issue. For example,
The pdf compiler is faulty? (I use Acrobat XI and withPdfLaTeXas compiler and usingDVI -> PS -> PDF chainin TeXStudio)My compiling procedures has done wrongly?My format is done wrong (although I fairly think so because I changed my format according to many sources but no luck).TeXStudio is faulty? (Just a suspect, but did happened with other IDEs before and I am using ver. 2.8.0)- I haven't read the manual carefully? (smile)
It turns out some code has obstructed the PdfLaTeX to recognise some \label.
Update
While I was omitting the parts that I have some idea why it happens, however, it is neither of the five above.
- While I deleted some of the
\frontmatter, by delete a section (see MWE above) become fine to recognise the referencing. - I suspect the part is obstructing the compiler to recognise some
\label.
Solution
See Mico's answer, but I would like to append that it was actually because of
5. I haven't read the manual carefully
pdflatextwice on your document? – Aug 24 '14 at 09:00hyperref. Separately: If I augment your code to insert a cross-reference, I don't experience any problems. Did you maybe have a typo in the\refstatement? – Mico Aug 24 '14 at 09:05\refstatement is there now. – SHY.John Aug 24 '14 at 09:10ntheorem, rather than for any of the reasons discussed in the posting that this is supposed to be a duplicate of. – Mico Aug 24 '14 at 13:02