[OS X TeX] Automatic labeling for references

Ross Moore ross at ics.mq.edu.au
Sat Apr 5 03:59:36 EDT 2008


Hi Jan,

On 05/04/2008, at 5:55 PM, Jan Anderssen wrote:

> Hi,
>
> On Apr 5, 2008, at 1:04 AM, George Gratzer wrote:
>
>> Could you not just simply define a command to do this?
>
> I considered the other way easier for two reasons:
>
> 1) Personal lack of knowledge: I'm not sure how to write such a  
> command. Say I wanted the first three words of the title,  
> capitalized, prefixed with sec:, subsec:, chap: ..., for instance  
> \section{A novel approach to something old} would become \section{A  
> novel approach to something old}\label{sec:ANovelApproach}. I would  
> probably try something like this
>
> \newcommand{\mysection}[1]{\section{#1}\label{sec: **reformatted/ 
> shortened version of #1**}}
>
> but I just don't know enough about actual tex programming to do any  
> string manipulation to get that result. Is there an easy way?
>
> 2) If a command like the one above is what you had in mind, you'd  
> have to memorize how the labels are generated from the section  
> title, since they wouldn't be in the source anymore.

Surely it is better to pass 2 arguments to  \mysection .

Then use   \mysection{A novel approach to something old} 
{sec:ANovelApproach}
to expand to:

\section{A novel approach to something old}\label{sec:ANovelApproach}


There is, however, one defect with this approach.
It is concerned with exactly *where* on the PDF page the
anchor generated by  \label{sec:ANovelApproach}  is placed.
The ideal is for it to occur above and to the right of the
actual string of the section-title.

That way, when you jump to it in a browser, the section title
is at the top of the window, and so is fully visible.

By default, hyperref makes \ref hyperlinks jump to the
full page on which the section-title occurs.
But this can be changed to allow a different destination
and view of (a portion of) the page.

To do this requires significant hacking to LaTeX internals,
and/or to hyperref internals.  This is not simple TeX
programming, but well worth it if you really want to
implement such effects.


> Admittedly this is probably something one could get used to easily,  
> but I tend to often skip back to the chapter/section/subsection and  
> check what label I have used.

Use the 2-argument approach. It is simple and easy.
Furthermore, you won't have to change your LaTeX source
when/if you decide to try to implement something more fancy.

>
> Cheers,
> Jan

Hope this helps,

	Ross

------------------------------------------------------------------------
Ross Moore                                       ross at maths.mq.edu.au
Mathematics Department                           office: E7A-419
Macquarie University                             tel: +61 (0)2 9850 8955
Sydney, Australia  2109                          fax: +61 (0)2 9850 8114
------------------------------------------------------------------------






More information about the MacOSX-TeX mailing list