How to make colorised linked pagenumbering of appended documents?

I am trying to understand the last part of the answer, Key-value interface's pagenumbering, in the thread How to generate TOC by custom labels at appended documents' beginnings? I would like to colorise the pagenumber to red and make a link to it, back to the first page of the document (ToC, for instance). I think fancypagestyle is not the optimal here in the thread How to label all pagenumbers to TOC in fancy footer? My proposal but sure how to apply them to the Christian's Key-value interface's pagenumbering

• \usepackage{xcolor} so {\color{red} pagenumber}
• with a link to ToC, the following pseudocode, but not sure how to make an internal one here

\href{some-how-link-to-1st-page-of-document}{{\color{red} pagenumber}}


Relevant part of Christian's code

% https://tex.stackexchange.com/a/365580/13173
\usepackage{pdfpages}
\usepackage{hyperref} % for links in TOC
% https://tex.stackexchange.com/q/56316/13173
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt} % Werner, remove top margin border
% https://tex.stackexchange.com/a/338919/13173
\usepackage{letltxmacro}

\makeatletter
\LetLtxMacro\pdfpages@@includepdf\includepdf

\RenewDocumentCommand{\includepdf}{O{}mo}{%
\begingroup
\IfValueTF{#3}{% Is there a 3rd argument? Yes
% Process the keys for the \includepdf first in order to get the value of 'pages=...' option
% This is stored to \AM@pagestemp (see pdfpages.sty)
\setkeys{pdfpages}{#1}%
% Call the old command with the options for addtotoc
}{% No, no 3rd. argument}
\pdfpages@@includepdf[pagecommand={\thispagestyle{fancy}},#1]{#2}
}%
\endgroup% Prevent leaking of key values to the next call of the command
}
\makeatother


OS: Debian 8.7
Hardware: Asus Zenbook UX303UB

• Are you after \usepackage[colorlinks,linktocpage]{hyperref}? – user31729 Apr 21 '17 at 9:38
• @ChristianHupfer Can you please give an example about that? - - colorlinks seems to be appropriate, also linktocpage but not sure where this link is going to be created. – Léo Léopold Hertz 준영 Apr 21 '17 at 9:39
• Just add the line to a file which uses my answer about the redefined \includepdf (which I added yesterday, I think) – user31729 Apr 21 '17 at 9:40
• linktocpage = link the page number displayed in the ToC to the relevant page instead of the section etc. name being a link -- the link anchor is the same, the difference is the page numbers are clickable now and the entries aren't – user31729 Apr 21 '17 at 9:44
• @ChristianHupfer Ok, I think it is not what I want. I want to have links at pagenumber elsewhere than TOC, back to TOC, such that you can easily read the document and going back to TOC. – Léo Léopold Hertz 준영 Apr 21 '17 at 9:45

Try a \hypersetup{linkcolor}{red}\hyperlink{mytoc\jobname}{\thepage}} (whereas red is the default colour anyway for links)

Since this occurs in a group, \hypersetup does not leak outside other than the local group.

\documentclass{article}
\usepackage{blindtext}
\usepackage{fancyhdr}
\usepackage{xcolor}

\fancypagestyle{plain}{%
\fancyhf{}
}

\begin{document}
\pagestyle{plain}
\phantomsection
\hypertarget{docstart\jobname}{}
\blindtext[10]
\phantomsection
\hypertarget{mytoc\jobname}{}
\tableofcontents
\clearpage

\section{Beginning Foo}
\blindtext[10]

\end{document}


With fancy pagestyle:

\documentclass{article}
\usepackage{blindtext}
\usepackage{fancyhdr}
\usepackage{xcolor}

% Now for fancy pagestyle
\fancyhf{}

\begin{document}
\pagestyle{fancy}
\phantomsection
\hypertarget{docstart\jobname}{}
\blindtext[10]
\phantomsection
\hypertarget{mytoc\jobname}{}
\tableofcontents
\clearpage

\section{Beginning Foo}
\blindtext[10]

\end{document}


• Confirmed! Both approaches work with or without pdfpages. I disabled first page feature in a document where first page is the same as TOC. - - How can you make the red page number size bigger? I am thinking how to make the document for usable on tablets. - - I noticed that the location of the pagenumber raises up little by the approaches. Do you understand why? I think it is the only bug here. Maybe, this command \renewcommand{\headrulewidth}{0pt} is overrun somehow. – Léo Léopold Hertz 준영 Apr 21 '17 at 10:05
• @LéoLéopoldHertz준영: \thepage comes down to something like \arabic{page}, which is normal typesetting, so \huge\thepage inside the link will enlarge the pagenumber. You can use any of the font size switches there, i.e. \large etc. \bfseries is also possible – user31729 Apr 21 '17 at 10:07
• Some documentation about \phantomsection` here tex.stackexchange.com/a/44091/13173 – Léo Léopold Hertz 준영 Apr 21 '17 at 10:08
• @LéoLéopoldHertz준영: I see no raising in the position of the page number. – user31729 Apr 21 '17 at 10:11
• @LéoLéopoldHertz준영: You're trying to squeeze a full page of another document on a document with the same page size and still having header and footer -- this will cause problems. If possible you should strip the footer of the other documents (if they are LaTeX documents, this should be possible) – user31729 Apr 21 '17 at 10:21