diff -Naur latex2html-master.orig/latex2html.pin latex2html-master/latex2html.pin --- latex2html-master.orig/latex2html.pin 2021-06-05 18:58:52.279933335 +0700 +++ latex2html-master/latex2html.pin 2021-06-05 20:22:49.449880745 +0700 @@ -9852,6 +9852,7 @@ sub make_name { local($sec_name, $packed_curr_sec_id) = @_; local($title,$making_name,$saved) = ('',1,''); + local($filename) = ''; if ($LONG_TITLES) { $saved = $_; &process_command($sections_rx, $_) if /^$sections_rx/; @@ -9869,7 +9870,16 @@ #ensure no more than 32 characters, including .html extension $title =~ s/^(.{1,27}).*$/$1/; ++$OUT_NODE; - join("", ${PREFIX}, $title, $EXTN); + $filename = join("", ${PREFIX}, $title, $EXTN); + # Avoid duplication of filenames + unless ($nodenames{$filename}) { + $nodenames{$filename} = 1; + } else { + # Duplication detected: add version number to generated filename + $filename = + join("", ${PREFIX}, $title, ++$nodenames{$filename}, $EXTN); + } + $filename; } else { # Remove 0's from the end of $packed_curr_sec_id $packed_curr_sec_id =~ s/(_0)*$//; diff -Naur latex2html-master.orig/tests/longtitles.tex latex2html-master/tests/longtitles.tex --- latex2html-master.orig/tests/longtitles.tex 1970-01-01 07:00:00.000000000 +0700 +++ latex2html-master/tests/longtitles.tex 2021-06-05 20:16:59.129884402 +0700 @@ -0,0 +1,66 @@ +\documentclass[10pt]{article} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage[english]{babel} + +% Testing longtitles option +% +% pdflatex longtitles (may be do it several times to be sure) +% +% latex2html -html_version 4.0 -local_icons longtitles.tex +% Everything should be OK. There are several sections with duplicated names. +% The duplications are intentional, to demonstrate the bug. +% Notice section 1, subsections 1.1 and 1.2, +% section 2, subsection 2.1, and section 3, subsection 3.1. +% +% rm -rf longtitles +% latex2html -html_version 4.0 -local_icons -long_titles 5 longtitles.tex +% Now you will not see sections 1 and 2 at all, and section 3 will be mess. +% Moreover, repetitive clicking 'Next' in the browser will never reach the end. +% This is because of mutual clobbering of duplicated HTML filenames. +% +% After applying the patch against titles duplication +% the -long_titles option should work correctly: +% the sequential numbers will be added to the duplicated filenames +% starting from #2. + +\begin{document} + +\tableofcontents + +\section{Some basic stuff with very long first section name} + +This is some simple text, from section \thesection{} Some basic stuff +with very long first section name. + +\subsection{Fonts} + +This subsections has some fonts, from section \thesection{}, +subsection \thesubsection{} Fonts. + +\subsection{Lists} + +This subsections has some lists, from section \thesection{}, +subsection \thesubsection{} Lists. + +\section{Some basic stuff with very long second section name} + +This is some simple text, from section \thesection{} Some basic stuff +with very long second section name. + +\subsection{Fonts} + +This subsections has some fonts, from section \thesection{}, +subsection \thesubsection{} Fonts. + +\section{Some basic stuff with very long third section name} + +This is some simple text, from section \thesection{} Some basic stuff +with very long third section name. + +\subsection{Lists} + +This subsections has some lists, from section \thesection{}, +subsection \thesubsection{} Lists. + +\end{document}