2

So my problem is that there seams to be a clash between something in my preamble and the \label{} and \ref{} commands. When I do references within my definition environment it all goes smoothly, but whenever I try to label something within an equation environment, the reference becomes undefined, regardless of whether the equation is located within a definition/theorem environment or just within the document.

Here is my preamble along with an example:

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{paralist}
\usepackage{fancyhdr}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{mathtools}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[framed, thmmarks, standard]{ntheorem}
\usepackage{framed}
\usepackage{pstricks}

\pagestyle{fancy}
\fancyhf{}
\rfoot{page \thepage}
\renewcommand{\headrulewidth}{0pt}

\numberwithin{equation}{section}

\definecolor{lightgray}{gray}{0.94}

\theoremseparator{:}
\theoremstyle{nonumberplain}
\theoremheaderfont{\itshape}
\theorembodyfont{\normalfont}
\theoremsymbol{\nolinebreak[1]\hspace*{.5em plus 1fill}\ensuremath{\Box}}
\newtheorem{myproof}{Proof}

\theoremstyle{break}
\theoremheaderfont{\normalfont\bfseries}\theorembodyfont{\slshape}
\theoremseparator{}
\theoremsymbol{}
\shadecolor{lightgray}
\newshadedtheorem{thm}{Theorem}[section]

\theoremstyle{break}
\theoremheaderfont{\normalfont\bfseries}\theorembodyfont{\slshape}
\theoremseparator{}
\theoremsymbol{}
\shadecolor{lightgray}
\newshadedtheorem{mydef}{Definition}[section]

\begin{document}

\section{First section}

\begin{mydef}[Something]
\label{def:something}
We will now define something. It has a property:
\begin{equation}
\label{eq:first}
x+y=z
\end{equation}
\end{mydef}

Now I want to reference it. according to definition 
\ref{def:something} we have.. 
If we look at equation \ref{eq:first}...

Also we have another equation:
\begin{equation}
\label{eq:second}
z>0
\end{equation}

I also want to talk about equation \ref{eq:second}

\end{document}

Can anybody see where the issue might be? Thanks in advance.

2

According to the documentation of ntheorem, section 3.2.1, you should add the option amsmath together with thmmarks if you load the amsmath package:

\usepackage[amsmath,thmmarks]{ntheorem}

Full example:

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{paralist}
\usepackage{fancyhdr}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{mathtools}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[amsmath,framed, thmmarks, standard]{ntheorem}
\usepackage{framed}
\usepackage{pstricks}

\pagestyle{fancy}
\fancyhf{}
\rfoot{page \thepage}
\renewcommand{\headrulewidth}{0pt}

\numberwithin{equation}{section}

\definecolor{lightgray}{gray}{0.94}

\theoremseparator{:}
\theoremstyle{nonumberplain}
\theoremheaderfont{\itshape}
\theorembodyfont{\normalfont}
\theoremsymbol{\nolinebreak[1]\hspace*{.5em plus 1fill}\ensuremath{\Box}}
\newtheorem{myproof}{Proof}

\theoremstyle{break}
\theoremheaderfont{\normalfont\bfseries}\theorembodyfont{\slshape}
\theoremseparator{}
\theoremsymbol{}
\shadecolor{lightgray}
\newshadedtheorem{thm}{Theorem}[section]

\theoremstyle{break}
\theoremheaderfont{\normalfont\bfseries}\theorembodyfont{\slshape}
\theoremseparator{}
\theoremsymbol{}
\shadecolor{lightgray}
\newshadedtheorem{mydef}{Definition}[section]

\begin{document}

\section{First section}

\begin{mydef}[Something]
\label{def:something}
We will now define something. It has a property:
\begin{equation}
\label{eq:first}
x+y=z
\end{equation}
\end{mydef}

Now I want to reference it. according to definition 
\ref{def:something} we have.. 
If we look at equation \ref{eq:first}...

Also we have another equation:
\begin{equation}
\label{eq:second}
z>0
\end{equation}

I also want to talk about equation \ref{eq:second}

\end{document}

enter image description here

  • Btw. totally unrelated, but how do you make it render the output in tex? – Erik Olesen Jul 4 '15 at 17:42
  • @ErikOlesen I take a snapshot of the screen and upload it. – egreg Jul 4 '15 at 17:46
  • Right sure. Grazie mille :) – Erik Olesen Jul 4 '15 at 17:50
2

Using a more simplified example you can see it's the thmmarks option that causes the problem

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}


\usepackage{amsmath}

\usepackage
%[thmmarks]
{ntheorem}

\numberwithin{equation}{section}

\newtheorem{mydef}{Definition}[section]

\begin{document}

\section{First section}

\begin{mydef}[Something]
\label{def:something}
We will now define something. It has a property:
\begin{equation}
\label{eq:first}
x+y=z
\end{equation}
\end{mydef}

Now I want to reference it. according to definition 
\ref{def:something} we have.. 
If we look at equation \ref{eq:first}...

Also we have another equation:
\begin{equation}
\label{eq:second}
z>0
\end{equation}

I also want to talk about equation \ref{eq:second}

\end{document}

Haven't traced exactly where the label goes yet, it doesn't get written to the aux file at all if that option is used.

  • we ran into a superficially related problem today in an article for an ams journal. the \ref was inside an equation, and although the label was in the aux file, the \ref would always come out as ??. we finally packed the \ref in an \mbox (\hbox and \text also worked) and it was resolved. not the same thing, since in the present case the \label is getting "lost" rather than just not being seen, but worth remembering. i think the problem here may be similar to what happens to footnote texts in section headings. – barbara beeton Jul 3 '15 at 20:05

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.