ShowIdx(由 Heiko Oberdiek 黑客加载)显示为红色

ShowIdx(由 Heiko Oberdiek 黑客加载)显示为红色

我希望 showidx 以红色显示边距中的条目,但不知道该怎么做,因为 showidx 是由著名的 Heiko Oberdiek 黑客加载的。以下是 MWE:

\documentclass[11pt]{book}
\usepackage{xcolor} 
\usepackage{makeidx}
\usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty%Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
  \@ifpackageloaded{multind}{%
    \let\HyInd@org@wrindex\@wrindex
    \def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
    \def\HyInd@@wrindex#1#2|#3|#4\\{%
      \ifx\\#3\\%
        \HyInd@org@wrindex{#1}{#2|hyperpage}%
      \else
        \def\Hy@temp@A{#3}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          HyInd@org@wrindex{#1}{#2|#3hyperpage}%
        \else
          \HyInd@org@wrindex{#1}{#2|#3}%
        \fi
      \fi
    }%
  }{%
    \def\@wrindex#1{\@@wrindex#1||\\}
    \def\@@wrindex#1|#2|#3\\{%
      \ifx\\#2\\%
        \protected@write\@indexfile{}{%
          \string\indexentry{#1|hyperpage}{\thepage}%
        }%
      \else
        \def\Hy@temp@A{#2}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          \protected@write\@indexfile{}{%
             \string\indexentry{#1|#2hyperpage}{\thepage}%
          }%
        \else
          \protected@write\@indexfile{}{%
            \string\indexentry{#1|#2}{\thepage}%
          }%
        \fi
      \fi
      \endgroup
      \HyInd@showidx{#1}%
      \@esphack
    }%
  }%
\fi
\makeatother
\hypersetup{%begin colors
               colorlinks,
               linkcolor={red!50!black},
               citecolor={blue!50!black},
              urlcolor={blue!80!black}
            }%end colors
\newcommand{\INDEX}[2][]{\phantomsection%
\if\relax\detokenize{#1}\relax\index{#2}\label{ind:#2}%
\else\index{#2}\label{ind:#1}\fi%
}%

\newcommand{\DEX}[2][]{%
\if\relax\detokenize{#1}\relax\hyperref[ind:#2]{#2}%
\else\hyperref[ind:#1]{#2}%
\fi%
}%
\makeindex

\begin{document}

I would like this \textbf{NewWord}\INDEX[]{NewWord} to appear in the Index in black but be displayed in the margin in \textcolor{red}{red}.

\newpage

Just for checking, clicking on \DEX[NewWord]{\emph{NewWord}} should get us back to its first appearance. 
\printindex
\end{document}

答案1

我不知道这个 hack 是从哪里来的,也不知道它应该做什么(以及是否仍然需要它),但是为了将边距中的单词变为红色,你可以尝试这个:

\documentclass[11pt]{book}
\usepackage{xcolor} 
\usepackage{makeidx}
\usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty%Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
  \@ifpackageloaded{multind}{%
    \let\HyInd@org@wrindex\@wrindex
    \def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
    \def\HyInd@@wrindex#1#2|#3|#4\\{%
      \ifx\\#3\\%
        \HyInd@org@wrindex{#1}{#2|hyperpage}%
      \else
        \def\Hy@temp@A{#3}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          HyInd@org@wrindex{#1}{#2|#3hyperpage}%
        \else
          \HyInd@org@wrindex{#1}{#2|#3}%
        \fi
      \fi
    }%
  }{%
    \def\@wrindex#1{\@@wrindex#1||\\}
    \def\@@wrindex#1|#2|#3\\{%
      \ifx\\#2\\%
        \protected@write\@indexfile{}{%
          \string\indexentry{#1|hyperpage}{\thepage}%
        }%
      \else
        \def\Hy@temp@A{#2}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          \protected@write\@indexfile{}{%
             \string\indexentry{#1|#2hyperpage}{\thepage}%
          }%
        \else
          \protected@write\@indexfile{}{%
            \string\indexentry{#1|#2}{\thepage}%
          }%
        \fi
      \fi
      \endgroup
      \HyInd@showidx{\textcolor{red}{#1}}%<---
      \@esphack
    }%
  }%
\fi
\makeatother
\hypersetup{%begin colors
               colorlinks,
               linkcolor={red!50!black},
               citecolor={blue!50!black},
              urlcolor={blue!80!black}
            }%end colors
\newcommand{\INDEX}[2][]{\phantomsection%
\if\relax\detokenize{#1}\relax\index{#2}\label{ind:#2}%
\else\index{#2}\label{ind:#1}\fi%
}%

\newcommand{\DEX}[2][]{%
\if\relax\detokenize{#1}\relax\hyperref[ind:#2]{#2}%
\else\hyperref[ind:#1]{#2}%
\fi%
}%
\makeindex

\begin{document}

I would like this \textbf{NewWord}\INDEX[]{NewWord} to appear in the Index in black but be displayed in the margin in \textcolor{red}{red}.

\newpage

Just for checking, clicking on \DEX[NewWord]{\emph{NewWord}} should get us back to its first appearance. 
\printindex
\end{document}

相关内容