[OS X TeX] Referring to arbitrary labels? Solution!

Mohinish Shukla shukla at sissa.it
Wed Nov 24 17:21:45 CET 2004


Hi all,
	here is a (working!) solution to the problem of having a counter for
just certain sections, spread across multiple chapters and having their
own (linear) numbering.

THE PROBLEM:
---------------------
	- I have Experiments, numbered 1,2,3 etc. Experiments are at the level
'Section'.  However, not all sections are Experiments, and the set of
Experiments can span multiple chapters.
	- Each section that is an Experiment has a title, something like
"7.2  Experiment 3: Segmenting fluent speech"
	- The problem is referring to an Experiment like this: "... as we saw
in Experiment 3, it is not easy segmenting fluent speech." or
optionally, "... as we saw in Experiment 3 on page 35, it is not easy
segmenting fluent speech.", or also (for completeness), ".. as we saw  
in Experiment 3, Section 7.2..".

THE SOLUTION:
-----------------------
 >>Packages required:
	- varioref.sty (not Absolutely Necessary for the logic of the solution)


 >>In the preamble:
	\newcommand{\eref}[1]{Experiment \ref{#1}}
	\newcommand{\erefp}[1]{Experiment \ref{#1}\protect{\vpageref{#1}}}
	\newcounter{expt}
	\setcounter{expt}{1} % Counter for experiments


 >>At each section that is a chapter:
	\section{Experiment \arabic{expt}: Segmenting fluent  
speech}\label{expt:fluent}
	\addtocounter{expt}{-1}\refstepcounter{expt}\label{exptn: 
fluent}\addtocounter{expt}{1}

- Thus, in my example, \label{expt:xxx} refers to the section  
containing the EXPerimenT, while \label{exptn:xxx} refers to the  
EXPerimenT Number.


 >>Referring to the chapter elsewhere:
	As we saw in \eref{expt:fluent} that fluent speech can be segmented .  
. .
		or
	As we saw in \erefp{expt:fluent} that fluent speech can be segmented .  
. .
		or
	As we saw in \eref{expt:fluent}, Section \ref{expt:fluent} that fluent  
speech can be segmented . . .


 >>Note:
	You can also refer to the entire name of the experiment, for e.g.
	"Experiment 3: Segmenting fluent speech",
	BUT: you need to use titleref (titleref.sty) and not nameref, since  
nameref seems to screw up the \pageref


THANKS ETC.!
----------------------
Ok.. maybe not the bestest of code, and a little hacky, but the results  
are most satisfying :)

Thanks again to all the previous tips!!!

-Mohinish


--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
           & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>





More information about the macostex-archives mailing list