我正在使用 tex4ebook 生成 .epub,我需要使用 titlesec。当我编译文档时,我注意到如果我导入 titlesec 并编译多次,则章节和子章节的书签会重复。任何有关如何删除重复项的提示都将不胜感激。
麦格
\documentclass{book}
\usepackage{titlesec}
\begin{document}
\part{Mammalia}
\chapter{Monotremata}
\section{Platypoda}
\subsection{Ornithorhynchidae}
\subsubsection{Ornithorhynchus}
\paragraph{anatinus}
\section{Tachyglossa}
\subsection{Tachyglossidae}
\subsubsection{Tachyglossus}
\paragraph{aculeatus}
\end{document}
版本.mk4
local domfilter = require "make4ht-domfilter"
local filter = require "make4ht-filter"
local ncxprocess = domfilter {
function(dom)
for i, navpoint in ipairs(dom:query_selector("navPoint")) do
local text = navpoint:query_selector("text")[1]:get_text():gsub("^%s*", ""):gsub("%s*$", ""):lower()
if dom:query_selector("navPoint")[i+1] ~= nil then
local next_nav = dom:query_selector("navPoint")[i+1]
local next_text = next_nav:query_selector("text")[1]:get_text():gsub("^%s*", ""):gsub("%s*$", ""):lower()
if next_text == text then
navpoint:remove_node()
end
end
end
return dom
end
}
Make:htlatex {}
Make:htlatex {}
Make:match("ncx$", ncxprocess)
注释掉 titlesec import 时的输出:
未导入 titlesec 时的 .ncx 文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1"> <head>
<meta name="dtb:uid" content="http://example.com/mwe"/>
<meta name="dtb:depth" content="3"/>
<meta name="dtb:totalPageCount" content="0"/>
<meta name="dtb:maxPageNumber" content="0"/>
</head>
<docTitle>
<text>Unnamed</text>
</docTitle>
<navMap>
<navPoint id="navPoint-1" playOrder="1">
<navLabel>
<text><navmark type="part"> I</navmark> Mammalia</text>
</navLabel>
<content src="mwepa1.html#x2-1000I" />
<navPoint id="navPoint-2" playOrder="2">
<navLabel>
<text><navmark type="chapter"> 1</navmark> Monotremata</text>
</navLabel>
<content src="mwech1.html#x3-20001" />
<navPoint id="navPoint-3" playOrder="3">
<navLabel>
<text><navmark type="section"> 1.1</navmark> Platypoda</text>
</navLabel>
<content src="mwech1.html#x3-30001.1" />
<navPoint id="navPoint-4" playOrder="4">
<navLabel>
<text><navmark type="subsection"> 1.1.1</navmark> Ornithorhynchidae</text>
</navLabel>
<content src="mwech1.html#x3-40001.1.1" /> </navPoint>
</navPoint>
<navPoint id="navPoint-5" playOrder="5">
<navLabel>
<text><navmark type="section"> 1.2</navmark> Tachyglossa</text>
</navLabel>
<content src="mwech1.html#x3-70001.2" />
<navPoint id="navPoint-6" playOrder="6">
<navLabel>
<text><navmark type="subsection"> 1.2.1</navmark> Tachyglossidae</text>
</navLabel>
<content src="mwech1.html#x3-80001.2.1" />
</navPoint>
</navPoint>
</navPoint>
</navPoint>
</navMap>
</ncx>
导入titlesec时的输出:
导入 titlesec 时的 .ncx 文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1"> <head>
<meta name="dtb:uid" content="http://example.com/mwe"/>
<meta name="dtb:depth" content="3"/>
<meta name="dtb:totalPageCount" content="0"/>
<meta name="dtb:maxPageNumber" content="0"/>
</head>
<docTitle>
<text>Unnamed</text>
</docTitle>
<navMap>
<navPoint id="navPoint-1" playOrder="1">
<navLabel>
<text><navmark type="part"> I</navmark> Mammalia</text>
</navLabel>
<content src="mwepa1.html#x2-1000I" />
<navPoint id="navPoint-2" playOrder="2">
<navLabel>
<text><navmark type="chapter"> 1</navmark> Monotremata</text>
</navLabel>
<content src="mwech1.html#x3-20001" />
<navPoint id="navPoint-3" playOrder="3">
<navLabel>
<text><navmark type="section"> 1.1</navmark> Platypoda</text>
</navLabel>
<content src="mwech1.html#x3-30001" /> </navPoint>
<navPoint id="navPoint-4" playOrder="4">
<navLabel>
<text><navmark type="section"> </navmark>
1.1 Platypoda</text>
</navLabel>
<content src="mwech1.html#Q1-3-4" />
<navPoint id="navPoint-5" playOrder="5">
<navLabel>
<text><navmark type="subsection"> 1.1.1</navmark>
Ornithorhynchidae</text>
</navLabel>
<content src="mwech1.html#x3-40001" /> </navPoint>
<navPoint id="navPoint-6" playOrder="6">
<navLabel>
<text><navmark type="subsection"> </navmark> 1.1.1
Ornithorhynchidae</text>
</navLabel>
<content src="mwech1.html#Q1-3-6" /> </navPoint>
</navPoint>
<navPoint id="navPoint-7" playOrder="7">
<navLabel>
<text><navmark type="section"> 1.2</navmark> Tachyglossa</text>
</navLabel>
<content src="mwech1.html#x3-70002" /> </navPoint>
<navPoint id="navPoint-8" playOrder="8">
<navLabel>
<text><navmark type="section"> </navmark>
1.2 Tachyglossa</text>
</navLabel>
<content src="mwech1.html#Q1-3-12" />
<navPoint id="navPoint-9" playOrder="9">
<navLabel>
<text><navmark type="subsection"> 1.2.1</navmark>
Tachyglossidae</text>
</navLabel>
<content src="mwech1.html#x3-80001" /> </navPoint>
<navPoint id="navPoint-10" playOrder="10">
<navLabel>
<text><navmark type="subsection"> </navmark> 1.2.1
Tachyglossidae</text>
</navLabel>
<content src="mwech1.html#Q1-3-14" />
</navPoint>
</navPoint>
</navPoint>
</navPoint>
</navMap>
</ncx>
答案1
尝试这个版本titlesec.4ht
:
% titlesec.4ht (2020-11-20-14:29), generated from tex4ht-4ht.tex
% Copyright 2000-2009 Eitan M. Gurari
% Copyright 2009-2020 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2020-11-20-14:29}
\ifx \ttl@assign@ii\:Undef
\ifx \ttl@sect\:UnDef\else
\pend:defII\ttl@sect{%
\@ifstar {}{\SkipRefstepAnchor}}
\let\ttl:select=\ttl@select
\def\ttl@select#1#2#3#4#5{%
\edef\sc:tp{\ifttl@label\else like\fi #1}\def\c:secnumdepth{#5}%
\ttl:select{#1}{#2}{#3}{#4}{#5}}
\let\ttl@write\:gobbleIII
\fi
\ifx \ttl@useclass\:UnDef\else
\pend:defII\ttl@useclass{%
\@ifstar {}{\SkipRefstepAnchor}}
\let\ttl:select\ttl@select
\def\ttl@select#1{%
\edef\sc:tp{\ifttl@label\else like\fi
#1}\def\c:secnumdepth{\@nameuse{ttll@#1}}%
\ttl:select{#1}}
\let\ttl@write\:gobbleII
\let\ttl@glcmds\relax
\let\ttl@beginlongest\@empty
\let\ttl@midlongest\@empty
\let\ttl@endlongest\@empty
\fi
\let\ttlh:hang\ttlh@hang
\def\ttlh@hang#1#2#3#4#5#6#7#8{%
\HtmlEnv
\expandafter\def\csname thetitle\sc:tp\endcsname{#2}%
\csname no:\sc:tp\endcsname{#8}%
\par \ttlh:hang{}{}{#3}{}{}{#6}{#7}{}}
\let\:seccntformat=\@seccntformat
\def\@seccntformat#1{\ifnum 0=0\the\csname c@#1\endcsname\else
\:seccntformat{#1}\fi}
\else
\let\ttl:straight@i\ttl@straight@i
\def\ttl@straight@i#1[#2]#3{%
\gdef\NR:Title{\a:newlabel{#3}}%
%
\ifttl@label \else
\def\:temp{#1}\edef\:tempa{\expandafter
\expandafter\expandafter\:gobble
\expandafter\string\csname section\endcsname}\ifx \:temp\:tempa \else
\edef\:tempa{\expandafter\expandafter\expandafter\:gobble
\expandafter\string\csname subsection\endcsname}\ifx \:temp\:tempa \else
{\ttl@labeltrue \ttl@addcontentsline{like#1}{#3}}%
\fi
%
\fi
%
\fi
\edef\sc:tp{\ifttl@label\else like\fi #1}%
\ttl:straight@i{#1}[{#2}]{#3}%
}
\def\ttlh@hang#1#2#3#4#5#6#7#8{%
\def\c:secnumdepth{\@nameuse{ttll@\sc:tp}}%
\:StartSec {\sc:tp}{%
\ifttl@label \ifnum \c:secnumdepth >\c@secnumdepth
\else \csname the\sc:tp\endcsname \fi \fi
}{#8}%
}
\def\:tempc#1#2#3#4{%
\begingroup
\let\everypar\@gobble% don't let titlesec to break our paragraph handling
\edef\sc:tp{\ifttl@label\else like\fi #1}%
\let\ttl@savewrite\empty
\o:ttl@select:{#1}{#2}{#3}{#4}
\endgroup
}
\HLet\ttl@select\:tempc
\let\ttlh@runin\ttlh@hang
\let\ttlh@display\ttlh@hang
\fi
\def\ttl@addcontentsline#1#2{%
\nobreak}
\Hinput{titlesec}
\endinput
Titlesec 似乎将每个节或小节(而不是章节或部分)明确添加到目录中,但 TeX4ht 也这样做,因此您会得到重复的条目。
我们可以使用以下重新定义来禁用将它们添加到 TOC 的 Titlesec 代码:
\def\ttl@addcontentsline#1#2{%
\nobreak}