這是我之前問題的後續這裡。
它使用@Michal.h21 提供的文件。我已將輸入檔修改如下:
\documentclass[ebook,12pt,oneside,openany]{memoir}
\begin{filecontents}{test.bib}
@book{Hiemenz,
author={Hiemenz},
title={Polymer Chemistry}
}
\end{filecontents}
\usepackage{lipsum}
\usepackage[backend=biber,hyperref=auto,backref=true]{biblatex}
\bibliography{test}
\usepackage{imakeidx}
\makeindex[intoc=true,columns=1,noautomatic]
\usepackage[hyperindex=true]{hyperref}
\title{Book}
\author{Author}
\date{}
\begin{document}
\maketitle
\frontmatter
\tableofcontents \newpage
\mainmatter
\chapter{C1}
aword\index{aword}
\lipsum \newpage
Here comes a quotation \cite{Hiemenz}.
\chapter{C2}
bword\index{bword}
\lipsum \newpage
\backmatter
\phantomsection
%\addcontentsline{toc}{chapter}{Bibliography}
\printbibliography \newpage
\phantomsection
\addcontentsline{toc}{chapter}{Index}
\indexprologue{Concepts}
\printindex
\end{document}
配置和建置檔案與上一個問題相同,並且再次由@Michal.h21提供。
主要問題是:
- \indexprologue 指令在 pdf 中正確處理:
但是,它在 tex4ebook 運行中被忽略。
我認為 intoc 選項和 \addcontentsline{toc}{chapter}{Index} 選項之間存在不一致的行為。 intoc 選項在 tex4ebook 運作中被忽略。
目錄中的索引連結指向空白頁而不是索引標題所在的位置。
pdf 文件中的內容是正確的。
- 在 makeindex 指令中使用自動選項不會產生超連結:
使用 noautomatic 選項有效。這不是一個大問題,但它與正常乳膠運行的行為不同,而且看起來很奇怪。
其他人是否遇到這些問題?
我懷疑這會落在@Michal.h21 身上,所以我會提前感謝他。
答案1
先前版本的imakeidx
套件配置沒有考慮到該套件的某些功能,它使用預設tex4ht
配置來處理 \printindex
命令。我們可以使用定義的修改版本imakeidx
來獲得對其中一些功能的支援。
這是文件的新版本imakeidx.4ht
:
\RequirePackage[]{etoolbox}
\RequirePackage{gettitlestring}
\newcounter{indexcnt}
\let\@Index\@index
\patchcmd{\@Index}{\@wrindex}{\@Wrindex}{}{}
\let\@Wrindex\@wrindex
\patchcmd{\@Wrindex}{\thepage}{\theindexcnt}{}{}
\let\xIndex\index
\patchcmd{\xIndex}{\@index}{\@Index}{}{}
\patchcmd{\xIndex}{\@index}{\@Index}{}{}
\pretocmd{\xIndex}{\@stepindexcnt\@indexanchor}
% \patchcmd{\index}{\@index}{\@Index}{}{}
% \patchcmd{\xIndex}{\@index}{\@Index}{}{}
% \let\protected@iwrite\protected@write
% \let\@index\@Index
% \patchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
\patchcmd{\@Wrindex}{\protected@write}{\protected@iwrite}{}{}
\let\Index\xIndex
\let\index\xIndex
%\show\Index
\newcommand\@indexanchor{%
\edef\idx@anch{idx-anch\theindexcnt}%
\Link[]{}{\idx@anch}\EndLink%
%\Ref{(idx-link-\idx@anch)}{\FileName/\idx@anch}
}
\newcommand\@stepindexcnt{\stepcounter{indexcnt}}
\newcommand\hello[1]{\@hello#1}
\def\@hello#1/{%
\Link{idx-anch#1}{}#1\EndLink%
}
\GetTitleStringSetup{expand}
\GetTitleStringDisableCommands{%
\renewcommand\LaTeX{LaTeX}
}
\newcount\idxkwdcnt
\LinkCommand\IdxKWLink{span,href,id}
\newcommand\idxkeyword[1]{%
\global\advance\idxkwdcnt by 1\relax%
% use tags only one time
\GetTitleString{#1}
\ifcsdef{idxkw\GetTitleStringResult}{}%
%{\Tag{idxkw#1}{idxkw\the\idxkwdcnt}}%
{\expandafter\Tag\expandafter{idxkw\GetTitleStringResult}{idxkw\the\idxkwdcnt}}%
\csgdef{idxkw\GetTitleStringResult}{x}
\a:IdxKW{}{idxkw\the\idxkwdcnt}#1\b:IdxKW
}
\NewConfigure{IdxKW}{2}
\Configure{IdxKW}{\IdxKWLink}{\EndIdxKWLink}
\newcommand\idxlocator[1]{\Link{idx-anch#1}{}#1\EndLink}%
\renewenvironment{theindex}%
{\imki@maybeaddtotoc
% \imki@indexlevel{\indexname}\imki@indexheaders
\imki@idxprologue
\global\let\imki@idxprologue\relax
\parindent\z@
\parskip\z@ \@plus .3\p@\relax
\raggedright
\let\item\@idxitem
\imki@othercode}
{%
}
\let\indexspace\relax
\ConfigureEnv{theindex}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="theindex">}}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}{}{}
\begin{filecontents*}{\jobname.xdy}
(define-attributes (("default" "definition" "textbf")))
( define-location-class "sec-num" :var
("arabic-numbers"
:sep "." "arabic-numbers"
:sep "." "arabic-numbers"
:sep "." "arabic-numbers"
:sep "." "arabic-numbers"
))
(require "texindy.xdy")
(markup-keyword :open "\idxkeyword{" :close "}" )
(markup-locref :open "\idxlocator{" :close "}")
(markup-locref :open "\textbf{\idxlocator{" :close "}}" :attr "textbf")
(markup-locref :open "\textbf{\idxlocator{" :close "}}" :attr "definition")
\end{filecontents*}
重要的變化是:
\renewenvironment{theindex}%
{\imki@maybeaddtotoc
% \imki@indexlevel{\indexname}\imki@indexheaders
\imki@idxprologue
\global\let\imki@idxprologue\relax
\parindent\z@
\parskip\z@ \@plus .3\p@\relax
\raggedright
\let\item\@idxitem
\imki@othercode}
{%
}
\let\indexspace\relax
\ConfigureEnv{theindex}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="theindex">}}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}{}{}
將\reneenwironment{theindex}
考慮到\indexprologue
TOC 支持,將在索引內容周圍\ConfigureEnv{theindex}
添加元素。<div class="theindex">
透過此更改,您不再需要\addcontentsline{toc}{chapter}{Index}
在文件中使用 TOC 中的連結正確連結到索引。
關於您的最後一個問題,automatic
選項imakeidx
不起作用,因為您在使用pdflatex
和 進行編譯時需要使用不同的選項tex4ht
。這就是xindy
從構建文件中調用的原因。另一個原因是 LaTeX 在每次 tex4ebook 運行中被多次調用,並且在每次調用中編譯索引是沒有意義的。