Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
How exactly do you define the theorems? Are you using e.g. the amsthm package? –  Martin Scharrer Feb 6 '11 at 16:44
    
@Martin: Right now I'm using ntheorem with cleveref, though I'm happy to change this. –  Akhil Mathew Feb 6 '11 at 16:46
1  
I'd always write "Theorem 1.3" with capital "T". –  Hendrik Vogt Feb 7 '11 at 9:11

1 Answer 1

up vote 11 down vote accepted

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}
share|improve this answer
1  
This is great. Thanks! –  Akhil Mathew Feb 6 '11 at 20:35
    
Yes, very good idea. Well done, this is great ! –  user4552 Mar 30 '11 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. –  Martin Scharrer Mar 30 '11 at 19:03
    
Amazing trick, thanks a lot! –  Olivier Jul 13 '11 at 12:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.