2

tex4ht has options to create cross links betweens html pages, depending on the cut level.

Current cross-links can create next/previous/up, ... buttons and has several options to customize them.

I wanted to know if it is possible - instead of these cross links - to show the navigation as a "tree", showing only the current branch.

Example, let's say we have the following document structure

Documentation - Table of content

Chapter 1 - Overview

Section 1.1 - Introduction

Chapter 2 - Software

Section 2.1 - Drivers

Sub-section 2.1.1 - Ethernet driver

Sub-section 2.1.2 - USB driver

And that tex4ht is used to generate HTML pages split at subsection level.

When viewing the page "Ethernet driver", I would like to see at the top:

documentation > 2. Software > 2.1 Drivers > 2.1.1 Ethernet driver

Each item being a link to the related page.

Is there any standard way to do it using tex4ht or should I plan some post-processing to build that manually?

3

There is no standard way to do it in tex4ht, but it is possible to do it using some hacks. Try the following configuration file:

 \Preamble{xhtml}
% \TocAt{likechapter,chapter,likesection,section,likesubsubsection,subsection}
\makeatletter
\def\getsection#1{
  \expandafter\def\csname toc#1\endcsname##1##2##3{
   \edef\@tempa{##1}
   \edef\@tempb{\csname the#1\endcsname}
   \ifx\@tempb\@tempa \textgreater ##1\ ##2\fi}
}
\makeatother
\def\resetsections{%
  \def\doTocEntry{\ifx\tempa\@empty\fi}
  \def\tocpart{}
  \def\toclikepart{}
  \def\tocchapter{}
  \def\toclikechapter{}
  \def\tocsection{}
  \def\toclikesection{}
  \def\tocsubsection{}
  \def\toclikesection{}
}
\def\breadcrumbs{%
  \bgroup\resetsections\getsection{chapter}\getsection{part}\getsection{section}\getsection{subsection}%
    \HCode{<a href="\jobname.html">Main</a>}\IfFileExists{\jobname.4ct}{\input{\jobname.4ct}}{}
  \egroup%
}
\Configure{crosslinks*}{}
\Configure{crosslinks+}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="breadcrumbs">}\breadcrumbs\IgnorePar\HCode{</div>}}{}{}{}
\begin{document}
\EndPreamble

we erase default crosslinks definition using \Configure{crosslinks*}{}, then we request call to \breadcrumbs macro in crosslinks+ configuration.

\breadcrumbs macro is little bit hacky. We exploit the TOC file generated by tex4ht, which is named \jobname.4ct. It looks like this:

\expandafter\ifx\csname doTocEntry\endcsname\relax \expandafter\endinput\fi 
\doTocEntry\tocchapter{1}{\csname a:TocLink\endcsname{2}{x2-10001}{QQ2-2-1}{Overview}}{3}\relax 
\doTocEntry\tocsection{1.1}{\csname a:TocLink\endcsname{3}{x3-20001.1}{QQ2-3-2}{Introduction}}{3}\relax 
\doTocEntry\tocchapter{2}{\csname a:TocLink\endcsname{4}{x4-30002}{QQ2-4-3}{Software}}{7}\relax 
\doTocEntry\tocsection{2.1}{\csname a:TocLink\endcsname{5}{x5-40002.1}{QQ2-5-4}{Drivers}}{7}\relax 
\doTocEntry\tocsubsection{2.1.1}{\csname a:TocLink\endcsname{6}{x6-50002.1.1}{QQ2-6-5}{Ethernet driver}}{7}\relax 
\doTocEntry\tocsubsection{2.1.2}{\csname a:TocLink\endcsname{7}{x7-60002.1.2}{QQ2-7-6}{USB driver}}{8}\relax 
\par 

we call macro \resetsections, in which we declare macros which may be containted in the .4ct file to do nothing, then using \getsection, we request testing if the included chapter, section and subsection equals to the current sectioning numbers. If they do, then they are printed.

A sample file:

\documentclass{book}

\begin{document} 
\part{Documentation}
\chapter{Overview}

 \section{Introduction}

\chapter{Software}


 \section{Drivers}

 \subsection{Ethernet driver}

 \subsection{USB driver}
hello world
\end{document}

The result:

enter image description here

5
  • Thanks for that answer! I gave it a try, and forgot that I had also several \part in the structure. Using your cfg file gives weird result when taking in account parts. I came with an alternative solution using a bash script with awk and string substitions to do the job.
    – Blake_ch
    Jun 30 '16 at 12:19
  • @Blake_ch it is quite easy to add support for parts as well, see the updated answer
    – michal.h21
    Jun 30 '16 at 14:17
  • The generated links for parts do not match the structure with your proposal. Imagine you have \part{x} before \chapter{x} in the above structure, the links for part II Software will show Main > 1 Overview > 1.1 Introduction > II Software. I couldn't find how to fix this
    – Blake_ch
    Jul 4 '16 at 14:13
  • @michal.h21 Please could you provide the .tex file? Thanks in advance! Dec 1 '16 at 11:21
  • 1
    @Arianna sure, please see the updated answer
    – michal.h21
    Dec 1 '16 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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