11

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)
1

2 Answers 2

13

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}
4
  • 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. Mar 11, 2013 at 21:46
  • @cideous replace \maybe{\thechapter} by \maybe{\arabic{chapter}} Mar 11, 2013 at 21:50
  • Just add \renewcommand\thechapter{\Roman{chapter}} as the second line in your example. Mar 11, 2013 at 21:50
  • @cideous Code updated as in comments Mar 11, 2013 at 21:54
2

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!

You must log in to answer this question.

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