I am trying to make my own links to targets in separate subsubsections. (I have reasons why I can't use tex4ht own links, since it does not work when splitting using separate files. Long story. I reported it but not possible to correct/fix using xr-hyper)

In the following, everything works well for splitting up to subsection level, since tex4ht uses format of name insuNNN.htm for the file names, where the main document is index.tex and NNN is a counter it increments sequentially for how many subsections there are in the whole document.

So doing the split at this level, I am able to figure the correct HTML file name to use.

The problem when I want to split at lower level. At the subsubsection level.

tex4ht for some reason, uses the same counter NNNN for subsection and also subsubsection.

And it keeps incrementing the counter. So if subsection 10 was in file insu10.htm, then the next subsubsection will go to file insu11.htm

So my program, which wants to add a link to subsubsection is now not able to figure what the file name will be due to this. It gets the counting wrong since it does not know how many subsections were before to compenate.

If tex4ht had used separate counter for subsubsection, then it will be possible to figure the file name and add correct link to it.

Note that tex4ht uses inseMMM.htm for sections. But uses insuNNN.htm format for both subsections and also subsubsection file name. And that is the main problem.

My question is, given I want to split at subsubsection level (i.e. split=5), is it possible to tell tex4ht to use one counter for this level and not share it with the subsection counter?

If so, then my program will be able to determine the correct file name and add a link to each problem correctly.

Here is MWE



  see problem \HCode{<a href="insu1.htm#1">1</a>} and problem \HCode{<a href="insu2.htm#2">2</a>}
  and problem \HCode{<a href="insu3.htm#3">3</a>}

\chapter{this is chapter 1} 
\section{my first section} 
\subsection{my first subsection}
\subsubsection{my first subsubsection}
\HCode{<a id="1"></a>} 
      this is problem 1
\section{my first section} 
\subsection{my second subsection}
\subsubsection{my second subsubsection}
\HCode{<a id="2"></a>} 

      this is problem 2

\chapter{this is chapter 2} 
\section{my first section}
\subsection{my first subsection}
\subsubsection{my first subsubsection}
\HCode{<a id="3"></a>} 

      this is problem 3

Compiling with

make4ht -ulm default -a debug index.tex 'htm,5'

Now links to 1 is off by 1, and link 2 is off by 2 and 3 are now off by 3 and so on.

For example the link to first subsubsection insu1.htm should be insu2.htm because texh4t used insu1.htm for the intervening subsection.

It is not possible to figure these offsets in the program, due to this since the document is very complex and do not know how many subsections were used at different places to compensate for the counter drift.

But if the counter was sequential for each subsubsection, regardless of how subsection there are, then it will be possible to do what I want, I will simply have a global counter which I increase each time a new subsubsection is added and it will make life much simpler.

Is it possible to tell tex4ht or fix tex4ht to use different/unique counter for subsubsection splitting and not share the counter with subsection?

What I think tex4ht should do is this

inchNNN.htm for chapters (it does this already)

inseNNN.htm for sections (it does this already)

insuNNN.htm for subsections (it does this already)

insuuNNN.htm for subsubsections (this is the new change I am suggesting). Currently tex4ht uses same file name format and counter as subsection.

The above change will be very useful as it will make it much easier to add links to specific subsubsections in a document from outside.

TL 2022

  • 1
    Not sure, whether or not tex4ebook does provide a solution here already ...
    – MS-SPO
    Commented May 13, 2022 at 6:38

1 Answer 1



TeX4ht shortens generated filenames. It uses the first two characters of the \jobname, and the first two characters of the section type. The numeric suffix is attached to these to ensure unique names. In this case, \subsection and \subsubsection are both shortened to su. You can keep the full section type name in filename using this configuration file:

\def\fx:pt#1xxx!*?: {%
   \expandafter\ifx \csname big:#1:\endcsname\relax
         \expandafter\gHAssign\csname big:#1:\endcsname  0  \fi
   \expandafter\gHAdvance\csname big:#1:\endcsname  1
   \edef\big:fn{#1\csname big:#1:\endcsname}}

It is a redefinition of the internal TeX4ht command that shortens the section type name. In this version, it just keeps the full name.

These are resulting filenames:


I've also added the cut-fullname option to TeX4ht sources, so after TeX Live update, it will be possible to get the same effect using:

 $ make4ht -ulm default -a debug index.tex 'htm,5,cut-fullname'


The correct solution for this problem is to use the sec-filename option. It names files according to the current top section title:

 $ make4ht -ulm default -a debug index.tex 'htm,5,sec-filename'

It generates the following files:


As you can see, it uses section titles. It removes spaces and other non-alphanumeric characters, and if file with the same name already exists, it adds a numeric suffix, to ensure a unique filename.

Thanks for that, you don't need to update your links every time you add a new section (unless there already is one with the same name).

  • I did not know about sec-filename but I am afraid this makes things worst for me. Now I have to know what each subsubsection name actually is from outside the document I am trying to link to. using insuuNNN would be the perfect solution, since for me NNN is the problem number. So I could just say from outside, see problem <a \href="insuNNN.htm#NNN>etc...</a>" for problem NNN where NNN is the problem number which is one global counter I have that goes from 1 to say 100. I put each problem in its own subsubsection. But now I have to know what each subsubsection title is. Thanks,.
    – Nasser
    Commented May 13, 2022 at 9:30
  • Is it hard to make tex4ht just generate files with names insuuNNN.htm for subsubsection and not share insuNNN,htm with subsections? This would be a much better way to do it. At least it will be easier, since the file name is known, and just need to add the problem number to get the full name without having to know the exact title used.
    – Nasser
    Commented May 13, 2022 at 9:34
  • @Nasser it probably shouldn't be that hard, it is just that sec-filename already exists and I thought that it would be a better solution for you.
    – michal.h21
    Commented May 13, 2022 at 9:36
  • Thanks for pointing out this option, But the issue is that I am trying to build separate chapters on their own to speed tex4ht on large documents. But I need to be able to add links to specific problem(s) from outside. I only know the problem number from outside. The titles themselves change from chapter to chapter. If it is possible to make subsubsection use its own file format with its own counter that will be great. I have been running tex4ht for now 5 days on this one large file and it is on iteration 36 and not finished yet. So I need a way to speed this process :(
    – Nasser
    Commented May 13, 2022 at 9:39
  • I think the checksum is not working right btw. I do not understand why the current build I am running needs 36 iterations to get everything sorted out. But I am using your build file, and I set the maximum to 100 (it was 3 before) and it is still running and now at iteration 36. There seems to be a problem with how checksum is done but not sure. Hopefully will find out if it finished in 2-3 weeks.
    – Nasser
    Commented May 13, 2022 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .