TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When compiling a file with tex4ht, the sections are transformed with header HTML tags with anchor. So, if I compile

\documentclass{article}
\usepackage[xhtml,mathml]{tex4ht}
\begin{document}
\section{Hello}
\end{document}

with latex, tex4ht, I obtain the following html code

<h3>[...]<a id="x1-10001"></a>Hello</h3>

Is it possible to move the anchor tag to the end, and to make it non empty? Specifically, I would like something like:

<h3>[...]Hello<a class="anchor" id="x1-10001">¶</a></h3>

Is that possible?

share|improve this question
    
Anchor id's are rather hardwired, I believe it is hard to change the way it gets inserted since it is the only mechanism through which TeX4ht tracks various anchor points by making use of \jobname.xref. This is very much used to track and cross-link various linkable items correctly even if the html output is split into several different files with \CutAt{...} command, the argument of which can by any logical sectional unit or chapter. – CV Radhakrishnan Oct 9 '12 at 23:58
    
I take it that it is impossible to achieve what I want to do? – Olivier Oct 10 '12 at 10:07

Customizing section links isn't really easiest task in tex4ht. They are inserted on hardcoded location, but we can hopefully use toTocLink configuration to remove them from this hardcoded location and save them for the later use. We must then configure all sectioning commands to use the saved link.

You can use following configuration file, "mysec.cfg":

\Preamble{xhtml,mathml}
\newcommand\SecLink[2]{\gdef\SecAnchor{{#1}{#2}}}

\Configure{toTocLink}{\SecLink}{}

\newcommand\BlockTag[1]{\ifvmode\IgnorePar\fi\EndP\HCode{#1}}
\def\pilcrow{\special{t4ht@+&{35}xb6;}x}
\newcommand\MySection[2]{%
  \Configure{#1}{}{}{\BlockTag{<#2 class="#1Head">}\TitleMark
  }{ \expandafter\Link\SecAnchor \pilcrow\EndLink\BlockTag{</#2>}}
}
\MySection{section}{h2}
\MySection{likesection}{h2}
\MySection{subsection}{h3}
\MySection{likesubsection}{h3}
\MySection{subsubsection}{h3}
\MySection{likesubsubsection}{h3}
\begin{document}
\EndPreamble

compile with

make4ht -uc mysec.cfg filename.tex

we can inspect the code a little bit

\newcommand\SecLink[2]{\gdef\SecAnchor{{#1}{#2}}}
\Configure{toTocLink}{\SecLink}{}

tex4ht provides command \Link{#href}{id} ... \EndLink for internl cross referencing. This command is used in \Configure{toTocLink} by default, resulting in <a> element with anchor to and from TOC. With this configuration we save the link destinations for later use and remove it from the usual place.

\newcommand\MySection[2]{%
  \Configure{#1}{}{}{\BlockTag{<#2 class="#1Head">}\TitleMark
  }{ \expandafter\Link\SecAnchor \pilcrow\EndLink\BlockTag{</#2>}}
}

this command configures sectioning command to put saved link right before the closing tag.

Slightly modified example with more sections

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
\tableofcontents
\section{Hello}
\section{world}
\subsection{and subsection}
\section*{Like section}
\end{document}

produces:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.