tex4ebook 和 xindy 的索引项中的重音字符错误(Texlive 2020)

tex4ebook 和 xindy 的索引项中的重音字符错误(Texlive 2020)

这是我上一个问题的后续这里。我正在使用 texlive 2020 并使用@Michal.h21 提供的文件。

我已经修改了输入文件sample.tex。

\documentclass[ebook,12pt,oneside,openany]{memoir}

\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

\chapter{C2}

bword\index{bword}

\index{Muller@M\"{u}ller}

\lipsum \newpage

zword\index{zword}

\backmatter

\printindex

\end{document}

配置和构建文件与上一个问题相同,并再次由@Michal.h21 提供。

电子书.cfg:

% save the clearpage before it is redefined by tex4ht
\let\oldclrearpage\clearpage
% define macro for newpage insertion
\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}}
%
\Preamble{xhtml}
\CutAt{section}
%
% enforce newpage
%
% define it for \newpage
%
\mypagebreak
\Css{.newpage{page-break-before:always;}}
% modify \Configure{BODY} so our confiurations work on all extracted pages
\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}}
\Configure{@/BODY}{\global\let\clearpage\oldclrearpage\Configure{newpage}{}}
\begin{document}
\EndPreamble

构建.mk4

Make:add("biber","biber ${input}")
Make:add("xindy", function(par)
  -- par.encoding  = par.encoding or "utf8"
  -- par.language = par.language or "english"
  par.idxfile = par.idxfile or par.input .. ".idx"
  local modules = par.modules or {}
  local t = {}
  for k,v in ipairs(modules) do
    t[#t+1] = "-M ".. v
  end
  par.moduleopt = table.concat(t, " ")
  local xindy_call = "xindy -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par
  print(xindy_call)
  return os.execute("xindy -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par)
end, {modules = {"texindy"}, language = "english", encoding = "utf8"})

if mode=="draft" then
  Make:htlatex {}
else
 Make:htlatex {}
 Make:biber {}
 -- xindymodule = Make.params["input"]
 Make:xindy {modules = {"sample"}}
 Make:htlatex {}
 Make:htlatex {}
 Make:htlatex {}
end

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-trace :on)
;; ignore group headers
;;markup-letter-group :open "% ")
;;
(markup-index :open  "\begin{theindex}~n
 \providecommand*\lettergroupDefault[1]{}
 \providecommand*\lettergroup[1]{%
 \par}"
          :close "~n~n\end{theindex}~n"
          :tree)
;;
(markup-keyword :open "\idxkeyword{" :close "}" )
(markup-locref :open "\idxlocator{" :close "}")
(markup-locref :open "\textrm{\idxlocator{" :close "}}"  :attr "textrm")
(markup-locref :open "\textrm{\idxlocator{" :close "}}"  :attr "definition")
;;
;; change style of index entries
;;(markup-locclass-list :open "\dotfill " :sep ", ")
(markup-locclass-list :open "\ \ \ ")
(markup-locref-list :sep ", ")
\end{filecontents*}

Muller 的索引项未正确生成 - 见下图。

来自 tex4ebook 的索引

tex4ebook 运行出现错误。

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=latex)
 \write18 enabled.
entering extended mode
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename Line    Message
[ERROR]   htlatex: ./ebook.cfg  40   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  40   LaTeX Error: Missing \begin{document} in `ebook.cfg'.
[ERROR]   htlatex: ./ebook.cfg  40   Extra \endcsname.
[ERROR]   htlatex: ./ebook.cfg  40   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  40   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  40   Extra \endcsname.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Extra \endcsname.
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=latex)
 \write18 enabled.
entering extended mode
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename Line    Message
[ERROR]   htlatex: ./ebook.cfg  43   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  43   LaTeX Error: Missing \begin{document} in `ebook.cfg'.
[ERROR]   htlatex: ./ebook.cfg  43   Extra \endcsname.
[ERROR]   htlatex: ./ebook.cfg  43   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  43   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  43   Extra \endcsname.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Extra \endcsname.
--- warning --- Ignoring \special{t4ht.html}

pdflatex 运行的索引是正确的。

几年前 tex4ebook 运行正常,但现在却不能了。

有什么办法可以解决这个问题吗,谢谢?

使用来自@Michal.h21 的 build.mk4 进行更新。

我收到索引错误并且没有生成索引。

tex4ebook 运行中出现错误:

This is LuaTeX, Version 1.12.0 (TeX Live 2020/W32TeX)
 restricted system commands enabled.
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename Line    Message
[ERROR]   htlatex: ./sample.ind [15 5    Extra }, or forgotten $.
[ERROR]   htlatex: ./sample.ind [15 9    Missing $ inserted.
[ERROR]   htlatex: ./sample.ind [15 13   Missing } inserted.

样本.idx

\beforeentry{samplech1.html}{dx3-2001}{}
\indexentry{aword}{3}
\beforeentry{samplech2.html}{dx4-3001}{}
\indexentry{bword}{9}
\beforeentry{samplech2.html}{dx4-3002}{}
\indexentry{Muller@M\"{u}ller}{9}
\beforeentry{samplech2.html}{dx4-3003}{}
\indexentry{zword}{13}

样品信息

\begin{theindex}
\indexspace
\textbf{A}\label{L-xindex-A}
\nopagebreak[4]
  \item aword, {\Link[]{dx3-2001}{}1\EndLink{}}
\indexspace
\textbf{B}\label{L-xindex-B}
\nopagebreak[4]
  \item bword, {\Link[]{dx4-3001}{}2\EndLink{}}
\indexspace
\textbf{M}\label{L-xindex-M}
\nopagebreak[4]
  \item M\({u}ller, {\Link[]{dx4-3002}{}3\EndLink{}}
\indexspace
\textbf{Z}\label{L-xindex-Z}
\nopagebreak[4]
  \item zword, {\Link[]{dx4-3003}{}4\EndLink{}}
\end{theindex}

更新 2:

电子书仍存在两个问题。

索引未显示在目录中,并且索引中的链接无处可去 - 请参阅下文。

电子书

pdf 文件中的目录是正确的,并且链接有效 - 见下文。

pdf

有什么方法可以解决这个问题,谢谢。

更新 3:

索引现在使用新的 imakeidx.4ht 显示在目录中。

我在构建文件中添加了一行代码以使链接正常工作。现在

if mode=="draft" then
 Make:htlatex {}
else
  Make:htlatex {}
  Make:xindy {modules={"utf8-lang"}}
  Make:biber {}
  Make:htlatex {}
  Make:xindy {modules={"utf8-lang"}}
  Make:htlatex {}
end

这是最好或者最有效的方法吗?

我也像上面一样将 xindy 模块更改为 utf8-lang,并添加了一行新行

S\'{e}an\index{Sean@S\'{e}an}

在输入文件中,它也起作用了。这是处理来自

https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes

而不只是德国的吗?

索引中还有一个小问题。“aword”和“B”标题之间缺少一个空格:

新指数

谢谢。

答案1

make4ht我已经更改了和中的索引支持tex4ebook,因此您不再需要使用imakeindex.4ht。您可以删除它。相反,可以使用内置的 TeX4ht 索引支持。

build.mk4文件看起来如下:

if mode=="draft" then
  Make:htlatex {}
else
  Make:htlatex {}
  Make:xindy {modules={"duden-utf8"}}
  Make:biber {}
  Make:htlatex {}
  Make:htlatex {}
end

命令Make:xindy是内置make4ht命令。还有Make:xindexMake:makeindex命令。请参阅make4ht 文档更多细节。

这是 Epub 文件中的结果索引,使用以下方法编译

tex4ebook -l -c epub.cfg -e build.mk4 filename.tex

在此处输入图片描述

现在每个术语都有不同的编号,因此索引包含所有使用的术语。这与之前的版本不同,之前的版本中的术语是按章节编号排序的。

编辑:

对于intoc选项 imakeidx 支持,请尝试以下版本imakeidx.4ht

% imakeidx.4ht (2020-05-18-14:06), generated from tex4ht-4ht.tex
% Copyright 2019 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-05-18-14:06}


\def\:temp#1#2#3{\html:addr%
\hbox{\Link-{}{dx\last:haddr
}\EndLink}%
\expandafter\protected@write\csname#1@idxfile\endcsname{}%
{\string\beforeentry{\RefFileNumber\FileNumber}{dx\last:haddr
}{\a:makeindex}}%
\o:imki@wrindexentrysplit:{#1}{#2}{#3}%
}
\HLet\imki@wrindexentrysplit\:temp

\ifx \a:makeindex\:UnDef
\NewConfigure{makeindex}{}\Configure{makeindex}{}
\fi
\Configure{@begin}{theindex}{\ind:defs\imki@maybeaddtotoc}



\Hinput{imakeidx}
\endinput

我已经更新了 TeX4ht 源,因此它很快就能在任何地方运行。

相关内容