# [tex4ht] Use Original \label as Anchor Text

Allen Barnett allen at transpireinc.com
Wed Sep 23 22:19:05 CEST 2009

On Wed, 2009-09-23 at 23:26 +0530, Radhakrishnan CV wrote:
> On 23-Sep-09, at 5:36 PM, Allen Barnett wrote:
>
> > Hi: I'd like to be able to jump into the middle of the HTML
> > generated by
> > tex4ht. So, I was wondering if there was a way to use the original
> > \label text as the anchor id in the generated HTML? For example, I
> > have:
> >
> > \label{chp:ChapterTitle}
> >
> > and would like the HTML to have
> >
> > <a id="chp:ChapterTitle">
> >
> >
> > <a id="x7-510005.1">.
>
>
> \Get:SecAnchor macro does the job of inserting anchor id's as shown
> above to various anchor points. It has further implications and role
> in several places like TOC, next, previous, top, up, etc in a html
> page. If you want to use your label as the anchor point, I am afraid,
> it is a non-trivial task, particularly when your label occurs after
> the occurrence of a chapter heading. The following macro does the job
> of configuring chapter mark:
>
>   \ConfigureMark{chapter}{\HCode{<a id="chp:ChapterTitle"></a>}}
>
> You need to insert the label string as a parameter in place of
> 'chp:ChapterTitle' so that your can use the above function in a
> generic fashion to insert labels as id's wherever possible. I would
> appreciate to see your results if you are successful to configure
> chaptermark successfully.

to admit, though, that my knowledge of TeX is quite limited. Could you
give me a little more guidance on how to introduce this macro in the the
Tex4ht system?

As I reflect on your suggestion, it occurs to me that it is not
essential that exactly the \label text be used as the anchor id. It
would be sufficient to introduce an HTML anchor with just some given
text. For example, could I defined an "anchor" command so that:

\section{Chapter Title}
\label{chp:ChapterTitle}
\anchor{some-other-text}

yields:

<a id="x7-510005.1"><a id="some-other-text">

Is this any easier to implement?

Thanks again,
Allen

--
Allen Barnett
Transpire, Inc
E-Mail: allen at transpireinc.com
Skype:  allenbarnett
Ph:     518-887-2930