# [OS X TeX] Automatic labeling for references

Alain Schremmer schremmer.alain at gmail.com
Sat Apr 5 11:27:28 EDT 2008

On Apr 5, 2008, at 3:59 AM, Ross Moore wrote:
> Hi Jan,
>
> On 05/04/2008, at 5:55 PM, Jan Anderssen wrote:
>
> 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.
>
> 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.

OK, I must confess: I covered up some.

After a few hours spent trying to figure out from Companion2ed p843
how to do a "command definition", the best I could come up was:

\newcommand{\mysection}[2]{\section \label{421}}

which, when I typed "\mysection{this and that}" gave me both the
correct section number in the body and it the toc but, in both
places, without "this and that" and sure enough without \label{421}.

The 421 was an experiment: I was hoping eventually to replace 421 by
a command that would automatically put "the next number" (as opposed
to a random one) which I would then look up anytime I would need to
make a reference.

So, really, I have two problems:

—the fact that I can't write the \newcommand but which I hope
eventually to figure it out which is why I didn't mention it,
—the one I know I have no chance whatsoever to solve which is the one
I asked about, namely how to get a command that generates "the next
number" from a counter or the chapter-section number of the section.

Hopeful regards
--schremmer