[tex4ht] Is it possible to fix tex4ht links so so it ends at top of page?

Nasser M. Abbasi nma at 12000.org
Wed Sep 25 13:42:49 CEST 2024


On 9/25/2024 5:24 AM, Michal Hoftich wrote:
> Hi Nasser,
> 
> But on chapter one, I have few sections and a local TOC for
>> the chapter that links to them, i.e. on same page.
>>
> 
> Well, this is why this change is a bad idea in the first place. This
> configuration is used when the TOC is printed, so any change later in the
> document cannot influence it.
> 
> This configuration seems to work, but it starts to get messy:
> 
> \Preamble{xhtml}
> 
> \Configure{TocLink}{\Link[\LikeRef{cutfile \LikeRef{fileidcut #1}(L
> }]{}{#3} #4\EndLink}
> 
> \catcode`\:=11
> \Configure{TocAt}
>     {\let\sv:atoc\a:tableofcontents
> \let\sv:btoc\b:tableofcontents
> \let\sv:ctoc\c:tableofcontents
> \let\sv:dtoc\d:tableofcontents
> \let\sv:etoc\e:tableofcontents
> %
>      \Configure{tableofcontents}
>         {\IgnorePar\EndP\HCode{<div class="\sec:typ TOCS">}\IgnorePar}
>         {}{\IgnorePar\HCode{</div>}\ShowPar}{\HCode{<br />}}{}%
>      \ifvmode \IgnorePar\fi \EndP
> \Configure{TocLink}{\Link{##2}{##3}##4\ifvmode\IgnorePar\fi\EndLink}
>     }
>     {\let\a:tableofcontents\sv:atoc
> \let\b:tableofcontents\sv:btoc
> \let\c:tableofcontents\sv:ctoc
> \let\d:tableofcontents\sv:dtoc
> \let\e:tableofcontents\sv:etoc
> \par\ShowPar}
> \catcode`\:=12
> \begin{document}
> \EndPreamble
> 

Thanks Michal for the effort, but I am afraid this does not work
in general.

It worked on the example I gave. But when I added subsection and
made split=3, and clicked on the new TOC, it opened the new
page as before. i.e. with shifted web page not showing the
navigation bars.

The good news is that TOC for sections on same page still
work OK. So I can use your code above for now, as it is
an improvement over what was before, but it is not a complete
solution for all cases.

If it is possible to make your code work for all cases, this
will be great benefit for all users of tex4ht, but I know
it is not easy problem to make it handle all possible cases.

Below is the example I used to test your new .cfg

----------
\documentclass[12pt]{book}%
\usepackage{lipsum}
\begin{document}
	
\ifdefined\HCode
\Configure{tableofcontents*}{chapter}
\else
\setcounter{tocdepth}{0} %for toc
\tableofcontents
\fi

\ifdefined\HCode
\TocAt{chapter,section}%this tells tex4ht to make local TOC in chapter web page
\TocAt{section,subsection}%this tells tex4ht to make local TOC in section web page
\fi
	
\chapter{chapter 1}
%tex4ht will make local TOC here
\lipsum[2-4]
\lipsum[2-4]
\section{s1}
   %tex4ht will make local TOC here
   \lipsum[2-4]
   \subsection{s11}
   \lipsum[2-4]
   \subsection{s11}
\lipsum[2-4]
\section{s2}
\lipsum[2-4]

\chapter{chapter 2}
more text

\end{document}
------------------------

Compiled using

make4ht -ulm default -a debug -c t.cfg  A.tex "mathjax,3,htm"

Where t.cfg is your .cfg you show above.

Now if you click on "chapter 1" link on main page, this will
open chapter one page correctly (i.e. no vertical shift) and
navigation bars show automatically.

Now you will see a TOC with s1 and s2 at top. If you click on s1,
then it will open a new page for section 1. But the vertical
shift now is there and navigation bars do not show again without
manually moving the slider.

The .cfg has to work for all cases as same .cfg will be used
to build different pages and files with different split levels.

If you like me to test anything else, please let me know.

Thanks again for the help.

Regards,
--Nasser





More information about the tex4ht mailing list.