This is a direct follow-up to tex4ht: custom list of … (part 2 of 3)
I have a custom list of <things>. The code below provides two-way links between the occurrence of the <thing> on the page and its place in the List of cmh.
the question
How can I adapt the solution from the linked question to account for cases in which the argument to \cmhcommand contains either or both of the following:
- multiple paragraphs
- mathematical content
To reproduce the problem in the code below, replace \cmhcommand{Here is some text} with \cmhcommand{Here is some text\par a new paragraph} in mwe.tex.
mwe.tex
\documentclass{article}
\usepackage{cmhloc}
\begin{document}
\tableofcontents
\section{normal section}
\cmhcommand{Here is some text}
some text
\section{another secton}
\cmhcommand{Another text}
\cmhcommand{some more}
\listofcmh
\end{document}
cmhloc.sty
\ProvidesPackage{cmhloc}
\newcommand\printcmhentry[1]{#1}
\newcommand{\cmhcommand}[1]{\addcontentsline{cmh}{subsection}{#1}\printcmhentry{#1}}
\newcommand{\listofcmh}{\subsection*{List of cmh}\@starttoc{cmh}}
\endinput
cmhloc.4ht
\RequirePackage{etoolbox}
\def\toccmh#1#2#3{%
\bgroup% make the changes local
\Configure{TocLink}{% This will print the link in TOC.
\Link{##2}{\@nameuse{cmhcn-##4}}##4\EndLink% We need to construct the ID parameter in second parameter for \Link
}
\HCode{<div class="sectionToc">}#2\HCode{</div>\Hnewline}% Print the entry
\egroup%
}%
\newcount\cmhcount % each cmhentry will have it's unique idntifier
\renewcommand\printcmhentry[1]{%
\advance\cmhcount by1\relax%
\edef\cmhlink{cmh-\the\cmhcount}% this will be the id for the corresponding entry in the \listcmh
\csxdef{cmhcn-#1}{\cmhlink}\Link{\cmhlink}{}#1\EndLink} % we use the entry text in csname,
% in order to be able to retrieve the id later
% in the \listcmh entries
\append:def\listofcmh{\TableOfContents[cmh]}
\endinput
compilation sequence
htlatex mwe.tex