색인 정보를 사용하여 상호 참조 생성

색인 정보를 사용하여 상호 참조 생성

아이디어는 색인 정보를 사용하여 상호 참조를 자동으로 생성하는 것입니다. 색인 항목이 1페이지 이상을 참조하는 경우(예: "Smith, John 5, 9") 색인 항목을 만든 위치의 여백에 다른 페이지 번호와 함께 색인 항목이 표시되어야 합니다(, 위의 예에 따르면 5페이지 여백에 "Smith, John 9"가 나타납니다.

그에 따라 패키지 를 변경할 수 있나요 showidx?

또한 솔루션은 와 호환되어야 하며 내가 사용하고 있지만 더 큰 여백이 항상 오른쪽에 있다는 hyperref사실 (나는 을 사용하고 있습니다 )입니다.twosidedtufte-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}. 정렬, 범위, 캡슐화 사양은 사라졌습니다. 따라서 생성된 인덱스 파일의 결과는 해당 키에서 페이지 목록으로의 매핑이 됩니다. 예:

foobar  ⇒ 1, \textbf{2}, 3
foo!bar ⇒ 3--7, 10

다음 패키지는 이러한 매핑을 생성하는 makeindex에 대한 indexpagelist스타일 파일을 정의합니다 .indexpagelist.ist

LaTeX 수준으로 돌아가서 에 제공되는 문자열에서 정렬, 범위 및 캡슐화 사양을 제거해야 합니다 \index.

복잡성 수준을 줄이고 시간을 절약하기 위해 인용 및 이스케이프 문자에 대한 지원을 구현하지 않았습니다. 또한 actual, levelencap문자는 기본값( @, !, |)으로만 지원됩니다.

%%% 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 대시로 표시되므로 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 호출을 두 개 모두 추가했습니다 (TeX Live는 제한된 쉘 이스케이프를 사용하여 이를 실행합니다).

파일에는 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이는 withcontents 와 같은 매크로를 정의합니다 1, \textbf{2}, 3. 매크로는 \iplMultiPage단일 및 다중 페이지 목록을 보다 쉽게 ​​감지하기 위한 마커로 사용됩니다.

그런 다음 패키지가 연결되어 \@showidx페이지 목록을 추가합니다.

색인:

색인

페이지 1:

페이지 1

2 쪽:

2 쪽

페이지 3:

3페이지

관련 정보