如何使用 imakeidx 和 splitindex 在 srcbook 中生成适当的索引?

如何使用 imakeidx 和 splitindex 在 srcbook 中生成适当的索引?

我使用 lipsum 为我的书生成了 MWE。编译很顺利,但并未生成所需的四个索引。我错过了什么?

\documentclass[ngerman,12pt,a4paper]{scrbook}
\usepackage[export]{adjustbox}
\usepackage[ngerman]{babel}
\usepackage[%
paperheight=297mm, paperwidth=210mm%
]{geometry}
\usepackage[]{lipsum}
\usepackage[T1]{fontenc}
\usepackage{Alegreya}
\usepackage{graphicx}
\usepackage{enumitem,longtable,caption,tabularx,xcolor,multirow}
\usepackage[splitindex]{imakeidx}
\usepackage{xparse, setspace}
\usepackage{ragged2e}
\setkomafont{descriptionlabel}{\normalfont  \bfseries}
\newcommand{\leer}{\relax}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{P}[1]{>{\arraybackslash}m{#1}}
\newcommand{\tcg}[1]{\textcolor{gray}{#1}}
\DeclareTextFontCommand{\textsemibold}{\AlegreyaMedium}
\DeclareTextFontCommand{\textblack}{\AlegreyaBlack}
\DeclareTextFontCommand{\textextrabold}{\AlegreyaExtraBold}
\newcommand{\RRar}{\RaggedRight\arraybackslash}
\newcommand{\ScN}[1]{\textsemibold{\textit{#1}}}%Scientic Names
\newcommand{\BTS}[2]{\ScN{#1 #2\index[sci]{#1!#2|boldhyperpage}\index[sci]{#2}}} %Index Scientific wenn mehrere Falter in einer Gattung
\newcommand{\BTSone}[2]{\ScN{#1 #2\index[sci]{#1 #2|boldhyperpage}\index[sci]{#2}}} %Index Scientific wenn ein Falter in einer Gattung
\newcommand{\bts}[2]{\index[sci]{#1!#2|boldhyperpage}\index[sci]{#2}}
\newcommand{\btsone}[2]{\index[sci]{#1 #2|boldhyperpage}\index[sci]{#2}}
\newcommand{\Bts}[1]{\ScN{#1 \index[sci]{#1|boldhyperpage}}} %Index Scientific wenn nur ein Falter aus der Gattung
\newcommand{\BTD}[1]{#1\index[dt]{#1|boldhyperpage}} %Index deutsch
\newcommand{\Btd}[1]{\index[dt]{#1|boldhyperpage}} %Index deutsch
\newcommand{\PFL}[3]{#1#2\index[pfl]{#2!#1!#3}\index[pflinv]{#3!#2!#1}}
\newcommand{\pfl}[3]{\index[pfl]{#2!#1!#3}\index[pflinv]{#3!#2!#1}} % für die unter "u.a." erwähnten
\usepackage{array}
\ExplSyntaxOn\makeatletter
\renewcommand*\subitem{\peek_meaning_ignore_spaces:NF\relax{\@idxitem \hspace*{20\p@}}}
\renewcommand*\subsubitem{\peek_meaning_ignore_spaces:NF\relax{\@idxitem \hspace*{40\p@}}}
\ExplSyntaxOff\makeatother
\setlength{\tabcolsep}{2mm}
\makeindex[name=sci, title=Wissenschaftliche Namen, columns=3]
\makeindex[name=dt, title=Deutsche Namen]
\makeindex[name=pfl, title=Raupenwirtspflanzen (nach Pflanzen sortiert), columns=2]
\makeindex[name=pflinv, title= Raupenwirtspflanzen (nach Faltern sortiert), columns=3]
\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}
\DeclareDocumentCommand\mychapter{sO{#3}m}{%
    \IfBooleanTF{#1}%
    %   {\chapter*{#3}\renewcommand*{\chapterthumbformat}{#3}}%
    %   {\chapter[{#2}]{#3}\renewcommand*{\chapterthumbformat}
        {\thechapter\enskip#2}}%
    %   }
\begin{document}    
    \newpage
\begin{longtable}{@{}p{5.8cm}@{}p{1cm}@{\hspace{3mm}}p{5.8cm}@{}p{1cm}@{}}%Argynni
    \multicolumn{4}{@{}p{10.8cm}@{}}{\large\textbf{Argynni -- Perlmutterfalter}}
    \\[2mm]
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.8cm]{example-image-duck}}
    &
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.8cm]{example-image-duck}}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Kaisermantel}} & \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Großer Perlmutterfalter}} 
    \\
    \BTSone{Argynnis}{paphia}\label{argynnispaphia} & RL=*  & \BTSone{Speyeria}{aglaja}\label{speyeriaaglaja}  & RL=*
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}}
    &
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}} 
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{Veilchen-Arten\pfl{\relax}{Veilchen}{Argynnis paphia}           
    } 
    & 
    \multicolumn{2}{@{}p{5.3cm}@{}}{Veilchen-Arten\pfl{Rauhaariges }{Veilchen}{Speyeria aglaja}\pfl{Hunds-}{Veilchen}{Speyeria aglaja}\pfl{Wald-}{Veilchen}{Speyeria aglaja}\pfl{Sumpf-}{Veilchen}{Speyeria aglaja}         
    }
    \\[1mm]
    
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.8cm]{example-image-duck}}
    &
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.8cm]{example-image-duck}}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Feuriger Perlmutterfalter}} & \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Mittlerer Perlmutterfalter}} 
    \\
    \BTS{Fabriciana}{adippe}\label{fabricianaadippe} & \textbf{RL=V}  & \BTS{Fabriciana}{niobe}\label{fabriciananiobe}  & \textbf{RL=3}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}}
    &
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}} 
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{Veilchen-Arten\pfl{\relax}{Veilchen}{Fabriciana adippe}
    } 
    & 
    \multicolumn{2}{@{}p{5.3cm}@{}}{Veilchen-Arten\pfl{\relax}{Veilchen}{Fabriciana niobe}
    }            
    \\
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.8cm]{example-image-duck}}
    &
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.8cm]{example-image-duck}}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Kleiner Perlmutterfalter}} & \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Natternwurz-Perlmutterfalter}} 
    \\
    \BTS{Issoria}{lathionia}\label{issorialathonia} & \textbf{RL=V}  & \BTS{Boloria}{titania}\label{boloriatitania} & \textbf{RL=3} 
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}}
    &
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{Acker-}{Stiefmütterchen}{Issoria lathonia}}  &
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{Wiesen-}{Knöterich}{Boloria titania}}
    \\[1mm]
    
\end{longtable}
\newpage
\begin{longtable}{@{}p{5.8cm}@{}p{1cm}@{\hspace{3mm}}p{5.8cm}@{}p{1cm}@{}}%Argynni
    \multicolumn{4}{@{}p{14cm}@{}}{\large\textbf{Argynni (2)}}
    \\[2mm]
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.2cm]{example-image-duck}}
    &
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.2cm]{example-image-duck}}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Hochmoor-Perlmutterfalter}} & \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Silberfleck-Perlmutterfalter}} 
    \\
    \BTS{Boloria}{aquilonaris}\label{boloriaaquilonaris} & \textbf{RL=3}  & \BTS{Boloria}{euphrosyne}\label{boloriaeuphrosyne}  & \textbf{RL=V}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}}
    &
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}} 
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{Gemeine }{Moosbeere}{Boloria aquilonaris}} 
    & 
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{\relax}{Veilchen}{Boloria euphrosyne}}
    \\[1mm]
    
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.2cm]{example-image-duck}}
    &
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.2cm]{example-image-duck}}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Randring-Perlmutterfalter}} & \multicolumn{2}{@{}p{5.8cm}@{}}{\BTD{Braunfleckiger Perlmutterfalter}} 
    \\
    \BTS{Boloria}{eunomia}\label{boloriaeunomia} & \textbf{RL=3}  & \BTS{Boloria}{selene}\label{boloriaselene}  & \textbf{RL=V}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}}
    &
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}} 
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{Wiesen-}{Knöterich}{Boloria eunomia}} 
    & 
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{\relax}{Veilchen}{Boloria selene}}          
    \\[1mm]
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.3cm]{example-image-duck}}
    &
    \multicolumn{2}{@{}p{6cm}@{}}{\includegraphics[width=5.3cm]{example-image-duck}}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Mädesüß-Perlmutterfalter}} & \multicolumn{2}{@{}p{5.3cm}@{}}{\BTD{Magerrasen-Perlmutterfalter}} 
    \\
    \BTSone{Brenthis}{ino}\label{brenthisino} & \textbf{RL=V}  & \BTS{Boloria}{dia}\label{boloriadia}  & \textbf{RL=3}
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}}
    &
    \multicolumn{2}{@{}p{5.3cm}@{}}{\includegraphics[height=3mm]{example-image-a}} 
    \\
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{\relax}{Mädesüß}{Brenthis ino} und \PFL{Großer }{Wiesenknopf}{Brenthis ino}} 
    & 
    \multicolumn{2}{@{}p{5.3cm}@{}}{\PFL{\relax}{Veilchen}{Boloria dia}}
    \\[1mm]
    
\end{longtable}

\part{Anhang}
\chapter[Index]{Stichwortverzeichnisse}
\footnotesize
\printindex[sci]
\printindex[dt]
\printindex[pfl]
\end{document}```

答案1

未制定指数的原因有两个。

  1. 具体来说,当 imakeidx 调用时带有 splitindex 选项,如 中所示\usepackage[splitindex]{imakeidx},latexmk 目前无法检测到运行 makeindex 的需要。这与省略 splitindex 选项或使用其他包创建索引的情况不同。

  2. 此外,使用 splitindex 选项时,需要运行 splitindex 程序来创建单独的索引。

第一个问题通过在文档顶部添加以下行来解决:

\typeout{Writing index file \jobname.idx}

这是 latexmk 用于检测索引是否存在的标准签名。(从 v. 4.84 开始,latexmk 将改进其对索引文件创建的检测,并且不再需要此技巧。)

第二个问题通过 latexmkrc 文件中的以下代码解决:

$makeindex = 'internal splitindex2 %S %D %R %B %O';
$clean_ext .= " %R-*.ind %R-*.idx %R-*.ilg %R-*.ind";

sub splitindex2 {
  # Use splitindex instead of makeindex.
  # The splitindex programe starts from an .idx file, makes a set of
  #   other .idx files for separate indexes, and then runs makeindex to
  #   make corresponding .ind files.
  # However, it is possible that the document uses the splitindex
  #   package, but in a way compatible with the standard methods
  #   compatible with makeindex, i.e., with a single index and with the
  #   use of the \printindex command.
  #   Then we need to invoke makeindex.
  # In addition, latexmk assumes that makeindex or its replacement makes
  #   an .ind file from an .idx file, and latexmk gives an error if it
  #   doesn't exist, so we need to make an .ind file.
  # Both problems are solved by running makeindex and then splitindex.
  # Note: errors are returned by makeindex and splitindex for things
  #   like a missing input file.  No error is returned for lines in an
  #   input file that are in an incorrect format; they are simply
  #   ignored.  So no problem is caused by lines in the .idx file
  #   that are generated by splitindex in a format incompatible with
  #   makeindex.
  my ($source, $dest, $root, $base, @opts) = @_;
  my $ret1 = system( "makeindex", $source );
  my $ret2 = system( "splitindex", $source );
  return $ret1 || $ret2;
}

相关内容