[OS X TeX] Automatic labeling for references
Jan Anderssen
jan at linguist.umass.edu
Sat Apr 5 08:55:47 CEST 2008
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. 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.
Cheers,
Jan
(p/s I wanted to mention that for examples, I really like the way that
Wolfgang Sternefeld's linguex package deals with references: Besides
the usual \label{} - \ref{} mechanism, it defines four commands: \Next
\NNext \Last and \LLast, which refer to the two upcoming and two
preceding examples respectively. 95% of the time, that's enough for
me, and the restriction to the local context makes keeping track of
them relatively easy. Obviously less attractive for chapters, figures,
etc.)
> On 4-Apr-08, at 9:18 PM, Jan Anderssen wrote:
>> Hello.
>>
>>>> But then you've still got to get the \ref commands right so you
>>>> need to know what the labels are. Or do I have this wrong?
>>>
>>> I assume you mean that before I can write "We already saw in
>>> \titleref{314} that …" in the source, I have to know that 314 is
>>> the label of the section I want to reference. Well, I could look
>>> up the section in the toc and then the label number at the given
>>> page number. In fact, why coulnd't the label be the chapter number
>>> followed by some symbol and then by the section number? Then I
>>> would just have to look up the toc!
>>>
>>> The reason I would like this to be automatic is that last year I
>>> gave up on references altogether because I got completely confused
>>> even though someone on this list had written a macro that would
>>> generate random label numbers. This way, it would be just a matter
>>> of looking up an already existing label.
>>
>> I often change the order of things around as I go along (sometimes
>> quite dramatically), so what was section 2.3 might become section
>> 2.7 etc. So you (I?) would either need to live with a mismatch of
>> label and actual section number then (making it kind of arbitrary),
>> or change the label and all depending \ref's all the time, which
>> seems quite tedious and error-prone unless automated.
>>
>> What I imagine could be more feasible is to create a label that
>> looks more like \label{sec:SomeWordsFromSectionTitle}. I usually do
>> that manually, but I imagine it might be automated - probably
>> through some sort of autocompletion mechanism, or applescript that
>> grabs hold of an immediately preceding \section{}, rather than in
>> (La)TeX.
>>
>> Since I don't use TexShop myself, and are rather a novice at
>> AppleScript, maybe other people could be more helpful with the
>> specifics.
>>
>> Cheers,
>> Jan
More information about the macostex-archives
mailing list