2

I was using the code from Harish Kumar's excellent answer to this question to create a link t my table of contents. However, I wanted to alter it so that the link did not appear on the first two pages.

I tried using the \everypage package to create a hook that would exclude the first two pages from the function, but I'm not sure how to nest the hook to fit with the \ifthenelse. Every attempt I tried to somehow combine in a hook, in various combinations, resulted in a compile error.

Here is the code, which, once again, I lifted from the earlier-linked excellent answer:

\documentclass{article}
\usepackage{blindtext}
\usepackage{eso-pic}
\usepackage{hyperref}
\usepackage{ifthen}
\newboolean{linktoc}
\setboolean{linktoc}{true}  %%% uncomment to show answers properly
%\setboolean{linktoc}{false}  %%% comment to show answers properly

\newcommand\AtPageUpperRight[1]{\AtPageUpperLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{-0.3\paperheight}){#1}%
 }}%
\newcommand\AtPageLowerRight[1]{\AtPageLowerLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{0.3\paperheight}){#1}%
 }}%

\ifthenelse{\boolean{linktoc}}%
{%
\AddToShipoutPictureBG{%
   \AtPageUpperRight{\put(-70,0){\hyperref[toc]{Go to TOC}}}
   \AtPageLowerRight{\put(-70,0){\hyperref[toc]{Go to TOC}}}
    }%
}%
{}%


\begin{document}
  \tableofcontents\label{toc}
  \Blinddocument
\end{document}

(I'm relatively new to using conditionals, so I apologize if my title or question uses incorrect terminology— please tell me if it does so I can edit it and make my question clearer)

  • related, see this comment http://tex.stackexchange.com/questions/285538/control-of-the-markers-at-header#comment689507_285538 – touhami Jan 03 '16 at 18:02

1 Answers1

1

You could condition on the value of the page counter, as you're adding content at the time of shipout (when the page counter is correct):

enter image description here

\documentclass{article}

\usepackage{blindtext}
\usepackage{eso-pic,hyperref}

\newif\iflinktoc
\linktoctrue%%% uncomment to show answers properly
%\linktocfalse%%% comment to show answers properly

\newcommand\AtPageUpperRight[1]{\AtPageUpperLeft{%
  \put(\LenToUnit{\paperwidth},\LenToUnit{-0.3\paperheight}){#1}%
}}%
\newcommand\AtPageLowerRight[1]{\AtPageLowerLeft{%
  \put(\LenToUnit{\paperwidth},\LenToUnit{0.3\paperheight}){#1}%
}}%

\newcommand{\addlinktotoc}{\hyperref[toc]{Go to ToC}}
\iflinktoc
  \AddToShipoutPictureBG{%
    \ifnum\value{page}<3\else
      \AtPageUpperRight{\put(-70,0){\addlinktotoc}}%
      \AtPageLowerRight{\put(-70,0){\addlinktotoc}}%
    \fi
  }%
\fi

\begin{document}

\tableofcontents\label{toc}
\Blinddocument

\end{document}

I've dropped the use of ifthen, based on Why is the ifthen package obsolete? and How to keep up with packages and know which ones are obsolete?.

Werner
  • 603,163
  • Thank you! Good to know about ifthen — I had no idea it was obsolete –  Jan 03 '16 at 18:39