[OS X TeX] references inside a single chapter
Peter Vamos
P.Vamos at exeter.ac.uk
Wed Apr 12 12:10:48 EDT 2006
On Sun Mar 26 Ewan Delanoy wrote:
>I should like to produce an output like that in LaTeX
>
> Chapter A Mammals
>
> Section1. Whales
> Section 2. Dogs
>
> Section 1 was about whales.
>
> Chapter B Birds
>
> Section A1 was about whales.
>
> So the philosophy is to omit the index of the chapter
>when making references inside a single chapter. This is
>not the default practice in LaTeX. How can this be done ?
This is what I told my PhD students to do in their Theses but they
came back to ask me how to do it. So I had to figure it out.
Fortunately I found a lovely package: `smartref' by by Giuseppe
Bilotta. Using this I wrote a macro \Ref (note the capitalization);
this will do exactly what you want. Just write your file as usual;
you'll need a few lines in the preamble to ensure correct numbering +
the \Ref macro. I enclose a sample file. This specifies the AMS book
\documentclass but I don't think this (AMS) is relevant. The smartref
package doesn't seem to be in Gerben's distribution (at least not in
my set-up) so you'll need to get it from CTAN. When I looked it up
now it showed version number 1.6, mine is 1.9; I cannot remember how
I got it although i corresponded with the author. Hopefully it won't
matter.
========= sample document ==========
%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Sample file to illustrate `Chapter Aware Referencing'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{%
amsbook%
}%
\parindent0pt
\usepackage{verbatim, smartref}
%%%%%%%smart Ref stuff %%%%%%%%%
\newcommand{\Ref}[1]{%
\ischapterchanged{#1}% checks if chapter number has changed
\hbox{%
\ifchapterchanged% if chapter is different
\chapterref{#1}.% put the chapter reference
\fi % else do nothing
\ref{#1}%
}%
}
\addtoreflist{chapter} %this is needed for the smartref package
%%%%%%%%%%%%% for numbering to work properly %%%%%%%%%%%
\numberwithin{section}{chapter}
\numberwithin{equation}{chapter}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}[theorem]{Lemma}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\title{Chapter Aware Referencing.}
\author[V\'amos]{Peter V\'amos}
\address{P. V\'amos\\ School of Mathematical sciences \\ University of
Exeter \\ North Park Rd., Exeter
EX4~4QE \\ England}
\email{P.Vamos at exeter.ac.uk}
\maketitle
\chapter{This is the first chapter}
\section{This is a numbered first-level section head}
This is an example document to illustrate `chapter aware'
referencing, see Theorem~\Ref{t:main} for the precise definition.
This type of referencing is made possible by the use of the
\texttt{smartref} package by Giuseppe Bilotta and the macro
$\backslash$\texttt{Ref. }We will need two chapters to demonstrate
the desired effect.\\
So let's put here a couple of things with labels for cross-referencing.
\begin{lemma}\label{l:functions}
Let $f, g\in A(X)$ etc
\end{lemma}
%\begin{comment}
And now an equation for testing equation referencing:
\begin{equation}\label{eq:action}
e^{i\pi}=-1
\end{equation}
%\end{comment}
\begin{comment}
\begin{theorem}\label{t:main}
References of the form \textup{x.x (section.number)} will indicate
an item in the current chapter whereas the form \textup{x.x.x
(chapter.section.number)} will indicate an item in a different
chapter.
\end{theorem}
\end{comment}
End of Chapter 1.
\chapter{Testing Cross Referencing}
\section{This is a numbered first-level section head in chapter 2}
\begin{lemma}\label{l:start}
This is a lemma to start with.
\end{lemma}
\section{This is a numbered first-level section head in chapter 2}
And now for our next result:
\begin{lemma}\label{l:next}
This is our next lemma.
\end{lemma}
Followed by a theorem which maybe moved to Chap.1 for testing.
%\begin{comment}
\begin{theorem}\label{t:main}
References of the form \textup{s.x (section.number)} will indicate
an item in the current chapter whereas the form \textup{c.s.x
(chapter.section.number)} will indicate an item in chapter
\textup{c} different from the current chapter.
\end{theorem}
%\end{comment}
Testing referencing to a lemma in Chapter 1: Lemma~\Ref{l:functions},
and to results in \emph{this}
chapter: Lemma~\Ref{l:start}; also Lemma~\Ref{l:next} and Theorem~\Ref{t:main}.
Equation referencing: by equation~\Ref{eq:action} etc.\\
\begin{comment}
And now an equation for testing equation referencing:
\begin{equation}\label{eq:action}
e^{i\pi}=-1
\end{equation}
\end{comment}
Now lets move Theorem~\Ref{t:main} to Chapter 1 and
equation~\Ref{eq:action} to Chapter 2 and see what happens. (Just
\texttt{comment} and \texttt{uncomment} in the source file.)
Remember: you have to \emph{typeset twice} to see the correct
references!
\end{document}
More information about the MacOSX-TeX
mailing list