# Smartly omit chapter number in equation numbering

In my thesis I use chapters, sections and subsection. I like to have my equations numbered with respect to section, but I want the displayed equations numbers not to include the chapter number. Moreover when referencing the equations I want the chapter number to be excluded unless I reference them from a different chapter.

How can I achieve this? If not otherwise possible it would be ok to use two commands \ref{} and \gref{} where the first one omits the chapter number. I would like to do the same thing also for references to sections and to theorems. At the moment I am using the koma scrbook class.

### Example

I. Chapter 1
1. Section 1
a^2 + b^2 = c^2         (1.1)
as seen in (1.1)

II. Chapter 2
1. Section 1
an extension of (I.1.1) is
a^3 + b^3 = c^3         (1.1)


You can make the prefix conditional on the current chapter being different to the saved chapter in the reference, something like

\documentclass{book}

\renewcommand\theequation{\maybe{\arabic{chapter}}\arabic{section}.\arabic{equation}}
\renewcommand\thechapter{\Roman{chapter}}

\DeclareRobustCommand\maybe[1]{\ifnum#1=\value{chapter}\relax\else\thechapter.\fi}

\usepackage{amsmath}
\begin{document}
\chapter{zz}

\section{lll}

$$1=0\label{x}$$

\section{sss}

$$1=-1\label{y}$$

[[[\ref{x}]]]

\chapter{YY}

[[[\ref{x}]]]

\end{document}

• This works when my chapters are number arabic. How does this work if I have the chapters number with roman? My \renewcommand\thechapter{\Roman{chapter}} messes this up. – H. Brandsmeier Mar 11 '13 at 21:46
• @cideous replace \maybe{\thechapter} by \maybe{\arabic{chapter}} – David Carlisle Mar 11 '13 at 21:50
• Just add \renewcommand\thechapter{\Roman{chapter}} as the second line in your example. – H. Brandsmeier Mar 11 '13 at 21:50
• @cideous Code updated as in comments – David Carlisle Mar 11 '13 at 21:54

I think that there is a slight mistake here. If:

\DeclareRobustCommand\maybe[1]{\ifnum#1=\value{chapter}\relax\else\thechapter.\fi}


is used, then the current chapter will be displayed, and not the referred chapter. I propose to use instead:

\DeclareRobustCommand\maybe[1]{\ifnum#1=\value{chapter}\relax\else\uppercase\expandafter{\romannumeral#1}.\fi}


And it works!