
A ideia é usar as informações do índice para gerar referências cruzadas automaticamente. Se uma entrada de índice se referir a mais de uma página (por exemplo, "Smith, John 5, 9"), então a entrada de índice junto com os outros números de página deverão aparecer na margem no local onde eu faço a entrada de índice (ou seja, seguindo o exemplo acima, na página 5 na margem aparece "Smith, John 9").
É possível alterar o showidx
pacote de acordo?
Além disso, a solução deve ser compatível com hyperref
o fato que estou usando, twosided
mas a margem maior está sempre à direita (estou usando tufte-latex
).
Obrigado por qualquer dica.
E aqui está minha tentativa de um MWE (não tenho certeza se isso ajuda):
%\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}
Responder1
O"pequeno ajuste"é um eufemismo. Após o processamento normal do .idx
arquivo pelo makeindex, a relação dos dados brutos dentro \index
(arquivo LaTeX) ou \indexentry
( .idx
arquivo) com a entrada de índice formatada no .ind
arquivo é perdida. Exemplo:
\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)
A partir do arquivo de índice gerado, a forma exata de \index
só pode ser adivinhada (por exemplo, \index{foobar}
e \index{foo!bar}
. As especificações de classificação, intervalo e encap desapareceram. Assim, o resultado do arquivo de índice gerado seria um mapeamento de tais chaves para a lista de páginas, por exemplo:
foobar ⇒ 1, \textbf{2}, 3
foo!bar ⇒ 3--7, 10
O pacote a seguir indexpagelist
define um arquivo de estilo indexpagelist.ist
para makeindex que gera tal mapeamento.
De volta ao nível do LaTeX, precisamos retirar as especificações de classificação, intervalo e encap da string fornecida a \index
.
Para reduzir o nível de complexidade e economizar tempo, não implementei o suporte para caracteres de cotação e escape. Além disso actual
, os caracteres level
, e encap
são suportados apenas com seus valores padrão ( @
, !
, |
).
%%% 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
Então o "ajuste" no arquivo TeX principal é minúsculo, apenas o pacote precisa ser carregado. Devido a deficiências na codificação OT1, o encap
caractere |
é exibido como travessão —
, portanto usei a codificação de fonte T1 com fontes Latin Modern.
%%% 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}
O arquivo de índice bruto 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}
O arquivo de índice principal é gerado normalmente:
$ makeindex test
O arquivo de índice test.ind
para \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}
O arquivo com os mapeamentos da lista de páginas é gerado por:
$ makeindex -s indexpagelist.ist -t test-ipl.ilg -o test.ipl test.idx
Por conveniência, adicionei ambas as chamadas de makeindex via \immediate\write18
no arquivo do pacote (o TeX Live as executa com escape de shell restrito).
O arquivo test.ipl
contém os mapeamentos das chaves de índice para suas listas de páginas:
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}
Isso define macros como \ipl@animals!dog
content 1, \textbf{2}, 3
. A macro \iplMultiPage
é usada como marcador para detectar listas de uma e várias páginas com mais facilidade.
Em seguida, o pacote é conectado \@showidx
para adicionar a lista de páginas.
O índice:
Página 1:
Página 2:
Página 3: