[OS X TeX] Automatic labeling for references

Matthew Leingang leingang at math.harvard.edu
Mon Apr 7 09:07:57 EDT 2008

On Apr 6, 2008, at 11:49 AM, Alain Schremmer wrote:
> On Apr 6, 2008, at 1:47 AM, Peter Pagin wrote:
>> Alain Schremmer wrote:
>>>         \renewcommand\theTitleReference[2]{\bfseries{#1}\ \emph{#2}}
>>> 	\newcommand{\MYsection}[1]{\section{#1}\label{\thesection}}
>> The drawback with it is that if you move a section (to before or  
>> after another), it will get a new label. Then if you have cross  
>> references to it in your text, they will after the change go to  
>> the wrong section.
> I agree that
> 		\newcounter{labb}
> 		\newcommand{\Section}[1]{\section{#1}\label{\thelabb}\stepcounter 
> {labb}}
> is a lot better.
> The only problem I have is that I am writing chapters included in a  
> "book" rootfile and that each chapter also has a dedicated  
> "chapter" root file for typesetting just the chapter and then of  
> course \newcounter{labb} gives different references when  
> typesetting the "chapter" rootfile or the "book" rootfile.
> To avoid this, I would need only place in each "book" rootfile  
> something like \addtocounter{labb}{total number of sections before  
> the current chapter} just before the \include.
> I actually do that, by hand, for "total number of chapters before  
> the current chapter"—but that is easy to maintain—and "total number  
> of pages before the current chapter"—but that is not critical—(so  
> that neither really needs to be automated).
> But I have no idea about how to get "total number of sections  
> before the current chapter" other than by hand.

Well, maybe you could extend the addtocontents macro to count for  
you.  If you're using \include on each of your chapter files and  
includeonly to specify which, then the aux files are read anyway and  
that's where the addtocontents macros are.  But you're already  
incrementing the counter with \section, so you'd have to make sure  
you didn't do it twice...

Several philosophical arguments have been made against this approach,  
and I don't want to pile on.  But it seems like you're going to a lot  
of trouble to effectively *remove* functionality from LaTeX.   
Automatically generated labels are *less* useful then labels with  
human names.  Having \section create a label called "4.11" that  
expands to "4.11" is no better than simply looking in the table of  
contents and typing "4.11".  Either way, if you change the document  
organization, you have to change the labels.  Having \section create  
a label called "392" that expands to "4.11" is worse, because I don't  
see where you check the number of the label to refer to it (it's  
neither in the source nor the final).

Maybe you're tired of creating your own labels because you're using  
more than you need. I only make a label at the moment I realize I  
need to refer to it.  I agree with your point that it's hard to  
decide on a label "style" (capitalization, word breaks, etc.), but  
(assuming you're a solo author) you've only yourself to blame for that.

Matthew Leingang

Matthew Leingang
Preceptor in Mathematics
Harvard University


More information about the MacOSX-TeX mailing list