使用 xindy 和 hyperref 索引条目的小写罗马数字

使用 xindy 和 hyperref 索引条目的小写罗马数字

考虑以下示例:

\documentclass{memoir}
\usepackage{makeidx}
\makeindex
%\usepackage[hyperindex=false]{hyperref}%doesn't help
\usepackage{hyperref} %commenting out this one would do.
\begin{document}
\frontmatter
Something\index{Something}. And something else\index{Something else}
\mainmatter
Something\index{Something}. And something else\index{Something else}
\printindex
\end{document}

以下是最小的 xindy 样式文件,将罗马页码格式化为小型大写字母:

(markup-locref :class "roman-page-numbers" :open  "\textsc{" :close "}")

$ xindy -M texindy -M scpages.xdy example.idx

当我注释掉它时,它有效hyperref

最低工作量示例

但是,使用 hyperref 罗马数字时,不会被格式化为小型大写字母:

在此处输入图片描述

我该如何让它工作hyperref

编辑:一种可能的解决方法是仅为构建索引而注释掉hyperref。一旦我对索引感到满意,我就可以再次将其注释掉,但我必须注释掉\makeindex不是运行 xindy,这意味着如果由于编辑我的项目而将某些条目推送到另一页,则不会自动反映在索引中。此外,在 pdf 中,页码将不可点击。对于打印,此解决方法已足够,并且至少hyperref适用于文件的其余部分,即 pdf 中前部和主要内容的单独页面范围。

编辑:

另一个临时的解决方法是在 -file 上运行一个 perl 单行程序.ind

perl -pi -e 's/(\\hyperpage{.*?})/\\textsc{$1}/g' myfile.ind

它封装了\hyperpage{[some number]}with的每个实例\textsc{}。这样就不需要hyperref在注释和注释之间切换,从而简化了构建过程。数字变得可点击,并且可以获得所需的罗马数字的小写字母。调用后可以方便地将此行添加到构建脚本中xindy

答案1

我建议使用一个可能的工具来实现你想要的。它定义了 3 种新的页码样式。它们不是我写的,但我记不清是谁写的了,可能是在我的要求下,为了解决一些旧式排版问题。

这 3 种样式分别是:(scroman罗马风格,小型大写字母)、osroman(类似罗马风格,但如果页码是连续的is,则最后一个 i 将被替换j)和scosroman(与前一种相同,采用小型大写字母)。以下是示例:

\documentclass[openany]{book}
\usepackage{ebgaramond}

\usepackage{lipsum}% texte bidon

\makeatletter
\newcommand{\oldstyleroman}[1]{\expandafter\@oldstyleroman#1\@nil}
\def\@oldstyleroman#1#2\@nil{%
  \ifcat$\detokenize{#2}$%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {\if#1ij\else#1\fi}% si #2 est vide
  {#1\@oldstyleroman#2\@nil}% si #2 n'est pas vide
}
\def\scroman#1{\expandafter\@scroman\csname c@#1\endcsname}
\def\@scroman#1{{\scshape\romannumeral #1}}
\def\osroman#1{\expandafter\@osroman\csname c@#1\endcsname}
\def\@osroman#1{{\oldstyleroman{\romannumeral #1}}}
\def\scosroman#1{\expandafter\@scosroman\csname c@#1\endcsname}
\def\@scosroman#1{{\scshape\oldstyleroman{\romannumeral #1}}}
\makeatother

\usepackage{hyperref}

\begin{document}

\tableofcontents

\frontmatter
\pagenumbering{scroman}

\chapter{Introduction}
\section{Titre}
\lipsum[1-10]
\section{Titre}
\label{page}
\lipsum[11-20]

\mainmatter
\chapter{A Matter of Styles}
\lipsum[21-25]

Voir page~\pageref{page}.


\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容