12

I have a document organized into several chapters. In each chapter, theorems are numbered by section (1.1, 1.2, ... even in chapter 5). I often would like to refer to theorems in different chapters. However, if I am in chapter 6 and refer to theorem 1.3 in chapter 1, it is rather ambiguous, and the reader might assume that "theorem 1.3" meant the current chapter. Is there an automatic way of configuring things so that the cross-referencing will say "theorem 1.3" only if it is really the current chapter, but "theorem I.1.3" (or something like that) if the cross-referencing spans chapters?

3
  • 1
    How exactly do you define the theorems? Are you using e.g. the amsthm package? Feb 6, 2011 at 16:44
  • @Martin: Right now I'm using ntheorem with cleveref, though I'm happy to change this. Feb 6, 2011 at 16:46
  • 1
    I'd always write "Theorem 1.3" with capital "T". Feb 7, 2011 at 9:11

1 Answer 1

16

You can add a conditional in the reference number which checks if the chapter number of the referenced label is identical to the current chapter number and then suppress the chapter number in the output.

Here a way to do it. I used ntheorem and loaded cleveref because you said you are using it. It might need some minor adjustments to work in your document, but you get the idea.

\documentclass{book}
\usepackage{ntheorem}
\usepackage{cleveref}

% From your post I assume you have settings like this:
\renewcommand*\thechapter{\Roman{chapter}}
\newtheorem{mytheo}{MyTheo}[chapter]

% Redefine the format of the theorem number:
\renewcommand*\themytheo{%
   \protect\maybechapter{\arabic{chapter}}\arabic{section}.\arabic{mytheo}%
}

% May print the chapter number
\newcommand*\maybechapter[1]{%
   % Tests if current chapter is equal to the chapter number of label)
   \ifnum\value{chapter}=0#1\relax
     % Print nothing if so
   \else
     % Set 'chapter' locally (=> no \setcounter) to the label chapter and
     % print it in the usual format followed by a dot
     {\value{chapter}=#1\relax\thechapter.}%
   \fi
}

% Test document:
\begin{document}
\chapter{One}
Here \ref{theo:11}  % prints "1.1"
and there \ref{theo:21}. % print "II.1.1"

\section{S1}
\begin{mytheo}
    Theo1-1\label{theo:11}
\end{mytheo}

\section{S2}
\begin{mytheo}
    Theo1-2\label{theo:12}
\end{mytheo}

\chapter{Two}
There \ref{theo:11}  % prints "I.1.1"
and here \ref{theo:21}. % print "1.1"

\section{S1}
\begin{mytheo}
    Theo2-1\label{theo:21}
\end{mytheo}

\end{document}
2
  • Yes, very good idea. Well done, this is great !
    – user4552
    Mar 30, 2011 at 18:57
  • @NicolasGreliche: Please only add solutions as answers. Please up-vote good answers instead or add comments. However, for both you need a certain amount of reputation points (15 for up-voting, 50 for commenting everywhere). This is a protection for spam-bots. I converted your post to a comment to keep the site tidy. Mar 30, 2011 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .