2

Whenever I try and label an equation in the following format

\begin{equation}\label{eq:blah}
blah
\end{equation}

and then reference this equation

By \eqref{eq:blah}

I get the usual (??) of an ill-defined labeling. It only happens with equation environments though.

I've tried removing almost everything I can think of in my preamble to make it work, but to no avail.

Consequently, I am posting a MWE which is not very minimal—apologies!

Any help is greatly appreciated!

\documentclass{book} 

\usepackage{amsfonts,amssymb,latexsym,verbatim,url,color,mathrsfs,tikz,extarrows,enumerate,lipsum,mathtools}
\usepackage[nameinlink]{cleveref}
\usepackage{enumerate,fancyhdr,verbatim,comment}

\usepackage{dsfont}


\usetikzlibrary{matrix,arrows}


\usepackage[colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}




\usepackage[amsmath,thmmarks]{ntheorem}

\newcounter{dummy} 
\numberwithin{dummy}{chapter}



\theoremprework{\setlength
\theorempreskipamount{10 pt}\setlength\theorempostskipamount{10 pt}}

\theoremstyle{plain}
\theorembodyfont{\upshape}
\theoremsymbol{}
\theoremseparator{:}
\newtheorem{example}[dummy]{Example}



\begin{document}

\begin{equation}\label{eq:example}
\int_a^b f(x)\, dx=F(b)-F(a)
\end{equation}

By Equation \eqref{eq:example}

\end{document}

New MWE:

\documentclass{book} 

\usepackage{amsfonts,amsmath,amssymb,latexsym,verbatim,url,color,mathrsfs,tikz,extarrows,enumerate,lipsum,mathtools}

\usepackage{enumerate,fancyhdr,verbatim,comment}

\usepackage{dsfont}


\usepackage[margin=1 in]{geometry}


\usetikzlibrary{matrix,arrows}

\usepackage[amsmath,thmmarks]{ntheorem}

\usepackage[colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}

\usepackage[nameinlink]{cleveref}
 \newcounter{dummy} 
    \numberwithin{dummy}{chapter}



    \theoremprework{\setlength
    \theorempreskipamount{10 pt}\setlength\theorempostskipamount{10 pt}}

    \theoremstyle{plain}
    \theorembodyfont{\upshape}
    \theoremsymbol{}
    \theoremseparator{:}
    \newtheorem{example}[dummy]{Example}



    \begin{document}

    \begin{equation}\label{eq:example}
    \int_a^b f(x)\, dx=F(b)-F(a)
    \end{equation}

    By Equation \eqref{eq:example}

    \end{document}
  • The packages are loaded in the wrong order: load all of them before hyperref except cleveref which must be last. – egreg Nov 30 '15 at 07:47
  • @egreg Thanks! It didn't actually seem to fix anything though. :( I have edited the above with how I interpreted your statement (plus what I read in the linked post). Am I doing something wrong still? – Alex Youcis Nov 30 '15 at 08:09
  • @egreg Nope, I figured it out. Thanks so much!! – Alex Youcis Nov 30 '15 at 08:11
  • Indeed this not a duplicate of the linked question. You need to pass the amsmath option to thmtools. – Andrew Swann Nov 30 '15 at 09:04
  • Do you really need all those packages? Some of them are loaded twice. As I see, problematic are two of them: extarrows and comment. Both are not connected to the problem which you indicate in the question title. – Zarko Nov 30 '15 at 10:32
  • @AndrewSwann Hadn't I already done this? This was one of the things I found when googling this problem, but I thought that \usepackage[amsmath,thmmarks]{ntheorem} fixes the problem? – Alex Youcis Nov 30 '15 at 10:50
  • @Zarko To be honest, I don't know. I am, unfortunately, a very utilitarian user of LaTeX. Much of my preamble is copy and pasted from document to document, and came as part of some code someone else sent me, or that I copied from the internet. Why are the two you mentioned problematic? Thanks for the advice! – Alex Youcis Nov 30 '15 at 10:51
  • @AlexYoucis, I will make an answer, by which I will show, that your MWE in case that you omit mentioned packages work. – Zarko Nov 30 '15 at 11:02
  • Your first code has the amsmath option, your second doesn't – Andrew Swann Nov 30 '15 at 11:03
  • @AndrewSwann Oh, sorry! That was an issue in transcription. I'll fix that in an edit. Thanks! – Alex Youcis Nov 30 '15 at 11:03
  • Well now you have added an option amsthm, but the one you need is amsmath. – Andrew Swann Nov 30 '15 at 11:10
  • @AndrewSwann It's 3:14—i.e. another transcription error. :) Thanks again! – Alex Youcis Nov 30 '15 at 11:14
  • Since the final MWE works flawlessly with TeX Live from 2012 to the most recent 2015, I'm voting this as off-topic. The first MWE is wrong in that it loads ntheorem after hyperref (it should go before it) and cleveref before hyperref (it should go after it). – egreg Dec 30 '15 at 14:21

1 Answers1

2

As I mentioned in my comment, problematic are packages axtarrows and comment. They cause errors even if ntheorem as well as equation with referencing is not presented. Both clashes also with some other packages, what I didn't further investigate. Do you really need those packages in your text?

I suggest to load your packages in grops with similar use (math, etc). I made this according to my taste/habits. So, after this the code of your MWE is:

\documentclass{book}
    \usepackage{mathtools,amssymb,latexsym,
                color,mathrsfs}
    % amsfont is load by amsmath and amsmath by maththools
    % url is also part of hypperref package, no need to be loaded
    % verbatim enumerate are loaded twice
    % extarrows make troubles, I suggest to omit it, most its functionality is achievable by mathtools
    % tikz and lipsum I moved in new group of packages

    \usepackage{enumerate,fancyhdr,verbatim}
    % comment make troubles, in all my needs is sufficient to use \begin{comment} ... \end{comment} from verbatim package
     \usepackage{lipsum}% produce dummy text

     \usepackage{dsfont}
     \usepackage[margin=1 in]{geometry}

     \usepackage{tikz}% for drawing pictures
\usetikzlibrary{matrix,arrows}

    \usepackage[amsmath,thmmarks]{ntheorem}
\newcounter{dummy}
    \numberwithin{dummy}{chapter}

    \theoremprework{\setlength
    \theorempreskipamount{10 pt}\setlength\theorempostskipamount{10 pt}}

    \theoremstyle{plain}
    \theorembodyfont{\upshape}
    \theoremsymbol{$\square$}% you not use a symbol for end of example
    \theoremseparator{:}
    \newtheorem{example}[dummy]{Example}

    \usepackage[colorlinks = true,
                linkcolor = blue,
                urlcolor  = blue,
                citecolor = blue,
                anchorcolor = blue]{hyperref}
    \usepackage[nameinlink]{cleveref}

    \begin{document}

    \begin{equation}\label{eq:1}
\int_a^b f(x)\, dx=F(b)-F(a)
    \end{equation}
By Equation \eqref{eq:1} \dots
\begin{example}
Let explain \eqref{eq:1} with \dots
    \begin{equation}\label{eq:2}
\int_a^b f(x)\, \mathrm{d}x = F(b)-F(a)
    \end{equation}
\end{example}
Regarding \eqref{eq:2} \dots
    \end{document}

With above MWE I haven't any problem when I compile it:

enter image description here

Zarko
  • 296,517