texindy 样式文件:在分组条目之间添加空格

texindy 样式文件:在分组条目之间添加空格

感谢许多伟大的特辛迪在 stackexchange 上的问题,我有伊玛克在内部很好地工作赛莱特使用分裂指数和定制辛迪样式文件。但是,我遇到了一个格式问题,我从未在任何地方找到过这个问题或描述。

我有一个索引,其中所有术语都归入少数 (~7) 个标题下。当这些标题以不同的字母开头时,它们在组之间会有一些额外的空间。但是,如果标题以相同的字母开头,则没有额外的空间(参见下面的示例图像和代码)。

我的问题是,如何修改我的通用样式.xdy文件来在主要条目之间获取额外的空间?

我不想在子元素之间留出额外的空间,我只想要一致的格式,而某些组之间缺少空间看起来很尴尬。我意识到我可以使用不太优雅的方法,例如

\index{B@\textbf{\large Danish Tales}|nopage}
\index{C@\textbf{\large Danish Titles}|nopage}

代替

\index{danish@\textbf{\large Danish Tales}|nopage}
\index{danish titles@\textbf{\large Danish Titles}|nopage}

迫使 xindy 认为这些是列在不同的字母下。或者,我甚至可以将“丹麦语”和“丹麦标题”定义为单独的字母使用特殊排序规则西迪文件(比我想要处理的痛苦得多),但这一切感觉如此被黑客入侵而且很丑陋。肯定有一个简单的方法可以简单地定义主组条目,即使在同一个字母下,也应该有一个额外的空间?(请记住,我对 xindy/texindy/imakeidx 还很陌生 - 到目前为止,我只使用它们 1 周......)

无论如何,这是我的工作示例。它是从一份非常大的文档中摘录出来的,因此如果它不够精简,请见谅。

首先,.tex文件:

% !TEX TS-program = xelatex 
% !TEX encoding = UTF-8
% this allows us to use real characters like æ instead of macros like \ae

%% PREAMBLE

%Set the document type
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

%Provide standard TeX shortcuts in xelatex
\usepackage{xunicode}
%Extra customizations for XeLateX
\usepackage{xltxtra}

%XeLateX can't use babel, so use polyglossia instead
%(primarily to get proper hyphenation in the other languages)
\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
\setotherlanguages{icelandic,danish,norsk,swedish}

%Setup the indexing
\usepackage[xindy,splitindex]{imakeidx}
%default index 
\makeindex[title=Index of Tale Information,program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]
%I want to suppress page number on group headings, define \noidxpage so it eats the argument
%the idstyle.xdy defines the formatting option nopage = \noidxpage
\newcommand{\noidxpage}[1]{}

\begin{document}

    \mainmatter

    Dummy text here (really several chapters with lots of stuff indexed\ldots)

    %setup the category headers
    \index{danish@\textbf{\large Danish Tales}|nopage}
    \index{icelandic@\textbf{\large Icelandic Tales}|nopage}
    \index{danish titles@\textbf{\large Danish Titles}|nopage}
    \index{icelandic titles@\textbf{\large Icelandic Titles}|nopage}
    \index{collectors@\textbf{\large Collector}|nopage}
    \index{storytellers@\textbf{\large Storyteller}|nopage}
    \index{location@\textbf{\large Location Collected}|nopage}

    %dummy index info to show what I see
    \index{danish!Jesper the Rabbit Herder}
    \index{danish titles!Jesper Harehyrde}
    \index{collectors!Kristensen, Evald Tang}
    \index{storytellers!Futtrup, Rasmus}
    \index{location!DK, Lemvig}
    \index{danish!The Little Horse}
    \index{danish titles!Det Lille Øg}
    \index{collectors!Grundtvig, Svend}
    \index{storytellers!Krag-Juel-Vind, Elisa}
    \index{location!DK, Horsens}
    \index{icelandic!Mori, the Hound}
    \index{icelandic titles!Hundurinn Móri}
    \index{collectors!Árnason, Jón}
    \index{icelandic!Bukolla}
    \index{icelandic titles!Búkolla}
    \index{collectors!Einarsson, Magnús}
    \index{storytellers!Renessee, Ingibjörg}
    \index{storytellers!Skúlason, Hrund}
    \index{storytellers!Þorgrímsson, Sigrún}


    %Create the index
    \printindex

\end{document}

这是辛迪样式文件:

;Allow removing page numbers (e.g. for group headings)
;   this requires putting the comma in the default formatting
;   of the page number so that the default seperator is blank
(define-attributes (("nopage")) )
(markup-locref :attr "nopage" :open "\noidxpage{" :close "}")
(markup-locref :attr "default" :open ", \textbf{" :close "}")
;
;(markup-locclass-list :open "\dotfill " :sep ", ")
(markup-locclass-list :open "" :sep "")
;
;(markup-locref-list   :sep ", ")
(markup-locref-list   :sep "")
;
(markup-range :sep "--")


(markup-index :open  "\begin{theindex}~n
 \providecommand*\lettergroupDefault[1]{}
 \providecommand*\lettergroup[1]{%
   \nopagebreak
  }"
          :close "~n~n\end{theindex}~n"
          :tree)


;; The indexentries (item_<..> specifiers)

(markup-indexentry :open "~n  \item "           :depth 0)
(markup-indexentry :open "~n    \subitem "     :depth 1)
(markup-indexentry :open "~n      \subsubitem " :depth 2)

这是结果索引的图像:

包含多个主要分组的索引

答案1

第一个解决方案: 您会看到使用您的代码生成的 .ind 文件如下所示:

\begin{theindex}

 \providecommand*\lettergroupDefault[1]{}
 \providecommand*\lettergroup[1]{%
   \nopagebreak
  }
  \lettergroup{C}
  \item \textbf{\large Collector}\noidxpage{1}
    \subitem Árnason, Jón, \textbf{1}
    \subitem Einarsson, Magnús, \textbf{1}
    \subitem Grundtvig, Svend, \textbf{1}
    \subitem Kristensen, Evald Tang, \textbf{1}

  \indexspace

  \lettergroup{D}
  \item \textbf{\large Danish Tales}\noidxpage{1}
    \subitem Jesper the Rabbit Herder, \textbf{1}
    \subitem The Little Horse, \textbf{1}
  \item \textbf{\large Danish Titles}\noidxpage{1}
    \subitem Det Lille Øg, \textbf{1}
    \subitem Jesper Harehyrde, \textbf{1}

字母组之间有一个\indexspace命令(在 book.cls 中定义)。你想要的是每个 之间都有一个垂直空格item,因为你不会为字母组打印任何内容。因此,解决方案可以是在每个 之后添加一个垂直空格item,修改你的样式文件:

...
;; The indexentries (item_<..> specifiers)

(markup-indexentry  :open "~n  \item "           
                    :close "\bigskip"
                    :depth 0)
(markup-indexentry :open "~n    \subitem "     :depth 1)
(markup-indexentry :open "~n      \subsubitem " :depth 2)

:close\itemmarkup-indexentry 添加了参数。您得到的结果是:

\begin{theindex}

 \providecommand*\lettergroupDefault[1]{}
 \providecommand*\lettergroup[1]{%
   \nopagebreak
  }
  \lettergroup{C}
  \item \textbf{\large Collector}\noidxpage{1}
    \subitem Árnason, Jón, \textbf{1}
    \subitem Einarsson, Magnús, \textbf{1}
    \subitem Grundtvig, Svend, \textbf{1}
    \subitem Kristensen, Evald Tang, \textbf{1}\bigskip

  \indexspace

  \lettergroup{D}
  \item \textbf{\large Danish Tales}\noidxpage{1}
    \subitem Jesper the Rabbit Herder, \textbf{1}
    \subitem The Little Horse, \textbf{1}\bigskip
  \item \textbf{\large Danish Titles}\noidxpage{1}
    \subitem Det Lille Øg, \textbf{1}
    \subitem Jesper Harehyrde, \textbf{1}\bigskip

  \indexspace

\bigskip但是你看到在字母组之后添加了你的\indexspace。所以你必须删除\indexspace字母组之后的效果。你可以修改你的样式文件:

;Allow removing page numbers (e.g. for group headings)
;   this requires putting the comma in the default formatting
;   of the page number so that the default seperator is blank
(define-attributes (("nopage")) )
(markup-locref :attr "nopage" :open "\noidxpage{" :close "}")
(markup-locref :attr "default" :open ", \textbf{" :close "}")
;
;(markup-locclass-list :open "\dotfill " :sep ", ")
(markup-locclass-list :open "" :sep "")
;
;(markup-locref-list   :sep ", ")
(markup-locref-list   :sep "")
;
(markup-range :sep "--")


(markup-index :open  "\begin{theindex}~n
 \providecommand*\lettergroupDefault[1]{}
 \providecommand*\lettergroup[1]{%
   \nopagebreak}
   \let\oldindexspace\indexspace
   \def\indexspace{}
  "
          :close "~n~n\end{theindex}~n"
          :tree)


;; The indexentries (item_<..> specifiers)

(markup-indexentry  :open "~n  \item "           
                    :close "\oldindexspace"
                    :depth 0)
(markup-indexentry :open "~n    \subitem "     :depth 1)
(markup-indexentry :open "~n      \subsubitem " :depth 2)

\indexspace您保存了in的定义\oldindexspace,然后“清除”它。现在,每个字母后面都有垂直空格,item字母组后面没有空格。

在此处输入图片描述

第二种解决方案: 如果您有很多条目,您可以考虑使用 imakeidx 功能为每个“系列”创建一个单独的索引:

% !TEX TS-program = xelatex 
% !TEX encoding = UTF-8
% this allows us to use real characters like � instead of macros like \ae

%% PREAMBLE

%Set the document type
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

%Provide standard TeX shortcuts in xelatex
\usepackage{xunicode}
%Extra customizations for XeLateX
\usepackage{xltxtra}

%XeLateX can't use babel, so use polyglossia instead
%(primarily to get proper hyphenation in the other languages)
\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
\setotherlanguages{icelandic,danish,norsk,swedish}

%Setup the indexing
\usepackage[xindy,splitindex]{imakeidx}


\newcommand{\noidxpage}[1]{}

\makeindex[name=collector,title=Collector, program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]
\makeindex[name=danishta, title=Danish Tales ,program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]
\makeindex[name=danishtit, title=Danish Titles, program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]
\makeindex[name=icelandicta, title= Icelandic Tales, program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]
\makeindex[name=icelandictit, title= Icelandic Titles, program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]
\makeindex[name=location, title=Location Collected, program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]
\makeindex[name=storyteller, title=Storyteller, program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]

\begin{document}
\mainmatter
Dummy text here (really several chapters with lots of stuff indexed\ldots)

 %dummy index info to show what I see
\index[danishta]{Jesper the Rabbit Herder}
\index[danishtit]{Jesper Harehyrde}
\index[collector]{Kristensen, Evald Tang}
\index[storyteller]{Futtrup, Rasmus}
\index[location]{DK, Lemvig}
\index[danishta]{The Little Horse}
\index[danishtit]{Det Lille Øg}
\index[collector]{Grundtvig, Svend}
\index[storyteller]{Krag-Juel-Vind, Elisa}
\index[location]{DK, Horsens}
\index[icelandicta]{Mori, the Hound}
\index[icelandictit]{Hundurinn Móri}
\index[collector]{Árnason, Jón}
\index[icelandicta]{Bukolla}
\index[icelandictit]{Búkolla}
\index[collector]{Einarsson, Magnús}
\index[storyteller]{Renessee, Ingibjörg}
\index[storyteller]{Skúlason, Hrund}
\index[storyteller]{Þorgrímsson, Sigrún}

%Create the index
\printindex[collector]
\printindex[danishta]
\printindex[danishtit]
\printindex[icelandicta]
\printindex[icelandictit]
\printindex[location]
\printindex[storyteller]

\end{document}

结果是这样的几个索引:在此处输入图片描述

相关内容