1

I would like showidx to display the entries in the margin in red but can't figure out how, if only because showidx is loaded by the famous Heiko Oberdiek hack. Here is a 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}
schremmer
  • 2,107

1 Answers1

2

I have no idea where the hack is from and what it is supposed to do (and if it is still needed), but to get the word in the margin in red you can try this:

\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}
Ulrike Fischer
  • 327,261
  • The showidx displays are indeed red but ... the index disappeared altogether. 2. See "https://tex.stackexchange.com/questions/492874/what-does-quick-and-dirty-hack-by-heiko-oberdiek-do"
  • – schremmer Jan 28 '20 at 22:53
  • @ Ulrike Fischer May I take it back? The Index is here. It even works in the Magnum Opus. – schremmer Jan 28 '20 at 23:17
  • I don't have a problem with the index, it is on page three and contains your word. – Ulrike Fischer Jan 28 '20 at 23:17