hyperref の目次としおり

hyperref の目次としおり

- Toshio Otaguro の投稿
返信数: 6
過去ログを読んだりして試行錯誤したのですが,うまく行かないので質問させていただきます.以下のようなソースを uplatex + upmendex + dvipdfmx で処理します.処理系は TeXLive2021 です.

----------
\documentclass[uplatex,dvipdfmx,11pt,b5paper,openany]{jsbook}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{makeidx}
\usepackage[dvipdfmx, colorlinks=true, bookmarks=true, bookmarksnumbered=true, %
bookmarkstype=toc, filecolor=blue, urlcolor=blue, linkcolor=blue, %
linktocpage=true, citecolor=red, menucolor=black, %
pdfnewwindow=true, breaklinks=false]{hyperref}
\usepackage{pxjahyper}

\makeindex
\begin{document}
\tableofcontents

\chapter{はじめに}
最初の章.「はじめに\index{はじめに}」を索引に入れる.

\chapter{次に}
次の章の最初の節.「次に\index{つぎに@次に}」を索引に入れる.

\clearpage
\phantomsection
% \addcontentsline{toc}{chapter}{\indexname}
\printindex
\end{document}
----------

最終ページに索引が「索引」というタイトルの下に作られます.ところが,PDF の目次の中の索引ページや,しおりの中の索引をクリックすると,「索引」というタイトルではなく,索引の最初のエントリーである「次に」にリンクが張られている(Viewerの拡大率を大きめにするとよく確認できます)ことがわかります.これをタイトルの「索引」にリンクが張られるようにするにはどうすればよいのでしょうか?

FAQのようだったので,様々なサイトの過去ログを調べて対策とされたことを試してみたのですが,状況が変わらないので戸惑っています.
Toshio Otaguro への返信

Re: hyperref の目次としおり

- 和田 勇 の投稿
texmf-dist/tex/platex/jsclasses/jsbook.cls
1758:\newenvironment{theindex} ....

を改造しても良いかもしれないけど参照ポイントを登録でやって見ました。

(.ind ファイルに登録されたものにジャンプするようだったので)

....
\index{さくいん@索引}
\printindex
....

問題点
索引が索引に載ってしまう。
いろいろなケースを試していない。
和田 勇 への返信

Re: hyperref の目次としおり

- Toshio Otaguro の投稿

ご検討ありがとうございます.

実は,jsbook だけではなく,book.sty を使い,pxjahyper を使わずに英文だけで同様のことを行っても現象は同じなので,hyperref そのものに根本的な原因があるのではないか?というのが私の推測です.

Toshio Otaguro への返信

Re: hyperref の目次としおり

- はやて (h20y6m) の投稿

jsbook の場合

\usepackage{multicol}

するとうまくいくようです。 (\phantomsection がなくてもOK。)

どうも twocolumn が絡むとおかしくなるようです。 (索引は二段組みしている。)

はやて (h20y6m) への返信

Re: hyperref の目次としおり

- Toshio Otaguro の投稿

おお,確かにうまく行きますね.ただし索引が最初から2段組になるところが’違います.makeidx も絡んでいるのでしょうか?

はやて (h20y6m) への返信

Re: hyperref の目次としおり

- ut の投稿

検索してみましたら、

  Anchor for the index title that uses \twocolumn
  https://tex.stackexchange.com/questions/172352/correct-hyperlink-to-the-index

という質問に対して、

  answered Apr 19 '14 at 14:41
  Heiko Oberdiek

という回答で、\twocolumn[ ] の中に:

  \phantomsection
  \addcontentsline{toc}{chapter}{\indexname}

を入れる、というやり方が紹介されていました。

jsclasses ではなくて、簡単のために book.cls と pdflatex で試してみた例です:
(上記の回答では etoolbox.sty が使われていますが、ここでは直接再定義してみました)


----- test-pdflatex.tex -----

\documentclass{book}
\usepackage{hyperref}

\makeatletter
\renewenvironment{theindex}
              {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                %\twocolumn[\@makeschapterhead{\indexname}]%
                \twocolumn[%
                  \phantomsection
                  \addcontentsline{toc}{chapter}{\indexname}%
                  \@makeschapterhead{\indexname}]%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \columnseprule \z@
                \columnsep 35\p@
                \let\item\@idxitem}
              {\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother

\begin{document}

\tableofcontents

\chapter{Foo}

\chapter{Bar}

%\cleardoublepage
%\phantomsection
%\addcontentsline{toc}{chapter}{\indexname}

\begin{theindex}
  \item foo, \hyperpage{3}
  \indexspace
  \item bar, \hyperpage{5}
\end{theindex}

\end{document}


ut への返信

Re: hyperref の目次としおり

- Toshio Otaguro の投稿

ありがとうございます.示していただいた \renewenvironment{theindex} を当方が最初に示したソースに組み入れて確認してみました.

素晴らしい!完璧です.大変ありがとうございました.

乏しい知識と半端な理解なりに思うには,複数のパッケージが絡み合う状況で,このように解決路を探索するのは大変面白い反面,私のような素人が手を出せるものではありませんね.

いずれにせよ,コメントいただいたすべての方々に感謝申し上げます.