下面的 MWE 在生成的 PDF 中创建了带有页面超链接的索引。索引也出现在目录中。但是,生成的 epub 看起来tex4ebook
很棒,索引也出现了。但是,索引未列在我的目录中,并且其页面没有超链接。
\documentclass{memoir}
\let\ordinal\relax
\usepackage{makeidx}
\usepackage{hyperref}
\makeindex
\begin{document}
\tableofcontents*
\chapter{The First Chapter}
Here is some text.\index{text}
\chapter{The Second Chapter}
Here is some text.\index{text}
\backmatter
\printindex
\end{document}
答案1
TeX4ht 尚不支持 Memoir 的索引系统,下面是对此的修复memoir.4ht
:
% memoir.4ht (2021-01-29-14:14), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2021 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 2021-01-29-14:14}
\input book.4ht
\input verse.4ht
\input booktabs.4ht
\let\columnlines\empty
\let\rm\empty
\let\sf\empty
\let\tt\empty
\let\bf\empty
\let\it\empty
\renewcommand*{\@memoldfonterr}[3]{}
\renewcommand*{\@memoldfontwarn}[3]{}
\def\@chapter[#1]#2{%
\gHAdvance\:mpNum by 1
\HAssign\minipageNum=\:mpNum \relax
%
{\SkipRefstepAnchor \let\addcontentsline\:gobbleIII\no@chapter[#1]{}%
\global\let\f@rtoc\f@rtoc
\ifx\f@rtoc\empty\gdef\f@rtoc{#2}\fi
\global\let\f@rhdr\f@rhdr }%
\HtmlEnv \Toc:Title{\f@rtoc}\:chapter{#2}}
\def\:tempc{\@ifstar\o:tableofcontents:\o:tableofcontents:}
\HLet\tableofcontents\:tempc
\Def:Section\book{\thebook}{#1}
\NewConfigure{abstracttitle}{2}
\newenvironment{abstracttitle4ht}{\a:abstracttitle}{\b:abstracttitle\par\noindent}
% get rid of all extra <span> elements introduced by smaller font size
% \renewcommand{\abstracttextfont}{\normalfont}
% \renewcommand{\abstractnamefont}{\normalfont}
% use our dummy environment to insert tags around the abstract title
\renewcommand{\absnamepos}{abstracttitle4ht}
\NewConfigure{poemline}{2}
\NewConfigure{legend}{2}
\renewcommand\legend[1]{\a:legend #1\b:legend}
\@ifpackageloaded{hyperref}{%
\ifHy@hyperfootnotes
\Hy@hyperfootnotesfalse
\newcounter{Hfootnote}
\fi
}{}
\ifx \memgobble\:UnDef
\pend:defI\getthelinenumber{%
\let\sv:thepoemline\thepoemline
\pend:def\thepoemline{\a:poemline}%
\append:def\thepoemline{\b:poemline}}
\append:defI\getthelinenumber{\let\thepoemline\sv:thepoemline}
\else
\pend:defII\getthelinenumber{%
\let\sv:thepoemline\thepoemline
\pend:def\thepoemline{\a:poemline}%
\append:def\thepoemline{\b:poemline}}
\append:defII\getthelinenumber{\let\thepoemline\sv:thepoemline}
\let\no@Msect\M@sect
\NewConfigure{@sec @ssect}[1]{%
\def\rdef:sec##1{#1\csname no@##1\endcsname}}
\:CheckOption{sections-} \if:Option
\Configure{@sec @ssect}{}
\else
\Configure{@sec @ssect}{%
\let\sv:Sc\:Sc \let\sv:sect\@sect \let\sv:ssect\@ssect
\let\sv:Msect\M@sect
\let\:Sc\:gobble
\def\M@sect##1##2##3##4##5##6[##7][##8]##9{%
\ifx \o:@seccntformat:\:UnDef
\let\o:@seccntformat:\@seccntformat
\fi
\let\@seccntformat\:gobble
%
\let\M@sect\no@Msect \xdef\c:secnumdepth{##2}%
{\SkipRefstepAnchor \let\addcontentsline\:gobbleIII \let\mark\:gobble
\no@Msect{##1}{##2}{##3}{##4}{##5}{##6}[{##7}][{##8}]{}}%
\let\:Sc\sv:Sc \let\@sect\sv:sect \let\@ssect\sv:ssect
\let\M@sect\sv:Msect
%
\let\@seccntformat=\o:@seccntformat:
%
\HtmlEnv \Toc:Title{##8}\csname no:#1\endcsname{##9}}%
%
\def\@sect##1##2##3##4##5##6[##7]##8{%
\ifx \o:@seccntformat:\:UnDef
\let\o:@seccntformat:\@seccntformat
\fi
\let\@seccntformat\:gobble
%
\let\@sect\no@sect \xdef\c:secnumdepth{##2}%
{\SkipRefstepAnchor \let\addcontentsline\:gobbleIII \let\mark\:gobble
\no@sect{##1}{##2}{##3}{##4}{##5}{##6}[{##7}]{}}%
\let\:Sc\sv:Sc \let\@sect\sv:sect \let\@ssect\sv:ssect
\let\M@sect\sv:Msect
%
\let\@seccntformat=\o:@seccntformat:
%
\HtmlEnv \Toc:Title{##7}\csname no:#1\endcsname{##8}}%
%
\def\@ssect##1##2##3##4##5{%
\gdef\ssect:ttl{##5}%
%
\let\@ssect\no@ssect
{\def\addcontentsline####1####2####3{}%
\no@ssect{##1}{##2}{##3}{##4}{}}%
\let\:Sc\sv:Sc \let\@sect\sv:sect \let\@ssect\sv:ssect
\let\M@sect\sv:Msect
%
\HtmlEnv \csname :like#1\endcsname{##5}}%
\IgnorePar}
\fi
\fi
\def\:tempa#1|#2|#3\\{%
\html:addr\hbox{\Link-{}{dx\last:haddr}\EndLink}%
\expandafter\protected@write\csname \jobname @idxfile\endcsname{}{\string\beforeentry{\RefFileNumber\FileNumber}{dx\last:haddr}{}}%
\expandafter\protected@write\csname \jobname @idxfile\endcsname{}{\string\indexentry[\@idxfile]{#1}{\thepage}}%
\endgroup%
\@esphack%
}
\HLet\@@wrindexhyp\:tempa
\HLet\@@wrspindexhyp\:tempa
% we use make4ht's splitindex functionality, which produces .ind files in the form of \jobname-idxname.ind
\renewcommand{\printindex}[1][\jobname]{\@input@{\jobname-#1.ind}}
\Hinput{memoir}
\endinput
重要的部分是这样的:
\def\:tempa#1|#2|#3\\{%
\html:addr\hbox{\Link-{}{dx\last:haddr}\EndLink}%
\expandafter\protected@write\csname \jobname @idxfile\endcsname{}{\string\beforeentry{\RefFileNumber\FileNumber}{dx\last:haddr}{}}%
\expandafter\protected@write\csname \jobname @idxfile\endcsname{}{\string\indexentry[\@idxfile]{#1}{\thepage}}%
\endgroup%
\@esphack%
}
\HLet\@@wrindexhyp\:tempa
\HLet\@@wrspindexhyp\:tempa
% we use make4ht's splitindex functionality, which produces .ind files in the form of \jobname-idxname.ind
\renewcommand{\printindex}[1][\jobname]{\@input@{\jobname-#1.ind}}
它重新定义了用于将索引信息写入辅助文件的命令,插入超链接目标(这对于从索引链接回文本是必要的),并以所需的格式写入索引条目make4ht
。
索引不支持开箱即用,您需要明确调用索引命令在构建文件中。例如,您可以将以下代码保存为build.lua
:
Make:htlatex {}
Make:makeindex {}
Make:htlatex{}
最后一件事是将索引包含在目录中。您可以尝试此配置文件:
\Preamble{xhtml}
\begin{document}
\RenewDocumentCommand\tableofcontents{s}{\TableOfContents[part,likepart,chapter,likechapter,section,likesection,subsection,likesubsection]}
\EndPreamble
它重新定义\tableofcontents
命令来打印带星号的分段命令版本(感谢likechapter
等等)。
编译使用:
$ tex4ebook -c config.cfg -e build.lua sample.tex
这是最终的目录:
索引如下:
链接应该指向文本中的正确点。