
這個想法是使用索引資訊自動產生交叉引用。如果索引條目涉及超過 1 頁(例如,「Smith, John 5, 9」),則索引條目以及其他頁碼應顯示在我建立索引條目的位置的頁邊空白中(IE,依照上面的範例,第 5 頁的頁邊空白處出現「Smith, John 9」)。
是否可以showidx
相應更改套餐?
此外,該解決方案應該與hyperref
我正在使用的事實相容twosided
,但較大的邊距始終位於右側(我正在使用tufte-latex
)。
感謝您的任何提示。
這是我對 MWE 的嘗試(不確定這是否有幫助):
%\documentclass[twoside]{tufte-book}
\documentclass{book}
\usepackage{makeidx,showidx,lipsum}
\makeindex
\begin{document}
John Smith\index{Smith, John}
\lipsum
John Smith\index{Smith, John}
\lipsum
\printindex
\end{document}
答案1
這“小調整”這是相當輕描淡寫的說法。透過 makeindex 對文件進行常規處理後, (LaTeX 文件)或(文件)內的原始資料與文件中格式化索引條目.idx
的關係會遺失。例子:\index
\indexentry
.idx
.ind
\index{foobar} ⇒ \item foobar, ...
\index{foo@foobar} ⇒ \item foobar, ... (sort spec.
\index{foobar|(} ⇒ \item foobar, ... (range spec.)
\index{foobar|textbf} ⇒ \item foobar, \textbf{1} (encap feature)
\index{"f"o"o"b"a"r} ⇒ \item foobar, ... (quote char)
\index{foo!bar} ⇒ \item foo ...\subitem bar (level char)
\index{fooX@foo!barY@b"ar|(emph}
⇒ \item foo ...\subitem bar (sort + level + quote + range + encap)
\index
從產生的索引檔案中,只能猜測 的確切形式(例如\index{foobar}
和\index{foo!bar}
。排序、範圍、encap 規範都消失了。因此產生的索引檔案的結果將是從這些鍵到頁面清單的映射,例如:
foobar ⇒ 1, \textbf{2}, 3
foo!bar ⇒ 3--7, 10
以下包為 makeindex 定義了一個產生此類映射的indexpagelist
樣式檔。indexpagelist.ist
回到 LaTeX 級別,我們需要從賦予 的字串中刪除排序、範圍和封裝規範\index
。
為了降低複雜性並節省一些時間,我沒有實現對引號和轉義字元的支援。此外actual
, 、level
和encap
字元僅支援其預設值 ( @
, !
, |
)。
%%% indexpagelist.sty %%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{indexpagelist}[2013/07/16 v0.1 Index page list for showidx]
\RequirePackage{filecontents}
\begin{filecontents*}{indexpagelist.ist}
preamble ""
postamble ""
setpage_prefix ""
group_skip ""
headings_flag 0
symhead_negative ""
numhead_negative ""
item_0 "\\iplItemA{"
item_1 "\\iplItemB{"
item_2 "\\iplItemC{"
item_01 "\\iplItemB{"
item_x1 "}\n\\iplItemB{"
item_12 "\\iplItemC{"
item_x2 "}\n\\iplItemC{"
delim_0 "}\n\\iplPageList{"
delim_1 "}\n\\iplPageList{"
delim_2 "}\n\\iplPageList{"
delim_n "\\iplMultiPage, "
delim_r "\\iplMultiPage--"
delim_t "}\n"
line_max 1000
\end{filecontents*}
\immediate\write18{%
makeindex %
-s indexpagelist.ist %
-t \jobname-ipl.ilg %
-o \jobname.ipl %
\jobname.idx%
}
\immediate\write18{makeindex \jobname}% for convenience
\newcommand*{\iplItemA}[1]{%
\def\iplCurrentItemA{#1}%
\@onelevel@sanitize\iplCurrentItemA
\let\iplCurrent\iplCurrentItemA
}
\newcommand*{\iplItemB}[1]{%
\def\iplCurrentItemB{#1}%
\@onelevel@sanitize\iplCurrentItemB
\edef\iplCurrent{\iplCurrentItemA!\iplCurrentItemB}%
}
\newcommand*{\iplItemC}[1]{%
\def\iplCurrentItemC{#1}%
\@onelevel@sanitize\iplCurrentItemC
\edef\iplCurrent{\iplCurrentItemA!\iplCurrentItemB!\iplCurrentItemC}%
}
\newcommand*{\iplPageList}[1]{%
\expandafter\@ipl@PageList#1\iplMultiPage\@nil
}
\newcommand*{\iplMultiPage}{}
\def\@ipl@PageList#1\iplMultiPage#2\@nil{%
\def\@ipl@Temp{#2}%
\ifx\@ipl@Temp\@empty
\else
\expandafter\protected@xdef\csname ipl@\iplCurrent\endcsname{#1#2}%
\fi
}
\InputIfFileExists{\jobname.ipl}{}{}
\newcommand*{\iplGetPageList}[1]{%
\def\@ipl@Temp{#1}%
\@onelevel@sanitize\@ipl@Temp
\let\@ipl@Key\@empty
\expandafter\@ipl@GetPageList@Encap\@ipl@Temp|\@nil
\@ifundefined{ipl@\@ipl@Key}{}{%
, \@nameuse{ipl@\@ipl@Key}%
}%
}
\def\@ipl@GetPageList@Encap#1|#2\@nil{%
\let\@ipl@Key\@empty
\@ipl@GetPageList@Level#1!\@nil
}
\def\@ipl@Temp#1{%
\def\@ipl@GetPageList@Level##1!##2\@nil{%
\@ipl@GetPageList@Sort##1#1\@nil
\def\@ipl@Temp{##2}%
\ifx\@ipl@Temp\@empty
\else
\@ipl@GetPageList@Level##2\@nil
\fi
}%
\def\@ipl@GetPageList@Sort##1#1##2\@nil{%
\def\@ipl@Temp{##2}%
\edef\@ipl@Key{%
\ifx\@ipl@Key\@empty
\else
\@ipl@Key!%
\fi
\ifx\@ipl@Temp\@empty
##1%
\else
\@ipl@RemoveSortChar##2\@nil
\fi
}%
}%
\def\@ipl@RemoveSortChar##1#1\@nil{##1}%
}
\expandafter\@ipl@Temp\string @
% remaining "small tweak" for package showidx
\newcommand*{\iplPatchShowidx}{%
\@ifpackageloaded{showidx}{%
\@ifdefinable{\saved@showidx}{%
\let\saved@showidx\@showidx
\renewcommand*{\@showidx}[1]{%
\saved@showidx{##1\iplGetPageList{##1}}%
}%
}%
\global\let\iplPatchShowidx\relax
}{}%
}
\iplPatchShowidx
\AtBeginDocument{\iplPatchShowidx}
\endinput
然後對主 TeX 檔案的「調整」很小,只需要載入套件。由於 OT1 編碼的缺陷,encap
字元|
顯示為 em dash —
,因此我使用了帶有 Latin Modern 字體的 T1 字體編碼。
%%% test.tex %%%
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{makeidx,showidx,lipsum,indexpagelist}
\makeindex
\begin{document}
John Smith\index{Smith, John}, John Doe\index{Doe, John},
cat\index{animals!cat|(}, dog\index{animals!dog}
\lipsum
John Smith\index{Smith, John}, dog\index{animals!dog|textbf},
Donald E. Knuth\index{Knuth, Donald E.}
\lipsum
cat\index{animals!cat|)}, dog\index{animals!dog},
Donald E. Knuth\index{Knuth, Donald E.}
\newpage
\printindex
\end{document}
原始索引檔test.idx
:
\indexentry{Smith, John}{1}
\indexentry{Doe, John}{1}
\indexentry{animals!cat|(}{1}
\indexentry{animals!dog}{1}
\indexentry{Smith, John}{2}
\indexentry{animals!dog|textbf}{2}
\indexentry{Knuth, Donald E.}{2}
\indexentry{animals!cat|)}{3}
\indexentry{animals!dog}{3}
\indexentry{Knuth, Donald E.}{3}
主索引檔照常產生:
$ makeindex test
索引test.ind
檔\printindex
:
\begin{theindex}
\item animals
\subitem cat, 1--3
\subitem dog, 1, \textbf{2}, 3
\indexspace
\item Doe, John, 1
\indexspace
\item Knuth, Donald E., 2, 3
\indexspace
\item Smith, John, 1, 2
\end{theindex}
具有頁面列表映射的文件是透過以下方式產生的:
$ makeindex -s indexpagelist.ist -t test-ipl.ilg -o test.ipl test.idx
\immediate\write18
為了方便起見,我在套件檔案中添加了 makeindex via 的兩個呼叫(TeX Live 使用受限的 shell 轉義來執行它們)。
該文件test.ipl
包含從索引鍵到其頁面列表的映射:
iplItemA{animals}
\iplItemB{cat}
\iplPageList{1\iplMultiPage--3}
\iplItemB{dog}
\iplPageList{1\iplMultiPage, \textbf{2}\iplMultiPage, 3}
\iplItemA{Doe, John}
\iplPageList{1}
\iplItemA{Knuth, Donald E.}
\iplPageList{2\iplMultiPage, 3}
\iplItemA{Smith, John}
\iplPageList{1\iplMultiPage, 2}
它定義了宏,例如\ipl@animals!dog
with content 1, \textbf{2}, 3
。巨集\iplMultiPage
用作標記來更輕鬆地偵測單頁和多頁清單。
然後該包掛鉤\@showidx
以添加頁面列表。
索引:
第 1 頁:
第2頁:
第 3 頁: