[Tex/LaTex] Smartly omit chapter number in equation numbering

cross-referencingequationsnumberingsectioning

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)

Best Answer

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}

\begin{equation}1=0\label{x}\end{equation}

\section{sss}

\begin{equation}1=-1\label{y}\end{equation}

[[[\ref{x}]]]

\chapter{YY}

[[[\ref{x}]]]

\end{document}